Search in sources :

Example 6 with Arguments

use of com.squarespace.template.Arguments in project template-compiler by Squarespace.

the class ContentFormattersTest method testResize.

@Test
public void testResize() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args(" 50");
    String json = "\"100x200\"";
    assertFormatter(RESIZED_HEIGHT_FOR_WIDTH, args, json, "100");
    assertFormatter(RESIZED_WIDTH_FOR_HEIGHT, args, json, "25");
    args = mk.args(" 600");
    json = "\"1200x2400\"";
    assertFormatter(RESIZED_HEIGHT_FOR_WIDTH, args, json, "1200");
    assertFormatter(RESIZED_WIDTH_FOR_HEIGHT, args, json, "300");
    assertInvalidArgs(RESIZED_HEIGHT_FOR_WIDTH, mk.args(""));
    assertInvalidArgs(RESIZED_WIDTH_FOR_HEIGHT, mk.args(""));
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 7 with Arguments

use of com.squarespace.template.Arguments in project template-compiler by Squarespace.

the class LegacyMoneyFormatFactoryTest method cldr.

private String cldr(String tag, String currency, String number, boolean narrow) throws CodeException {
    Arguments args = mk.args(narrow ? " symbol:narrow" : " ");
    CLDR_MONEY.validateArgs(args);
    Locale locale = Locale.forLanguageTag(tag);
    Context ctx = new Context(moneyJson(number, currency), new StringBuilder(), locale);
    Variables variables = new Variables("@", ctx.node());
    CLDR_MONEY.apply(ctx, args, variables);
    return variables.first().node().asText();
}
Also used : Locale(java.util.Locale) Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables) Arguments(com.squarespace.template.Arguments)

Example 8 with Arguments

use of com.squarespace.template.Arguments in project template-compiler by Squarespace.

the class InternationalFormattersTest method testExtraArgument.

public void testExtraArgument() throws Exception {
    if (isJava8()) {
        try {
            MONEY_FORMATTER.validateArgs(new Arguments(new StringView(" en-US bad-arg")));
            Assert.fail("expected ArgumentsException, too many arguments passed");
        } catch (ArgumentsException e) {
        // fall through
        }
    }
}
Also used : ArgumentsException(com.squarespace.template.ArgumentsException) Arguments(com.squarespace.template.Arguments) StringView(com.squarespace.template.StringView)

Example 9 with Arguments

use of com.squarespace.template.Arguments in project template-compiler by Squarespace.

the class LegacyMoneyFormatFactoryTest method cldr.

private String cldr(CLDR.Locale locale, String currency, String number, boolean narrow) throws CodeException {
    Arguments args = mk.args(narrow ? " symbol:narrow" : " ");
    CLDR_MONEY.validateArgs(args);
    Context ctx = new Context(moneyJson(number, currency));
    ctx.cldrLocale(locale);
    Variables variables = new Variables("@", ctx.node());
    CLDR_MONEY.apply(ctx, args, variables);
    return variables.first().node().asText();
}
Also used : Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables) Arguments(com.squarespace.template.Arguments)

Example 10 with Arguments

use of com.squarespace.template.Arguments in project template-compiler by Squarespace.

the class LegacyMoneyFormatFactoryTest method legacy.

private String legacy(String locale, String currency, String number) throws CodeException {
    Arguments args = mk.args(" " + locale);
    LEGACY_MONEY.validateArgs(args);
    Context ctx = new Context(moneyJson(number, currency));
    Variables variables = new Variables("@", ctx.node());
    LEGACY_MONEY.apply(ctx, args, variables);
    return variables.first().node().asText();
}
Also used : Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables) Arguments(com.squarespace.template.Arguments)

Aggregations

Arguments (com.squarespace.template.Arguments)14 CodeMaker (com.squarespace.template.CodeMaker)10 Test (org.testng.annotations.Test)10 Context (com.squarespace.template.Context)5 Variables (com.squarespace.template.Variables)3 ArgumentsException (com.squarespace.template.ArgumentsException)1 CodeBuilder (com.squarespace.template.CodeBuilder)1 Instruction (com.squarespace.template.Instruction)1 StringView (com.squarespace.template.StringView)1 Locale (java.util.Locale)1