blob: c268ba2e1f7332e57fe058d53627eea6b455f99f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
public class Ascii7BitMatcherTestCase {
@Test
public void testThatListedCharsAreLegal() {
assertTrue(new Ascii7BitMatcher("a").matches("aaaa"));
assertTrue(new Ascii7BitMatcher("ab").matches("abbbbbbbbb"));
assertTrue(new Ascii7BitMatcher("ab").matches("bbbbbbbbbba"));
assertTrue(new Ascii7BitMatcher("1").matches("1"));
}
@Test
public void requireThatNotListedCharsFail() {
assertFalse(new Ascii7BitMatcher("a").matches("b"));
}
@Test
public void testThatLegalFirstAndRestPass() {
assertTrue(new Ascii7BitMatcher("a", "").matches("a"));
assertTrue(new Ascii7BitMatcher("a", "b").matches("abbbbbbbbb"));
assertTrue(new Ascii7BitMatcher("abc", "0123").matches("a123120"));
}
@Test
public void requireThatIllegalFirstOrSecondFail() {
assertFalse(new Ascii7BitMatcher("a", "").matches("aa"));
assertFalse(new Ascii7BitMatcher("a", "b").matches("aa"));
assertFalse(new Ascii7BitMatcher("", "a").matches("a"));
assertFalse(new Ascii7BitMatcher("a", "b").matches("bb"));
assertFalse(new Ascii7BitMatcher("a", "b").matches("abbbbbx"));
}
@Test
public void requireThatNonAsciiFailConstruction() {
try {
new Ascii7BitMatcher("aæb");
Assert.fail("'æ' should not be allowed");
} catch (IllegalArgumentException e) {
assertEquals("Char 'æ' at position 1 is not valid ascii 7 bit char", e.getMessage());
}
}
}
|