1 6 7 package com.hp.hpl.jena.graph.query.regexptrees.test; 8 9 import junit.framework.TestSuite; 10 11 import com.hp.hpl.jena.graph.test.GraphTestBase; 12 13 import com.hp.hpl.jena.graph.query.regexptrees.*; 14 18 public class TestRegexpTrees extends GraphTestBase 19 { 20 public TestRegexpTrees( String name ) 21 { super( name ); } 22 23 public static TestSuite suite() 24 { return new TestSuite( TestRegexpTrees.class ); } 25 26 protected Object [][] equalities = 27 { 28 { new EndOfLine(), "EOL" }, 29 { new EndOfLine(), "EOL" }, 30 { new StartOfLine(), "SOL" }, 31 { new StartOfLine(), "SOL" }, 32 { new AnySingle(), "ANY" }, 33 { new AnySingle(), "ANY" }, 34 { new Paren( new AnySingle() ), "(ANY)" }, 35 { new Paren( new EndOfLine() ), "(EOL)" }, 36 { Text.create( "hello" ), "hello" }, 37 { Text.create( "goodbye" ), "goodbye" }, 38 { new AnyOf( "abcde" ), "any[abcde]" }, 39 { new AnyOf( "defgh" ), "any[defgh]" }, 40 { new NoneOf( "pqrst" ), "none[pqrst]" }, 41 { new NoneOf( "12345" ), "none[12345]" }, 42 { new BackReference( 1 ), "back(1)" }, 43 { new BackReference( 2 ), "back(2)" } 44 }; 45 46 public void testEqualities() 47 { 48 for (int i = 0; i < equalities.length; i += 1) 49 for (int j = 0; j < equalities.length; j += 1) 50 { 51 Object [] A = equalities[i], B = equalities[j]; 52 boolean equal = A[1].equals( B[1] ); 53 if (A[0].equals( B[0] ) != equal ) 54 fail( A[0] + " should be " + (equal ? "equal to " : "different from ") + B[0] ); 55 } 56 } 57 58 public void testConstantsDefinition() 59 { 60 assertEquals( RegexpTree.EOL, new EndOfLine() ); 61 assertEquals( RegexpTree.SOL, new StartOfLine() ); 62 assertEquals( RegexpTree.ANY, new AnySingle() ); 63 } 64 65 public void testExtractOperandFromOneOrMore() 66 { 67 testExtractFromOneOrMore( RegexpTree.EOL ); 68 testExtractFromOneOrMore( RegexpTree.SOL ); 69 testExtractFromOneOrMore( RegexpTree.ANY ); 70 } 71 72 public void testExtractOperandFromZeroOrMore() 73 { 74 testExtractFromZeroOrMore( RegexpTree.EOL ); 75 testExtractFromZeroOrMore( RegexpTree.SOL ); 76 testExtractFromZeroOrMore( RegexpTree.ANY ); 77 } 78 79 public void testExtractOperandFromOptional() 80 { 81 testExtractFromOptional( RegexpTree.EOL ); 82 testExtractFromOptional( RegexpTree.SOL ); 83 testExtractFromOptional( RegexpTree.ANY ); 84 } 85 86 public void testLiteralContents() 87 { assertEquals( "hello", Text.create( "hello" ).getString() ); } 88 89 public void testParenOperand() 90 { assertSame( RegexpTree.EOL, new Paren( RegexpTree.EOL ).getOperand() ); } 91 92 public void testParenIndex() 93 { assertEquals( 0, new Paren( RegexpTree.EOL ).getIndex() ); 94 assertEquals( 1, new Paren( RegexpTree.EOL, 1 ).getIndex() ); 95 assertEquals( 17, new Paren( RegexpTree.NON, 17 ).getIndex() ); } 96 97 public void testBackReference() 98 { assertEquals( 2, new BackReference( 2 ).getIndex() ); } 99 100 protected void testExtractFromOneOrMore( RegexpTree operand ) 101 { assertSame( operand, new OneOrMore( operand ).getOperand() ); } 102 103 protected void testExtractFromZeroOrMore( RegexpTree operand ) 104 { assertSame( operand, new ZeroOrMore( operand ).getOperand() ); } 105 106 protected void testExtractFromOptional( RegexpTree operand ) 107 { assertSame( operand, new Optional( operand ).getOperand() ); } 108 } 109 110 | Popular Tags |