|
9 | 9 | import static com.google.common.labs.parse.Parser.string; |
10 | 10 | import static com.google.common.labs.parse.Parser.word; |
11 | 11 | import static com.google.common.labs.parse.Parser.zeroOrMore; |
| 12 | +import static com.google.common.labs.parse.Parser.zeroOrMoreCharsIn; |
12 | 13 | import static com.google.common.truth.Truth.assertThat; |
13 | 14 | import static com.google.common.truth.Truth8.assertThat; |
14 | 15 | import static com.google.mu.util.CharPredicate.is; |
@@ -3193,6 +3194,62 @@ public void zeroOrMore_charMatcher_matchesMultipleTimes_source() { |
3193 | 3194 | .containsExactly("[ 123 ]"); |
3194 | 3195 | } |
3195 | 3196 |
|
| 3197 | + @Test |
| 3198 | + public void zeroOrMore_charSet_matchesZeroTimes() { |
| 3199 | + Parser<String> parser = zeroOrMoreCharsIn("[0-9]").between("[", "]"); |
| 3200 | + assertThat(parser.parse("[]")).isEmpty(); |
| 3201 | + assertThat(parser.parseToStream("[]")).containsExactly(""); |
| 3202 | + assertThat(parser.parseSkipping(Character::isWhitespace, "[ ]")).isEmpty(); |
| 3203 | + assertThat(parser.skipping(Character::isWhitespace).parseToStream("[ ]")).containsExactly(""); |
| 3204 | + } |
| 3205 | + |
| 3206 | + @Test |
| 3207 | + public void zeroOrMore_charSet_matchesZeroTimes_source() { |
| 3208 | + Parser<String> parser = zeroOrMoreCharsIn("[0-9]").between("[", "]"); |
| 3209 | + assertThat(parser.source().parse("[]")).isEqualTo("[]"); |
| 3210 | + assertThat(parser.source().parseToStream("[]")).containsExactly("[]"); |
| 3211 | + assertThat(parser.source().parseSkipping(Character::isWhitespace, "[ ]")).isEqualTo("[ ]"); |
| 3212 | + assertThat(parser.source().skipping(Character::isWhitespace).parseToStream("[ ]")).containsExactly("[ ]"); |
| 3213 | + } |
| 3214 | + |
| 3215 | + @Test |
| 3216 | + public void zeroOrMore_charSet_matchesOneTime() { |
| 3217 | + Parser<String> parser = zeroOrMoreCharsIn("[0-9]").between("[", "]"); |
| 3218 | + assertThat(parser.parse("[1]")).isEqualTo("1"); |
| 3219 | + assertThat(parser.parseToStream("[1]")).containsExactly("1"); |
| 3220 | + assertThat(parser.parseSkipping(Character::isWhitespace, "[ 1 ]")).isEqualTo("1"); |
| 3221 | + assertThat(parser.skipping(Character::isWhitespace).parseToStream("[ 1 ]")).containsExactly("1"); |
| 3222 | + } |
| 3223 | + |
| 3224 | + @Test |
| 3225 | + public void zeroOrMore_charSet_matchesOneTime_source() { |
| 3226 | + Parser<String> parser = zeroOrMoreCharsIn("[0-9]").between("[", "]"); |
| 3227 | + assertThat(parser.source().parse("[1]")).isEqualTo("[1]"); |
| 3228 | + assertThat(parser.source().parseToStream("[1]")).containsExactly("[1]"); |
| 3229 | + assertThat(parser.source().parseSkipping(Character::isWhitespace, "[ 1 ]")).isEqualTo("[ 1 ]"); |
| 3230 | + assertThat(parser.source().skipping(Character::isWhitespace).parseToStream("[ 1 ]")) |
| 3231 | + .containsExactly("[ 1 ]"); |
| 3232 | + } |
| 3233 | + |
| 3234 | + @Test |
| 3235 | + public void zeroOrMore_charSet_matchesMultipleTimes() { |
| 3236 | + Parser<String> parser = zeroOrMoreCharsIn("[0-9]").between("[", "]"); |
| 3237 | + assertThat(parser.parse("[123]")).isEqualTo("123"); |
| 3238 | + assertThat(parser.parseToStream("[123]")).containsExactly("123"); |
| 3239 | + assertThat(parser.parseSkipping(Character::isWhitespace, "[ 123 ]")).isEqualTo("123"); |
| 3240 | + assertThat(parser.skipping(Character::isWhitespace).parseToStream("[ 123 ]")).containsExactly("123"); |
| 3241 | + } |
| 3242 | + |
| 3243 | + @Test |
| 3244 | + public void zeroOrMore_charSet_matchesMultipleTimes_source() { |
| 3245 | + Parser<String> parser = zeroOrMoreCharsIn("[0-9]").between("[", "]"); |
| 3246 | + assertThat(parser.source().parse("[123]")).isEqualTo("[123]"); |
| 3247 | + assertThat(parser.source().parseToStream("[123]")).containsExactly("[123]"); |
| 3248 | + assertThat(parser.source().parseSkipping(Character::isWhitespace, "[ 123 ]")).isEqualTo("[ 123 ]"); |
| 3249 | + assertThat(parser.source().skipping(Character::isWhitespace).parseToStream("[ 123 ]")) |
| 3250 | + .containsExactly("[ 123 ]"); |
| 3251 | + } |
| 3252 | + |
3196 | 3253 | @Test |
3197 | 3254 | public void skipping_propagatesThroughOptional() { |
3198 | 3255 | Parser<String> foo = string("foo"); |
|
0 commit comments