From 5047c53c0adfaf9b6bc9875818a73ec362b1f14a Mon Sep 17 00:00:00 2001 From: Son Luong Ngoc Date: Tue, 14 May 2024 06:02:35 -0700 Subject: [PATCH] Add PathFragment tests for mixed Windows path separators. To clarify that this is working as intended. Closes #22343. PiperOrigin-RevId: 633557654 Change-Id: I1b029d285626b0f87d0206eac68aa438ca24f014 --- .../build/lib/vfs/PathFragmentWindowsTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java index a8dc24fa1870b5..01d1e3376063b0 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java @@ -177,6 +177,9 @@ public void testGetParentDirectoryWindows() { public void testSegmentsCountWindows() { assertThat(create("C:/foo").segmentCount()).isEqualTo(1); assertThat(create("C:/").segmentCount()).isEqualTo(0); + // Mix usage of Windows and Unix separator is valid + assertThat(create("C:/foo\\bar").segmentCount()).isEqualTo(2); + assertThat(create("C:\\foo\\bar/baz").segmentCount()).isEqualTo(3); } @Test @@ -185,6 +188,12 @@ public void testGetSegmentWindows() { assertThat(create("C:/foo/bar").getSegment(1)).isEqualTo("bar"); assertThat(create("C:/foo/").getSegment(0)).isEqualTo("foo"); assertThat(create("C:/foo").getSegment(0)).isEqualTo("foo"); + // Mix usage of Windows and Unix separator is valid + assertThat(create("C:/foo\\bar").getSegment(0)).isEqualTo("foo"); + assertThat(create("C:/foo\\bar").getSegment(1)).isEqualTo("bar"); + assertThat(create("C:\\foo\\bar/baz").getSegment(0)).isEqualTo("foo"); + assertThat(create("C:\\foo\\bar/baz").getSegment(1)).isEqualTo("bar"); + assertThat(create("C:\\foo\\bar/baz").getSegment(2)).isEqualTo("baz"); } @Test @@ -193,6 +202,9 @@ public void testBasenameWindows() throws Exception { assertThat(create("C:/foo").getBaseName()).isEqualTo("foo"); // Never return the drive name as a basename. assertThat(create("C:/").getBaseName()).isEmpty(); + // Mix usage of Windows and Unix separator is valid + assertThat(create("C:/foo\\bar").getBaseName()).isEqualTo("bar"); + assertThat(create("C:\\foo\\bar/baz").getBaseName()).isEqualTo("baz"); } @Test