/
StringLiteralTest.java
78 lines (71 loc) · 3.2 KB
/
StringLiteralTest.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
78
/**
* Copyright (C) 2006-2018 INRIA and contributors
* Spoon - http://spoon.gforge.inria.fr/
*
* This software is governed by the CeCILL-C License under French law and
* abiding by the rules of distribution of free software. You can use, modify
* and/or redistribute the software under the terms of the CeCILL-C license as
* circulated by CEA, CNRS and INRIA at http://www.cecill.info.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package spoon.test.strings;
import org.junit.jupiter.api.Test;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
import spoon.reflect.factory.Factory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static spoon.testing.utils.ModelUtils.createFactory;
public class StringLiteralTest {
@SuppressWarnings("unused")
@Test
public void testSnippetFullClass() {
Factory factory = createFactory();
CtClass<?> clazz = factory.Code().createCodeSnippetStatement(
"class StringValueUTF {\n" +
" String f0 = \"toto\";\n" +
" String f1 = \"\\n\";\n" +
" char c1 = '\\n';\n" +
" String f2 = \"\\u20ac\";\n" +
" char c2 = '\\u20ac';\n" +
" String f3 = \"€\";\n" +
" char c3 = '€';\n" +
" String f4 = \"\\t\";\n" +
" char c4 = '\\t';\n" +
" String f5 = \" \";\n" +
" char c5 = ' ';\n" +
" String f6 = \"€\\u20ac\";\n" +
"}"
).compile();
CtField<?> f0 = (CtField<?>) clazz.getFields().toArray()[0];
CtField<?> f1 = (CtField<?>) clazz.getFields().toArray()[1];
CtField<?> c1 = (CtField<?>) clazz.getFields().toArray()[2];
CtField<?> f2 = (CtField<?>) clazz.getFields().toArray()[3];
CtField<?> c2 = (CtField<?>) clazz.getFields().toArray()[4];
CtField<?> f3 = (CtField<?>) clazz.getFields().toArray()[5];
CtField<?> c3 = (CtField<?>) clazz.getFields().toArray()[6];
CtField<?> f4 = (CtField<?>) clazz.getFields().toArray()[7];
CtField<?> c4 = (CtField<?>) clazz.getFields().toArray()[8];
CtField<?> f5 = (CtField<?>) clazz.getFields().toArray()[9];
CtField<?> c5 = (CtField<?>) clazz.getFields().toArray()[10];
CtField<?> f6 = (CtField<?>) clazz.getFields().toArray()[11];
assertEquals("java.lang.String f0 = \"toto\";", f0.toString());
assertEquals("java.lang.String f1 = \"\\n\";", f1.toString());
assertEquals("char c1 = '\\n';", c1.toString());
assertEquals("java.lang.String f2 = \"€\";", f2.toString());
assertEquals("char c2 = '€';", c2.toString());
assertEquals("java.lang.String f3 = \"€\";", f3.toString());
assertEquals("char c3 = '€';", c3.toString());
assertEquals("java.lang.String f4 = \"\\t\";", f4.toString());
assertEquals("char c4 = '\\t';", c4.toString());
assertEquals("java.lang.String f5 = \" \";", f5.toString());
assertEquals("char c5 = ' ';", c5.toString());
// spoon cannot handle unicode and unicode in the same literal
// assertEquals("java.lang.String f6 = \"€\\u20ac\";", f6.toString());
}
}