Skip to content

Commit 620159c

Browse files
committed
More startsWith(), endsWith() tests
1 parent 81a044e commit 620159c

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

mug/src/test/java/com/google/mu/util/SubstringTest.java

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,39 +2049,110 @@ public void skipFromEnd_toString() {
20492049
}
20502050

20512051
@Test
2052-
public void matchStartsWith_emptyMatch() {
2052+
public void matchStartsWith_empty() {
20532053
Substring.Match match = Substring.first("").in("abc").get();
20542054
assertThat(match.startsWith("")).isTrue();
20552055
assertThat(match.startsWith("a")).isFalse();
20562056
}
20572057

20582058
@Test
2059-
public void matchStartsWith_nonEmptyMatch() {
2059+
public void matchStartsWith_singleChars() {
2060+
Substring.Match match = Substring.first("c").in("abcd").get();
2061+
assertThat(match.startsWith("")).isTrue();
2062+
assertThat(match.startsWith("c")).isTrue();
2063+
assertThat(match.startsWith("bc")).isFalse();
2064+
assertThat(match.startsWith("cd")).isFalse();
2065+
assertThat(match.startsWith("d")).isFalse();
2066+
}
2067+
2068+
@Test
2069+
public void matchStartsWith_twoChars() {
20602070
Substring.Match match = Substring.first("bc").in("abcd").get();
20612071
assertThat(match.startsWith("")).isTrue();
20622072
assertThat(match.startsWith("b")).isTrue();
20632073
assertThat(match.startsWith("bc")).isTrue();
20642074
assertThat(match.startsWith("bcd")).isFalse();
20652075
assertThat(match.startsWith("c")).isFalse();
2076+
}
2077+
2078+
@Test
2079+
public void matchStartsWith_threeChars() {
2080+
Substring.Match match = Substring.first("bcd").in("abcde").get();
2081+
assertThat(match.startsWith("")).isTrue();
2082+
assertThat(match.startsWith("b")).isTrue();
2083+
assertThat(match.startsWith("bc")).isTrue();
2084+
assertThat(match.startsWith("bcd")).isTrue();
2085+
assertThat(match.startsWith("bcde")).isFalse();
2086+
assertThat(match.startsWith("c")).isFalse();
2087+
assertThat(match.startsWith("d")).isFalse();
2088+
assertThat(match.startsWith("e")).isFalse();
2089+
}
2090+
2091+
@Test
2092+
public void matchStartsWith_withSkip() {
2093+
Substring.Match match = Substring.first("bc").in("abcd").get();
20662094
assertThat(match.skip(1, 0).startsWith("c")).isTrue();
20672095
}
20682096

20692097
@Test
2070-
public void matchEndsWith_emptyMatch() {
2098+
public void matchStartsWith_withLimit() {
2099+
Substring.Match match = Substring.first("bc").in("abcd").get();
2100+
assertThat(match.limit(1).startsWith("b")).isTrue();
2101+
assertThat(match.limit(1).startsWith("bc")).isFalse();
2102+
}
2103+
2104+
@Test
2105+
public void matchEndsWith_empty() {
20712106
Substring.Match match = Substring.first("").in("abc").get();
20722107
assertThat(match.endsWith("")).isTrue();
20732108
assertThat(match.endsWith("c")).isFalse();
20742109
}
20752110

20762111
@Test
2077-
public void matchEndsWith_nonEmptyMatch() {
2112+
public void matchEndsWith_singleChars() {
2113+
Substring.Match match = Substring.first("b").in("abcd").get();
2114+
assertThat(match.endsWith("")).isTrue();
2115+
assertThat(match.endsWith("b")).isTrue();
2116+
assertThat(match.endsWith("bc")).isFalse();
2117+
assertThat(match.endsWith("ab")).isFalse();
2118+
assertThat(match.endsWith("d")).isFalse();
2119+
}
2120+
2121+
@Test
2122+
public void matchEndsWith_twoChars() {
20782123
Substring.Match match = Substring.first("bc").in("abcd").get();
20792124
assertThat(match.endsWith("")).isTrue();
20802125
assertThat(match.endsWith("c")).isTrue();
20812126
assertThat(match.endsWith("bc")).isTrue();
20822127
assertThat(match.endsWith("bcd")).isFalse();
20832128
assertThat(match.endsWith("d")).isFalse();
2129+
}
2130+
2131+
@Test
2132+
public void matchEndsWith_threeChars() {
2133+
Substring.Match match = Substring.first("bcd").in("abcde").get();
2134+
assertThat(match.endsWith("")).isTrue();
2135+
assertThat(match.endsWith("cd")).isTrue();
2136+
assertThat(match.endsWith("bcd")).isTrue();
2137+
assertThat(match.endsWith("abcd")).isFalse();
2138+
assertThat(match.endsWith("de")).isFalse();
2139+
}
2140+
2141+
@Test
2142+
public void matchEndsWith_withLimit() {
2143+
Substring.Match match = Substring.first("bc").in("abcd").get();
20842144
assertThat(match.limit(1).endsWith("b")).isTrue();
2145+
assertThat(match.limit(1).endsWith("")).isTrue();
2146+
assertThat(match.limit(1).endsWith("bc")).isFalse();
2147+
}
2148+
2149+
@Test
2150+
public void matchEndsWith_withSkip() {
2151+
Substring.Match match = Substring.first("bcd").in("abcde").get();
2152+
assertThat(match.skip(1, 1).endsWith("")).isTrue();
2153+
assertThat(match.skip(1, 1).endsWith("c")).isTrue();
2154+
assertThat(match.skip(1, 1).endsWith("cd")).isFalse();
2155+
assertThat(match.skip(1, 1).endsWith("bc")).isFalse();
20852156
}
20862157

20872158
@Test public void or_toString() {

0 commit comments

Comments
 (0)