@Test public void testNestedExpressions() { AttributeCompiler builder = new AttributeCompiler("(3 + (2)) - 10/5"); Source source = builder.compile(); assertEquals("((3+2)-(10/5))", source.getSource()); assertEquals((3 + (2)) - 10 / 5, ((3 + 2) - (10 / 5))); builder = new AttributeCompiler("(3 - (2)) - 10/5"); source = builder.compile(); assertEquals("((3-2)-(10/5))", source.getSource()); assertEquals((3 - (2)) - 10 / 5, ((3 - 2) - (10 / 5))); builder = new AttributeCompiler("(3 - (2+7)) - 10/5"); source = builder.compile(); assertEquals("((3-(2+7))-(10/5))", source.getSource()); assertEquals((3 - (2 + 7)) - 10 / 5, ((3 - (2 + 7)) - (10 / 5))); assertEquals(-8, ((3 - (2 + 7)) - (10 / 5))); builder = new AttributeCompiler("(3 - (2+7)) - 10/(5-3)"); source = builder.compile(); assertEquals("((3-(2+7))-(10/(5-3)))", source.getSource()); assertEquals((3 - (2 + 7)) - 10 / (5 - 3), ((3 - (2 + 7)) - (10 / (5 - 3)))); builder = new AttributeCompiler("(modelName.num - (2*(7-1))) - 10/(modelName.num-3)"); source = builder.compile(); List<ModelSource> modelSourceList = new ArrayList<>(); source.getModelSource(modelSourceList); for (ModelSource modelSource : modelSourceList) modelSource.setGetter("getNum"); assertEquals( "((scope.modelName.getNum()-(2*(7-1)))-(10/(scope.modelName.getNum()-3)))", source.getSource()); }
@Test public void testStringAdditionCompilation() { AttributeCompiler builder = new AttributeCompiler("getStringValue() + 'orange ' + getIntValue()"); Source getter = builder.compile(); assertEquals("((scope.getStringValue()+\"orange \")+scope.getIntValue())", getter.getSource()); builder = new AttributeCompiler("isTrue() ? 'abcdefg ' + getIntValue() : getStringValue()"); getter = builder.compile(); assertEquals( "scope.isTrue()?(\"abcdefg \"+scope.getIntValue()):scope.getStringValue()", getter.getSource()); }
@Test public void testStringCompilation() { AttributeCompiler builder = new AttributeCompiler("xyz('Martin Luther King Jr.')"); Source getter = builder.compile(); assertEquals("scope.xyz(\"Martin Luther King Jr.\")", getter.getSource()); builder = new AttributeCompiler("xyz('Martin Luther King\\'s Jr.')"); getter = builder.compile(); assertEquals("scope.xyz(\"Martin Luther King's Jr.\")", getter.getSource()); builder = new AttributeCompiler("xyz('Martin \"Luther\" King\\'s Jr.')"); getter = builder.compile(); assertEquals("scope.xyz(\"Martin \\\"Luther\\\" King's Jr.\")", getter.getSource()); }