Search in sources :

Example 26 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testSingleElementMinusDisjointSet.

@Test
public void testSingleElementMinusDisjointSet() throws Exception {
    IntervalSet s = IntervalSet.of(15, 15);
    IntervalSet s2 = IntervalSet.of(1, 5);
    s2.add(10, 20);
    // 15 - {1..5, 10..20} = {}
    String expecting = "{}";
    String result = s.subtract(s2).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 27 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testRmMiddleRange.

@Test
public void testRmMiddleRange() throws Exception {
    IntervalSet s = IntervalSet.of(1, 10);
    s.add(-3, -3);
    s.remove(5);
    String expecting = "{-3, 1..4, 6..10}";
    String result = s.toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 28 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testSize.

@Test
public void testSize() throws Exception {
    IntervalSet s = IntervalSet.of(20, 30);
    s.add(50, 55);
    s.add(5, 19);
    String expecting = "32";
    String result = String.valueOf(s.size());
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 29 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testNotEqualSet.

@Test
public void testNotEqualSet() throws Exception {
    IntervalSet vocabulary = IntervalSet.of(1, 1000);
    IntervalSet s = IntervalSet.of(1, 1000);
    String expecting = "{}";
    String result = (s.complement(vocabulary)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 30 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testComplement2.

@Test
public void testComplement2() throws Exception {
    IntervalSet s = IntervalSet.of(100, 101);
    IntervalSet s2 = IntervalSet.of(100, 102);
    String expecting = "102";
    String result = (s.complement(s2)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Aggregations

IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)84 Test (org.junit.Test)48 ATNState (org.antlr.v4.runtime.atn.ATNState)11 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)10 ATN (org.antlr.v4.runtime.atn.ATN)8 ArrayList (java.util.ArrayList)7 Grammar (org.antlr.v4.tool.Grammar)7 Interval (org.antlr.v4.runtime.misc.Interval)6 SetTransition (org.antlr.v4.runtime.atn.SetTransition)5 UnicodeSet (com.ibm.icu.text.UnicodeSet)4 HashMap (java.util.HashMap)4 Token (org.antlr.runtime.Token)4 NotSetTransition (org.antlr.v4.runtime.atn.NotSetTransition)4 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)4 LinkedHashMap (java.util.LinkedHashMap)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)3 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)3 DecisionState (org.antlr.v4.runtime.atn.DecisionState)3 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)3 Transition (org.antlr.v4.runtime.atn.Transition)3