@Test public void testOneVariableRef() { ParseResult result = new RepetitionProduction(new ExpressionProduction()).parse("foo", null); assertTrue(result.isSuccess()); List<? extends Token> tokens = result.getTokens(); assertNotNull(tokens); assertThat(tokens, hasSize(1)); MatcherAssert.<List<? extends Token>>assertThat(tokens, not(nullValue())); assertThat(tokens.get(0), instanceOf(VariableRefToken.class)); assertThat(((VariableRefToken) tokens.get(0)).getName(), equalTo("foo")); }
@Test public void testTwoMethodCalls() { ParseResult result = new RepetitionProduction(new PatternProduction(","), new ExpressionProduction()) .parse(", foo(apa), bar(banan)", null); assertTrue(result.isSuccess()); List<? extends Token> tokens = result.getTokens(); assertNotNull(tokens); assertThat(tokens, hasSize(2)); MatcherAssert.<List<? extends Token>>assertThat(tokens, not(nullValue())); assertThat(tokens.get(0), instanceOf(MethodCallToken.class)); MethodCallToken methodCall = (MethodCallToken) tokens.get(0); assertThat(methodCall.getName(), equalTo("foo")); assertThat(tokens.get(1), instanceOf(MethodCallToken.class)); methodCall = (MethodCallToken) tokens.get(1); assertThat(methodCall.getName(), equalTo("bar")); }
@Test public void testTwoVariableRefs() { ParseResult result = new RepetitionProduction(new PatternProduction(","), new ExpressionProduction()) .parse(", foo, bar", null); assertTrue(result.isSuccess()); List<? extends Token> tokens = result.getTokens(); assertNotNull(tokens); assertThat(tokens, hasSize(2)); MatcherAssert.<List<? extends Token>>assertThat(tokens, not(nullValue())); assertThat(tokens.get(0), instanceOf(VariableRefToken.class)); VariableRefToken variable = (VariableRefToken) tokens.get(0); assertThat(variable.getName(), equalTo("foo")); assertThat(tokens.get(1), instanceOf(VariableRefToken.class)); variable = (VariableRefToken) tokens.get(1); assertThat(variable.getName(), equalTo("bar")); }