001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: TestRegexpTrees.java,v 1.10 2008/01/02 12:11:05 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.query.regexptrees.test;
008:
009: import junit.framework.TestSuite;
010:
011: import com.hp.hpl.jena.graph.test.GraphTestBase;
012:
013: import com.hp.hpl.jena.graph.query.regexptrees.*;
014:
015: /**
016: Test useful properties of regexp trees.
017: @author hedgehog
018: */
019: public class TestRegexpTrees extends GraphTestBase {
020: public TestRegexpTrees(String name) {
021: super (name);
022: }
023:
024: public static TestSuite suite() {
025: return new TestSuite(TestRegexpTrees.class);
026: }
027:
028: protected Object[][] equalities = { { new EndOfLine(), "EOL" },
029: { new EndOfLine(), "EOL" }, { new StartOfLine(), "SOL" },
030: { new StartOfLine(), "SOL" }, { new AnySingle(), "ANY" },
031: { new AnySingle(), "ANY" },
032: { new Paren(new AnySingle()), "(ANY)" },
033: { new Paren(new EndOfLine()), "(EOL)" },
034: { Text.create("hello"), "hello" },
035: { Text.create("goodbye"), "goodbye" },
036: { new AnyOf("abcde"), "any[abcde]" },
037: { new AnyOf("defgh"), "any[defgh]" },
038: { new NoneOf("pqrst"), "none[pqrst]" },
039: { new NoneOf("12345"), "none[12345]" },
040: { new BackReference(1), "back(1)" },
041: { new BackReference(2), "back(2)" } };
042:
043: public void testEqualities() {
044: for (int i = 0; i < equalities.length; i += 1)
045: for (int j = 0; j < equalities.length; j += 1) {
046: Object[] A = equalities[i], B = equalities[j];
047: boolean equal = A[1].equals(B[1]);
048: if (A[0].equals(B[0]) != equal)
049: fail(A[0] + " should be "
050: + (equal ? "equal to " : "different from ")
051: + B[0]);
052: }
053: }
054:
055: public void testConstantsDefinition() {
056: assertEquals(RegexpTree.EOL, new EndOfLine());
057: assertEquals(RegexpTree.SOL, new StartOfLine());
058: assertEquals(RegexpTree.ANY, new AnySingle());
059: }
060:
061: public void testExtractOperandFromOneOrMore() {
062: testExtractFromOneOrMore(RegexpTree.EOL);
063: testExtractFromOneOrMore(RegexpTree.SOL);
064: testExtractFromOneOrMore(RegexpTree.ANY);
065: }
066:
067: public void testExtractOperandFromZeroOrMore() {
068: testExtractFromZeroOrMore(RegexpTree.EOL);
069: testExtractFromZeroOrMore(RegexpTree.SOL);
070: testExtractFromZeroOrMore(RegexpTree.ANY);
071: }
072:
073: public void testExtractOperandFromOptional() {
074: testExtractFromOptional(RegexpTree.EOL);
075: testExtractFromOptional(RegexpTree.SOL);
076: testExtractFromOptional(RegexpTree.ANY);
077: }
078:
079: public void testLiteralContents() {
080: assertEquals("hello", Text.create("hello").getString());
081: }
082:
083: public void testParenOperand() {
084: assertSame(RegexpTree.EOL, new Paren(RegexpTree.EOL)
085: .getOperand());
086: }
087:
088: public void testParenIndex() {
089: assertEquals(0, new Paren(RegexpTree.EOL).getIndex());
090: assertEquals(1, new Paren(RegexpTree.EOL, 1).getIndex());
091: assertEquals(17, new Paren(RegexpTree.NON, 17).getIndex());
092: }
093:
094: public void testBackReference() {
095: assertEquals(2, new BackReference(2).getIndex());
096: }
097:
098: protected void testExtractFromOneOrMore(RegexpTree operand) {
099: assertSame(operand, new OneOrMore(operand).getOperand());
100: }
101:
102: protected void testExtractFromZeroOrMore(RegexpTree operand) {
103: assertSame(operand, new ZeroOrMore(operand).getOperand());
104: }
105:
106: protected void testExtractFromOptional(RegexpTree operand) {
107: assertSame(operand, new Optional(operand).getOperand());
108: }
109: }
110:
111: /*
112: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
113: All rights reserved.
114:
115: Redistribution and use in source and binary forms, with or without
116: modification, are permitted provided that the following conditions
117: are met:
118:
119: 1. Redistributions of source code must retain the above copyright
120: notice, this list of conditions and the following disclaimer.
121:
122: 2. Redistributions in binary form must reproduce the above copyright
123: notice, this list of conditions and the following disclaimer in the
124: documentation and/or other materials provided with the distribution.
125:
126: 3. The name of the author may not be used to endorse or promote products
127: derived from this software without specific prior written permission.
128:
129: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
130: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
131: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
132: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
133: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
134: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
135: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
136: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
137: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
138: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139: */
|