Search in sources :

Example 6 with DecimalNode

use of com.fasterxml.jackson.databind.node.DecimalNode in project template-compiler by Squarespace.

the class MessageFormatsTest method testBasicArgs.

@Test
public void testBasicArgs() {
    String actual;
    CLDR cldr = CLDR.get("en");
    MessageFormats formats = new MessageFormats(cldr);
    formats.setTimeZone("America/New_York");
    String message = "{0 select abc {ABC} def {DEF} true {T} false {F}}";
    actual = formats.formatter().format(message, args().add(new TextNode("abc")));
    assertEquals(actual, "ABC");
    actual = formats.formatter().format(message, args().add(new TextNode("def")));
    assertEquals(actual, "DEF");
    actual = formats.formatter().format(message, args().add(new TextNode("ghi")));
    assertEquals(actual, "");
    actual = formats.formatter().format(message, args().add(new LongNode(123)));
    assertEquals(actual, "");
    actual = formats.formatter().format(message, args().add(BooleanNode.TRUE));
    assertEquals(actual, "T");
    actual = formats.formatter().format(message, args().add(BooleanNode.FALSE));
    assertEquals(actual, "F");
    actual = formats.formatter().format(message, args().add(NullNode.getInstance()));
    assertEquals(actual, "");
    actual = formats.formatter().format(message, args().add(MissingNode.getInstance()));
    assertEquals(actual, "");
    actual = formats.formatter().format(message, args().add(JsonUtils.createArrayNode()));
    assertEquals(actual, "");
    actual = formats.formatter().format(message, args().add(JsonUtils.createObjectNode()));
    assertEquals(actual, "");
    message = "{0 plural one {ONE} other {OTHER}}";
    actual = formats.formatter().format(message, args().add("123"));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add("1"));
    assertEquals(actual, "ONE");
    actual = formats.formatter().format(message, args().add("undefined"));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add(new LongNode(123)));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add(new LongNode(1)));
    assertEquals(actual, "ONE");
    actual = formats.formatter().format(message, args().add(BooleanNode.TRUE));
    assertEquals(actual, "ONE");
    actual = formats.formatter().format(message, args().add(BooleanNode.FALSE));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add(MissingNode.getInstance()));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add(NullNode.getInstance()));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add(new TextNode("abc")));
    assertEquals(actual, "OTHER");
    actual = formats.formatter().format(message, args().add(JsonUtils.createObjectNode()));
    assertEquals(actual, "OTHER");
    ObjectNode money = JsonUtils.createObjectNode();
    money.put("decimalValue", new DecimalNode(new BigDecimal("1.2320001")));
    actual = formats.formatter().format(message, args().add(money));
    assertEquals(actual, "OTHER");
    money.put("decimalValue", new DecimalNode(new BigDecimal("1")));
    actual = formats.formatter().format(message, args().add(money));
    assertEquals(actual, "ONE");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CLDR(com.squarespace.cldrengine.CLDR) TextNode(com.fasterxml.jackson.databind.node.TextNode) LongNode(com.fasterxml.jackson.databind.node.LongNode) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) MessageFormats(com.squarespace.template.MessageFormats) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 7 with DecimalNode

use of com.fasterxml.jackson.databind.node.DecimalNode in project ksql by confluentinc.

the class RecordNodeTest method shouldUseExactDecimals.

@Test
public void shouldUseExactDecimals() {
    // Given:
    final RecordNode node = new RecordNode("topic", NullNode.getInstance(), new DecimalNode(new BigDecimal("10.000")), Optional.empty(), Optional.empty(), Optional.empty());
    // When:
    final Record result = node.build();
    // Then:
    assertThat(result.value(), is(new BigDecimal("10.000")));
}
Also used : Record(io.confluent.ksql.test.tools.Record) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)7 BigDecimal (java.math.BigDecimal)5 LongNode (com.fasterxml.jackson.databind.node.LongNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 BigIntegerNode (com.fasterxml.jackson.databind.node.BigIntegerNode)2 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)2 FloatNode (com.fasterxml.jackson.databind.node.FloatNode)2 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 NullNode (com.fasterxml.jackson.databind.node.NullNode)2 NumericNode (com.fasterxml.jackson.databind.node.NumericNode)2 ShortNode (com.fasterxml.jackson.databind.node.ShortNode)2 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)2 CodeException (com.squarespace.template.CodeException)2 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2 Apfloat (org.apfloat.Apfloat)2