Skip to content

Commit

Permalink
Add PathFragment tests for mixed Windows path separators.
Browse files Browse the repository at this point in the history
To clarify that this is working as intended.

Closes #22343.

PiperOrigin-RevId: 633557654
Change-Id: I1b029d285626b0f87d0206eac68aa438ca24f014
  • Loading branch information
sluongng authored and copybara-github committed May 14, 2024
1 parent 53a358c commit 5047c53
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5047c53

Please sign in to comment.