|
| 1 | +package com.github.jknack.handlebars.issues; |
| 2 | + |
| 3 | +import com.github.jknack.handlebars.Handlebars; |
| 4 | +import com.github.jknack.handlebars.v4Test; |
| 5 | +import org.junit.BeforeClass; |
| 6 | +import org.junit.Test; |
| 7 | + |
| 8 | +import static org.junit.Assert.assertEquals; |
| 9 | + |
| 10 | +import java.io.IOException; |
| 11 | +import java.util.Arrays; |
| 12 | + |
| 13 | +public class Issue614 extends v4Test { |
| 14 | + |
| 15 | + @Override protected void configure(Handlebars handlebars) { |
| 16 | + try { |
| 17 | + handlebars.registerHelpers("helpers.js", |
| 18 | + "Handlebars.registerHelper('number', function(value) {\n" |
| 19 | + + " return value;\n" |
| 20 | + + "});\n" |
| 21 | + + "\n" |
| 22 | + + "Handlebars.registerHelper('len', function(array) {\n" |
| 23 | + + " return array.length;\n" |
| 24 | + + "});"); |
| 25 | + } catch (Exception x) { |
| 26 | + throw new IllegalStateException(x); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void shouldFavorIntOverDouble() throws Exception { |
| 32 | + shouldCompileTo("{{number this}}", $("hash", 3), "3"); |
| 33 | + shouldCompileTo("{{number this}}", $("hash", 3.1), "3.1"); |
| 34 | + |
| 35 | + shouldCompileTo("{{len this}}", $("hash", new Object[]{1, 2, 3, 4}), "4"); |
| 36 | + shouldCompileTo("{{len this}}", $("hash", Arrays.asList(1, 2, 3, 4)), "4"); |
| 37 | + } |
| 38 | +} |
0 commit comments