StyleExpression { public void evaluate(final AttributedStringBuilder buff, final String expression) { requireNonNull(buff); requireNonNull(expression); String translated = InterpolationHelper.substVars(expression, this::style, false); buff.appendAnsi(translated); } StyleExpression();  StyleExpression(final StyleResolver resolver); void evaluate(final AttributedStringBuilder buff, final String expression); AttributedString evaluate(final String expression);  }
@Test public void evaluateExpressionWithPrefixAndSuffix() { AttributedString result = underTest.evaluate("foo @{bold bar} baz"); System.out.println(result.toAnsi()); assert result.equals(new AttributedStringBuilder().append("foo ").append("bar", BOLD).append(" baz").toAttributedString()); }
@Test public void evaluateExpressionWithPrefix() { AttributedString result = underTest.evaluate("foo @{bold bar}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedStringBuilder().append("foo ").append("bar", BOLD).toAttributedString()); }
@Test public void evaluateExpressionWithSuffix() { AttributedString result = underTest.evaluate("@{bold foo} bar"); System.out.println(result.toAnsi()); assert result.equals(new AttributedStringBuilder().append("foo", BOLD).append(" bar").toAttributedString()); }
@Test public void evaluateExpression() { AttributedString result = underTest.evaluate("@{bold foo}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedString("foo", BOLD)); }
@Test public void evaluateExpressionWithDefault() { AttributedString result = underTest.evaluate("@{.foo:-bold foo}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedString("foo", BOLD)); }
@Test public void evaluateExpressionWithMultipleReplacements() { AttributedString result = underTest.evaluate("@{bold foo} @{fg:red bar} @{underline baz}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedStringBuilder().append("foo", BOLD).append(" ").append("bar", DEFAULT.foreground(RED)).append(" ").append("baz", DEFAULT.underline()).toAttributedString()); }
@Test public void evaluateExpressionWithRecursiveReplacements() { AttributedString result = underTest.evaluate("@{underline foo @{fg:cyan bar}}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedStringBuilder().append("foo ", DEFAULT.underline()).append("bar", DEFAULT.underline().foreground(CYAN)).toAttributedString()); }
@Test public void evaluateExpressionMissingVvalue() { AttributedString result = underTest.evaluate("@{bold}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedString("@{bold}", DEFAULT)); }
@Test public void evaluateExpressionMissingTokens() { AttributedString result = underTest.evaluate("foo"); System.out.println(result.toAnsi()); assert result.equals(new AttributedString("foo", DEFAULT)); }
@Test public void evaluateExpressionWithPlaceholderValue() { AttributedString result = underTest.evaluate("@{bold,fg:cyan ${foo\\}}"); System.out.println(result.toAnsi()); assert result.equals(new AttributedString("${foo}", DEFAULT.bold().foreground(CYAN))); }
@Test public void evaluateWithStyleReference() { source.set("test", "very-red", "bold,fg:red"); AttributedString string = underTest.evaluate("@{.very-red foo bar}"); assert string.equals(new AttributedString("foo bar", BOLD.foreground(RED))); }