Search in sources :

Example 1 with CodeMaker

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

the class InternationalFormattersTest method testDateTimeFieldFormatter.

@Test
public void testDateTimeFieldFormatter() throws Exception {
    String json = "1509647217000";
    CodeMaker mk = maker();
    assertEquals(format(en_US, DATETIMEFIELD, mk.args(" dd"), json), "02");
    assertEquals(format(en_US, DATETIMEFIELD, mk.args(" MMMM"), json), "November");
    assertEquals(format(en_US, DATETIMEFIELD, mk.args(" EEE"), json), "Thu");
    assertEquals(format(en_US, DATETIMEFIELD, mk.args(" EEEE"), json), "Thursday");
    assertEquals(format(fr, DATETIMEFIELD, mk.args(" dd"), json), "02");
    assertEquals(format(fr, DATETIMEFIELD, mk.args(" MMMM"), json), "novembre");
    assertEquals(format(fr, DATETIMEFIELD, mk.args(" EEE"), json), "jeu.");
    assertEquals(format(fr, DATETIMEFIELD, mk.args(" EEEE"), json), "jeudi");
}
Also used : CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 2 with CodeMaker

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

the class CoreFormattersTest method testPluralize.

@Test
public void testPluralize() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args("");
    assertFormatter(PLURALIZE, "0", "s");
    assertFormatter(PLURALIZE, "1", "");
    assertFormatter(PLURALIZE, "2", "s");
    assertFormatter(PLURALIZE, "3.1415", "s");
    args = mk.args(" A");
    assertFormatter(PLURALIZE, args, "0", "A");
    assertFormatter(PLURALIZE, args, "1", "");
    assertFormatter(PLURALIZE, args, "2", "A");
    assertFormatter(PLURALIZE, args, "100", "A");
    args = mk.args("/A/B");
    assertFormatter(PLURALIZE, args, "0", "B");
    assertFormatter(PLURALIZE, args, "1", "A");
    assertFormatter(PLURALIZE, args, "2", "B");
    assertFormatter(PLURALIZE, args, "100", "B");
    // Too many args
    args = mk.args(":1:2:3:4");
    assertInvalidArgs(PLURALIZE, args);
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 3 with CodeMaker

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

the class CoreFormattersTest method testProp.

@Test
public void testProp() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args(" foo");
    assertFormatter(PROP, args, "{ \"foo\": 123 }", "123");
    args = mk.args(" bar");
    assertFormatter(PROP, args, "{ \"bar\": \"123\" }", "123");
    args = mk.args(" foo");
    assertFormatter(PROP, args, "{ \"bar\": 123 }", "");
    args = mk.args(" bar quux");
    assertFormatter(PROP, args, "{ \"bar\": 123 }", "");
    args = mk.args(" foo bar");
    assertFormatter(PROP, args, "{}", "");
    runner.exec("f-prop-%N.html");
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 4 with CodeMaker

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

the class CoreFormattersTest method testCycle.

@Test
public void testCycle() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args(" A B C");
    String result = "";
    for (int i = -6; i < 6; i++) {
        result += format(CYCLE, args, Integer.toString(i));
    }
    assertEquals("CABCABCABCAB", result);
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 5 with CodeMaker

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

the class CoreFormattersTest method testTruncate.

@Test
public void testTruncate() throws CodeException {
    CodeMaker mk = maker();
    assertFormatter(TRUNCATE, mk.args(""), "\"foo\"", "foo");
    assertFormatter(TRUNCATE, mk.args(" 5 .."), "\"foo bar baz\"", "foo ..");
    assertFormatter(TRUNCATE, mk.args(" 100 .."), "\"foo bar baz\"", "foo bar baz");
    Context ctx = compiler().newExecutor().template("{@|truncate xyz}").safeExecution(true).execute();
    assertEquals(ctx.getErrors().size(), 1);
    assertEquals(ctx.getErrors().get(0).getType(), SyntaxErrorType.FORMATTER_ARGS_INVALID);
    runner.exec("f-truncate-%N.html");
}
Also used : Context(com.squarespace.template.Context) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Aggregations

CodeMaker (com.squarespace.template.CodeMaker)19 Test (org.testng.annotations.Test)19 Arguments (com.squarespace.template.Arguments)10 Context (com.squarespace.template.Context)4 CodeBuilder (com.squarespace.template.CodeBuilder)1 Instruction (com.squarespace.template.Instruction)1