Search in sources :

Example 11 with CodeMaker

use of com.squarespace.template.CodeMaker 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 12 with CodeMaker

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

the class CoreFormattersTest method testMod.

@Test
public void testMod() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args(" 3");
    assertFormatter(MOD, args, "4", "1");
    assertFormatter(MOD, args, "5", "2");
    assertFormatter(MOD, args, "6", "0");
    // Bad modulus defaults to 2
    args = mk.args(" abc");
    assertFormatter(MOD, args, "5", "1");
    // Bad value defaults to 0
    assertFormatter(MOD, args, "\"abc\"", "0");
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 13 with CodeMaker

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

the class CoreFormattersTest method testRound.

@Test
public void testRound() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args("");
    assertFormatter(ROUND, args, "1.44", "1");
    assertFormatter(ROUND, args, "1.6", "2");
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 14 with CodeMaker

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

the class CoreFormattersTest method testOutput.

@Test
public void testOutput() throws CodeException {
    CodeMaker mk = maker();
    Arguments args = mk.args(":1:2:3");
    assertFormatter(OUTPUT, args, "{}", "1 2 3");
}
Also used : Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Test(org.testng.annotations.Test)

Example 15 with CodeMaker

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

the class InternationalFormattersTest method testDateTimeFormatter.

@Test
public void testDateTimeFormatter() throws Exception {
    // epoch timestamp for: "Thu, 02 Nov 2017 18:26:57 GMT"
    String json = "1509647217000";
    CodeMaker mk = maker();
    // DEFAULTING
    assertEquals(format(en_US, DATETIME, mk.args(" xyz foo"), json), "2017, 14:26 EDT");
    // ENGLISH
    assertEquals(format(en_US, DATETIME, mk.args(""), json), "November 2, 2017");
    assertEquals(format(en_US, DATETIME, mk.args(" short"), json), "11/2/17, 2:26 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" long"), json), "November 2, 2017 at 2:26:57 PM EDT");
    assertEquals(format(en_US, DATETIME, mk.args(" date"), json), "11/2/17");
    assertEquals(format(en_US, DATETIME, mk.args(" date:short"), json), "11/2/17");
    assertEquals(format(en_US, DATETIME, mk.args(" time"), json), "2:26 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" time:medium"), json), "2:26:57 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" date:full time:short"), json), "Thursday, November 2, 2017 at 2:26 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" time:hm date:short"), json), "11/2/17, 2:26 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" date:yMMMd time:hm"), json), "Nov 2, 2017, 2:26 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" date:yMMMd time:medium wrap:short"), json), "Nov 2, 2017, 2:26:57 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" time:medium wrap:full date:yMMMd"), json), "Nov 2, 2017 at 2:26:57 PM");
    // Bare skeletons
    assertEquals(format(en_US, DATETIME, mk.args(" date:short hm"), json), "11/2/17, 2:26 PM");
    assertEquals(format(en_US, DATETIME, mk.args(" yMMMd hm"), json), "Nov 2, 2017, 2:26 PM");
    // FRENCH
    assertEquals(format(fr, DATETIME, mk.args(" date:short"), json), "02/11/2017");
    assertEquals(format(fr, DATETIME, mk.args(" time:medium"), json), "14:26:57");
    assertEquals(format(fr, DATETIME, mk.args(" date:full time:short"), json), "jeudi 2 novembre 2017 à 14:26");
    assertEquals(format(fr, DATETIME, mk.args(" time:hm date:short"), json), "02/11/2017 2:26 PM");
    assertEquals(format(fr, DATETIME, mk.args(" date:yMMMd time:hm"), json), "2 nov. 2017 à 2:26 PM");
    assertEquals(format(fr, DATETIME, mk.args(" date:yMMMd time:medium wrap:short"), json), "2 nov. 2017 14:26:57");
    assertEquals(format(fr, DATETIME, mk.args(" time:medium wrap:full date:yMMMd"), json), "2 nov. 2017 à 14:26:57");
}
Also used : 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