@Test public void itAssignsValToVar() throws Exception { TagNode tagNode = (TagNode) fixture("set-val"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("primary_line_height", -1, -1)).isEqualTo(42L); }
@Test public void itAssignsValToVar() throws Exception { TagNode tagNode = (TagNode) fixture("set-val"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("primary_line_height", -1, -1)).isEqualTo(42L); }
@Test public void itConcatsStringsWithNestedExprs() throws Exception { context.put("lw_font_size_base", 10); TagNode tagNode = (TagNode) fixture("set-expr-concat"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("lw_secondary_font_size", -1, -1)).isEqualTo("font-size: 8px; "); }
@Test public void itConcatsStringsInExprs() throws Exception { context.put("lw_font_size_base", 42); TagNode tagNode = (TagNode) fixture("set-string-concat"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("lw_font_size", -1 ,-1)).isEqualTo("font-size: 42px; "); }
@Test public void itAssignsVarToVar() throws Exception { context.put("primary_font_size_num", 10); TagNode tagNode = (TagNode) fixture("set-var-exp"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("primary_line_height", -1, -1)).isEqualTo(15.0); }
@Test public void itConcatsStringsInExprs() throws Exception { context.put("lw_font_size_base", 42); TagNode tagNode = (TagNode) fixture("set-string-concat"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("lw_font_size", -1 ,-1)).isEqualTo("font-size: 42px; "); }
@Test public void itSupportsExpressionsWithFilters() throws Exception { context.put("max_size", "470"); TagNode tagNode = (TagNode) fixture("set-filter-expr"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("ie_max_size", -1 ,-1)).isEqualTo(440L); }
@Test public void itConcatsStringsWithNestedExprs() throws Exception { context.put("lw_font_size_base", 10); TagNode tagNode = (TagNode) fixture("set-expr-concat"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("lw_secondary_font_size", -1, -1)).isEqualTo("font-size: 8px; "); }
@Test public void itSupportsExpressionsWithFilters() throws Exception { context.put("max_size", "470"); TagNode tagNode = (TagNode) fixture("set-filter-expr"); tag.interpret(tagNode, interpreter); assertThat(interpreter.resolveObject("ie_max_size", -1 ,-1)).isEqualTo(440L); }
@Test public void importedContextExposesMacros() { assertThat(fixture("import")).contains("<td height=\"42\">"); MacroFunction fn = (MacroFunction) interpreter.resolveObject("pegasus.spacer", -1, -1); assertThat(fn.getName()).isEqualTo("spacer"); assertThat(fn.getArguments()).containsExactly("orientation", "size"); assertThat(fn.getDefaults()).contains(entry("orientation", "h"), entry("size", 42)); }
@Test public void testSimpleFn() { TagNode t = fixture("simple"); assertThat(t.render(interpreter).getValue()).isEmpty(); MacroFunction fn = (MacroFunction) interpreter.resolveObject("__macros__.getPath", -1, -1); assertThat(fn.getName()).isEqualTo("getPath"); assertThat(fn.getArguments()).isEmpty(); assertThat(fn.isCaller()).isFalse(); assertThat(fn.isCatchKwargs()).isFalse(); assertThat(fn.isCatchVarargs()).isFalse(); context.put("myname", "jared"); assertThat(snippet("{{ getPath() }}").render(interpreter).getValue().trim()).isEqualTo("Hello jared"); }
@Test public void importedContextExposesMacros() { assertThat(fixture("import")).contains("<td height=\"42\">"); MacroFunction fn = (MacroFunction) interpreter.resolveObject("pegasus.spacer", -1, -1); assertThat(fn.getName()).isEqualTo("spacer"); assertThat(fn.getArguments()).containsExactly("orientation", "size"); assertThat(fn.getDefaults()).contains(entry("orientation", "h"), entry("size", 42)); }
@Test public void testFnWithArgs() { TagNode t = fixture("with-args"); assertThat(t.render(interpreter).getValue()).isEmpty(); MacroFunction fn = (MacroFunction) interpreter.resolveObject("__macros__.section_link", -1, -1); assertThat(fn.getName()).isEqualTo("section_link"); assertThat(fn.getArguments()).containsExactly("link", "text"); assertThat(snippet("{{section_link('mylink', 'mytext')}}").render(interpreter).getValue().trim()).isEqualTo("link: mylink, text: mytext"); }
@Test public void testFnWithArgsWithDefVals() { TagNode t = fixture("def-vals"); assertThat(t.render(interpreter).getValue()).isEmpty(); MacroFunction fn = (MacroFunction) interpreter.resolveObject("__macros__.article", -1, -1); assertThat(fn.getArguments()).containsExactly("title", "thumb", "link", "summary", "last"); assertThat(fn.getDefaults()).contains(entry("last", false)); assertThat(snippet("{{ article('mytitle','mythumb','mylink','mysummary') }}").render(interpreter).getValue().trim()) .isEqualTo("title: mytitle, thumb: mythumb, link: mylink, summary: mysummary, last: false"); assertThat(snippet("{{ article('mytitle','mythumb','mylink','mysummary', last=true) }}").render(interpreter).getValue().trim()) .isEqualTo("title: mytitle, thumb: mythumb, link: mylink, summary: mysummary, last: true"); }
@Test public void itSupportsArraySyntax() throws Exception { context.put("i_am_seven", 7L); TagNode tagNode = (TagNode) fixture("set-array"); tag.interpret(tagNode, interpreter); List<Object> result = (List<Object>) interpreter.resolveObject("the_list", -1,-1); assertThat(result).containsExactly(1L, 2L, 3L, 7L); }
@Test public void itSupportsArraySyntax() throws Exception { context.put("i_am_seven", 7L); TagNode tagNode = (TagNode) fixture("set-array"); tag.interpret(tagNode, interpreter); List<Object> result = (List<Object>) interpreter.resolveObject("the_list", -1,-1); assertThat(result).containsExactly(1L, 2L, 3L, 7L); }
@Test public void testFnWithArgsWithDefVals() { TagNode t = fixture("def-vals"); assertThat(t.render(interpreter).getValue()).isEmpty(); MacroFunction fn = (MacroFunction) interpreter.resolveObject("__macros__.article", -1, -1); assertThat(fn.getArguments()).containsExactly("title", "thumb", "link", "summary", "last"); assertThat(fn.getDefaults()).contains(entry("last", false)); assertThat(snippet("{{ article('mytitle','mythumb','mylink','mysummary') }}").render(interpreter).getValue().trim()) .isEqualTo("title: mytitle, thumb: mythumb, link: mylink, summary: mysummary, last: false"); assertThat(snippet("{{ article('mytitle','mythumb','mylink','mysummary', last=true) }}").render(interpreter).getValue().trim()) .isEqualTo("title: mytitle, thumb: mythumb, link: mylink, summary: mysummary, last: true"); }
@Test public void testFnWithArrayDefVal() { TagNode t = fixture("array-def-val"); assertThat(t.render(interpreter).getValue()).isEmpty(); MacroFunction fn = (MacroFunction) interpreter.resolveObject("__macros__.prefix", -1, -1); assertThat(fn.getArguments()).containsExactly("property", "value", "prefixes", "prefixval"); assertThat(fn.getDefaults()).contains(entry("prefixes", Lists.newArrayList("webkit", "moz"))); }
@Test public void testFnWithArrayDefVal() { TagNode t = fixture("array-def-val"); assertThat(t.render(interpreter).getValue()).isEmpty(); MacroFunction fn = (MacroFunction) interpreter.resolveObject("__macros__.prefix", -1, -1); assertThat(fn.getArguments()).containsExactly("property", "value", "prefixes", "prefixval"); assertThat(fn.getDefaults()).contains(entry("prefixes", Lists.newArrayList("webkit", "moz"))); }
@Test public void itSupportsDictionarySyntax() throws Exception { context.put("i_am_seven", 7L); context.put("the_list", Lists.newArrayList(1L, 2L, 3L)); TagNode tagNode = (TagNode) fixture("set-dictionary"); tag.interpret(tagNode, interpreter); Map<String, Object> result = (Map<String, Object>) interpreter.resolveObject("the_dictionary", -1,-1); assertThat(result).contains(entry("seven", 7L)); }