-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegExTokenFactoryTest.java
65 lines (56 loc) · 1.84 KB
/
RegExTokenFactoryTest.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class RegExTokenFactoryTest {
@Test
public void testMatchFixed() {
RegExTokenFactory f = new RegExTokenFactory("hi");
f.setText("XXhiXX");
boolean found = f.find(2);
assertTrue(found);
assertEquals(2, f.getTokenStartPosition());
assertEquals(2, f.getTokenLength());
assertEquals("hi", f.getTokenText());
}
@Test
public void testMatchFlexible() {
RegExTokenFactory f = new RegExTokenFactory("ha*");
f.setText("XhaaaX");
boolean found = f.find(1);
assertTrue(found);
assertEquals(1, f.getTokenStartPosition());
assertEquals(4, f.getTokenLength());
assertEquals("haaa", f.getTokenText());
}
@Test
public void testMatchThereAndNotEarlier() {
RegExTokenFactory f = new RegExTokenFactory("hi");
f.setText("XhiXhiX");
boolean found = f.find(4);
assertTrue(found);
assertEquals(4, f.getTokenStartPosition());
}
@Test
public void testMatchThereAndNotLater() {
RegExTokenFactory f = new RegExTokenFactory("hi");
f.setText("XhiXhiX");
boolean found = f.find(1);
assertTrue(found);
assertEquals(1, f.getTokenStartPosition());
}
@Test
public void testNoMatchNowhere() {
RegExTokenFactory f = new RegExTokenFactory("hi");
f.setText("abc");
assertFalse(f.find(0));
assertFalse(f.find(1));
assertFalse(f.find(2));
}
@Test(expected = IndexOutOfBoundsException.class)
public void testStartOutOfBounds() {
RegExTokenFactory f = new RegExTokenFactory("hi");
f.setText("abc");
f.find(4); // this call must throw an IOOB exception
}
}