forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckedTemplateRequireTypeSafeTest.java
77 lines (63 loc) · 2.75 KB
/
CheckedTemplateRequireTypeSafeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package io.quarkus.qute.deployment.typesafe;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.TemplateException;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.test.QuarkusUnitTest;
public class CheckedTemplateRequireTypeSafeTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(Templates.class, Fool.class)
.addAsResource(new StringAsset(
"Hello {name}!"
+ "{any} "
+ "{inject:fool.getJoke(null)} "
+ "{inject:fool.getJoke(identifier)} "
+ "{#each name.chars.iterator}"
// {it_index} is not considered an error because the binding is registered by the loop section !}
+ "{it_index}."
// however, {index} is an error
+ "{index}"
+ "{it}"
+ "{/each}"),
"templates/CheckedTemplateRequireTypeSafeTest/hola.txt"))
.assertException(t -> {
Throwable e = t;
TemplateException te = null;
while (e != null) {
if (e instanceof TemplateException) {
te = (TemplateException) e;
break;
}
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found incorrect expressions (3)"), te.getMessage());
assertTrue(te.getMessage().contains("any"), te.getMessage());
assertTrue(te.getMessage().contains("identifier"), te.getMessage());
assertTrue(te.getMessage().contains("index"), te.getMessage());
});
@Test
public void testValidation() {
fail();
}
@CheckedTemplate // requireTypeSafeExpressions=true by default
static class Templates {
static native TemplateInstance hola(String name);
}
@Singleton
@Named
public static class Fool {
public String getJoke(Integer id) {
return "ok";
}
}
}