1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .springframework .expression .spel .standard .SpelExpressionParser ;
25
25
26
26
import static org .assertj .core .api .Assertions .assertThat ;
27
+ import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
27
28
28
29
/**
29
30
* Parse some expressions and check we get the AST we expect.
@@ -42,6 +43,58 @@ class ParsingTests {
42
43
@ Nested
43
44
class Miscellaneous {
44
45
46
+ @ Test
47
+ void supportedCharactersInIdentifiers () {
48
+ parseCheck ("#var='value'" );
49
+ parseCheck ("#Varz='value'" );
50
+ parseCheck ("#VarZ='value'" );
51
+ parseCheck ("#_var='value'" );
52
+ parseCheck ("#$var='value'" );
53
+ parseCheck ("#_$_='value'" );
54
+
55
+ parseCheck ("age" );
56
+ parseCheck ("getAge()" );
57
+ parseCheck ("get$age()" );
58
+ parseCheck ("age" );
59
+ parseCheck ("Age" );
60
+ parseCheck ("__age" );
61
+ parseCheck ("get__age()" );
62
+
63
+ parseCheck ("person.age" );
64
+ parseCheck ("person.getAge()" );
65
+ parseCheck ("person.get$age()" );
66
+ parseCheck ("person$1.age" );
67
+ parseCheck ("person_1.Age" );
68
+ parseCheck ("person_1.__age" );
69
+ parseCheck ("Person_1.get__age()" );
70
+ }
71
+
72
+ @ Test
73
+ void unsupportedCharactersInIdentifiers () {
74
+ // Invalid syntax
75
+ assertThatIllegalStateException ()
76
+ .isThrownBy (() -> parser .parseRaw ("apple~banana" ))
77
+ .withMessage ("Unsupported character '~' (126) encountered at position 6 in expression." );
78
+
79
+ // German characters
80
+ assertThatIllegalStateException ()
81
+ .isThrownBy (() -> parser .parseRaw ("begrüssung" ))
82
+ .withMessage ("Unsupported character 'ü' (252) encountered at position 5 in expression." );
83
+ assertThatIllegalStateException ()
84
+ .isThrownBy (() -> parser .parseRaw ("Spaß" ))
85
+ .withMessage ("Unsupported character 'ß' (223) encountered at position 4 in expression." );
86
+
87
+ // Spanish characters
88
+ assertThatIllegalStateException ()
89
+ .isThrownBy (() -> parser .parseRaw ("buenos_sueños" ))
90
+ .withMessage ("Unsupported character 'ñ' (241) encountered at position 11 in expression." );
91
+
92
+ // Chinese characters
93
+ assertThatIllegalStateException ()
94
+ .isThrownBy (() -> parser .parseRaw ("have乐趣()" ))
95
+ .withMessage ("Unsupported character '乐' (20048) encountered at position 5 in expression." );
96
+ }
97
+
45
98
@ Test
46
99
void literalNull () {
47
100
parseCheck ("null" );
0 commit comments