Search in sources :

Example 51 with IntervalSet

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

the class TestIntervalSet method testSubtractOfCompletelyCoveredRange.

@Test
public void testSubtractOfCompletelyCoveredRange() throws Exception {
    IntervalSet s = IntervalSet.of(10, 20);
    IntervalSet s2 = IntervalSet.of(1, 25);
    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 52 with IntervalSet

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

the class TestIntervalSet method testNotSet.

@Test
public void testNotSet() throws Exception {
    IntervalSet vocabulary = IntervalSet.of(1, 1000);
    IntervalSet s = IntervalSet.of(50, 60);
    s.add(5);
    s.add(250, 300);
    String expecting = "{1..4, 6..49, 61..249, 301..1000}";
    String result = (s.complement(vocabulary)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 53 with IntervalSet

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

the class TestIntervalSet method testRmRightSide.

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

Example 54 with IntervalSet

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

the class TestIntervalSet method testToList.

@Test
public void testToList() throws Exception {
    IntervalSet s = IntervalSet.of(20, 25);
    s.add(50, 55);
    s.add(5, 5);
    String expecting = "[5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55]";
    String result = String.valueOf(s.toList());
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 55 with IntervalSet

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

the class TestIntervalSet method testSubtractOfOverlappingRangeFromRight.

@Test
public void testSubtractOfOverlappingRangeFromRight() throws Exception {
    IntervalSet s = IntervalSet.of(10, 20);
    IntervalSet s2 = IntervalSet.of(15, 25);
    String expecting = "{10..14}";
    String result = (s.subtract(s2)).toString();
    assertEquals(expecting, result);
    IntervalSet s3 = IntervalSet.of(20, 25);
    expecting = "{10..19}";
    result = (s.subtract(s3)).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