XPathParser { protected List<Component> parsePredicates( TokenStream tokens ) { List<Component> predicates = new ArrayList<Component>(); while (tokens.canConsume('[')) { predicates.add(collapse(parseExpr(tokens))); tokens.consume(']'); } return predicates; } XPathParser( TypeSystem context ); Component parseXPath( String xpath );  }
@Test public void shouldParsePredicatesWithAttributeEqualsStringLiteral() { assertThat(parser.parsePredicates(tokenize("[@jcr:title='something']")), is(predicates(comparison(attributeNameTest(nameTest("jcr", "title")), Operator.EQUAL_TO, literal("something"))))); }
@Test public void shouldParsePredicatesWithAttributeLessThanIntegerLiteral() { assertThat(parser.parsePredicates(tokenize("[@ex:age<3]")), is(predicates(comparison(attributeNameTest(nameTest("ex", "age")), Operator.LESS_THAN, literal("3"))))); }
@Test public void shouldParsePredicatesWithAttributeLikeStringLiteral() { assertThat(parser.parsePredicates(tokenize("[jcr:like(@jcr:title,'%something%')]")), is(predicates(functionCall(nameTest("jcr", "like"), attributeNameTest(nameTest("jcr", "title")), literal("%something%"))))); }
@Test public void shouldParsePredicatesWithAndedExpressions() { assertThat(parser.parsePredicates(tokenize("[@ex:age<3 and jcr:like(@jcr:title,'%something%')]")), is(predicates(and(comparison(attributeNameTest(nameTest("ex", "age")), Operator.LESS_THAN, literal("3")), functionCall(nameTest("jcr", "like"), attributeNameTest(nameTest("jcr", "title")), literal("%something%")))))); }
@Test public void shouldParsePredicatesWithOredExpressions() { assertThat(parser.parsePredicates(tokenize("[@ex:age<3 or jcr:like(@jcr:title,'%something%')]")), is(predicates(or(comparison(attributeNameTest(nameTest("ex", "age")), Operator.LESS_THAN, literal("3")), functionCall(nameTest("jcr", "like"), attributeNameTest(nameTest("jcr", "title")), literal("%something%")))))); }
@Test public void shouldParsePredicatesWithMultipleSeparatePredicates() { assertThat(parser.parsePredicates(tokenize("[@ex:age<3][jcr:like(@jcr:title,'%something%')]")), is(predicates(comparison(attributeNameTest(nameTest("ex", "age")), Operator.LESS_THAN, literal("3")), functionCall(nameTest("jcr", "like"), attributeNameTest(nameTest("jcr", "title")), literal("%something%"))))); }
@Test public void shouldParsePredicatesWhenThereIsOnlyOnePredicate() { assertThat(parser.parsePredicates(tokenize("[foo]")), is(predicates(nameTest("foo")))); }
@Test public void shouldParsePredicatesWhenThereAreMultiplePredicates() { assertThat(parser.parsePredicates(tokenize("['foo']['bar']")), is(predicates(literal("foo"), literal("bar")))); assertThat(parser.parsePredicates(tokenize("[foo][bar]")), is(predicates(nameTest("foo"), nameTest("bar")))); }