@@ -66,14 +66,24 @@ public void testStrings() {
6666 assertEquals ("hello\\ \n world" , unquoteString (source ("\" hello\\ \\ \\ nworld\" " )));
6767 assertEquals ("hello\\ \" world" , unquoteString (source ("\" hello\\ \\ \\ \" world\" " )));
6868
69- // test for unescaped strings: ?"...."
70- assertEquals ("hello\" world" , unquoteString (source ("?\" hello\" world\" " )));
71- assertEquals ("hello\\ \" world" , unquoteString (source ("?\" hello\\ \" world\" " )));
72- assertEquals ("hello'world" , unquoteString (source ("?\" hello'world\" " )));
73- assertEquals ("hello\\ nworld" , unquoteString (source ("?\" hello\\ nworld\" " )));
74- assertEquals ("hello\\ \\ nworld" , unquoteString (source ("?\" hello\\ \\ nworld\" " )));
75- assertEquals ("hello\\ \\ \\ nworld" , unquoteString (source ("?\" hello\\ \\ \\ nworld\" " )));
76- assertEquals ("hello\\ \\ \\ \" world" , unquoteString (source ("?\" hello\\ \\ \\ \" world\" " )));
69+ // test for unescaped strings: """...."""
70+ assertEquals ("hello\" world" , unquoteString (source ("\" \" \" hello\" world\" \" \" " )));
71+ assertEquals ("hello\\ \" world" , unquoteString (source ("\" \" \" hello\\ \" world\" \" \" " )));
72+ assertEquals ("\" \" hello\" \\ \" world\" \" \" " , unquoteString (source ("\" \" \" \" \" hello\" \\ \" world\" \" \" \" \" \" " )));
73+ assertEquals ("hello'world" , unquoteString (source ("\" \" \" hello'world\" \" \" " )));
74+ assertEquals ("hello'world" , unquoteString (source ("\" \" \" hello\' world\" \" \" " )));
75+ assertEquals ("hello\\ 'world" , unquoteString (source ("\" \" \" hello\\ \' world\" \" \" " )));
76+ assertEquals ("hello\\ nworld" , unquoteString (source ("\" \" \" hello\\ nworld\" \" \" " )));
77+ assertEquals ("hello\\ \\ nworld" , unquoteString (source ("\" \" \" hello\\ \\ nworld\" \" \" " )));
78+ assertEquals ("hello\\ \\ \\ nworld" , unquoteString (source ("\" \" \" hello\\ \\ \\ nworld\" \" \" " )));
79+ assertEquals ("hello\\ \\ \\ \" world" , unquoteString (source ("\" \" \" hello\\ \\ \\ \" world\" \" \" " )));
80+ assertEquals ("\" \\ \" " , unquoteString (source ("\" \" \" \" \\ \" \" \" \" " )));
81+ assertEquals ("\\ \" \" \" " , unquoteString (source ("\" \" \" \\ \" \" \" \" \" \" " )));
82+ assertEquals ("\" \\ \" \" " , unquoteString (source ("\" \" \" \" \\ \" \" \" \" \" " )));
83+ assertEquals ("\" \" \\ \" " , unquoteString (source ("\" \" \" \" \" \\ \" \" \" \" " )));
84+ assertEquals ("\" \" " , unquoteString (source ("\" \" \" \" \" \" \" \" " )));
85+ assertEquals ("\" \" \" \" " , unquoteString (source ("\" \" \" \" \" \" \" \" \" \" " )));
86+ assertEquals ("" , unquoteString (source ("\" \" \" \" \" \" " )));
7787 }
7888
7989 public void testLiterals () {
@@ -100,18 +110,80 @@ public void testDoubleQuotedString() {
100110
101111 public void testSingleQuotedUnescapedStringDisallowed () {
102112 ParsingException e = expectThrows (ParsingException .class , () -> expr ("?'hello world'" ));
103- assertEquals ("line 1:2: Use double quotes [\" ] to define string literals, not single quotes [ ']" ,
113+ assertEquals ("line 1:2: Use triple double quotes [\" \" \" ] to define unescaped string literals, not [? ']" ,
104114 e .getMessage ());
105- e = expectThrows (ParsingException .class , () -> parser .createStatement ("process where name== ?'hello world'" ));
106- assertEquals ("line 1:22 : Use double quotes [\" ] to define string literals, not single quotes [ ']" ,
115+ e = expectThrows (ParsingException .class , () -> parser .createStatement ("process where name == ?'hello world'" ));
116+ assertEquals ("line 1:24 : Use triple double quotes [\" \" \" ] to define unescaped string literals, not [? ']" ,
107117 e .getMessage ());
108118 }
109119
110- public void testDoubleQuotedUnescapedString () {
111- // "hello \" world"
112- Expression parsed = expr ("?\" hello \\ \" world!\" " );
113- Expression expected = new Literal (null , "hello \\ \" world!" , DataTypes .KEYWORD );
114- assertEquals (expected , parsed );
120+ public void testDoubleQuotedUnescapedStringForbidden () {
121+ ParsingException e = expectThrows (ParsingException .class , () -> expr ("?\" hello world\" " ));
122+ assertEquals ("line 1:2: Use triple double quotes [\" \" \" ] to define unescaped string literals, not [?\" ]" ,
123+ e .getMessage ());
124+ e = expectThrows (ParsingException .class , () -> parser .createStatement ("process where name == ?\" hello world\" " ));
125+ assertEquals ("line 1:24: Use triple double quotes [\" \" \" ] to define unescaped string literals, not [?\" ]" ,
126+ e .getMessage ());
127+ }
128+
129+ public void testTripleDoubleQuotedUnescapedString () {
130+ // """hello world!"""" == """foobar""" => hello world! = foobar
131+ String str = "\" \" \" hello world!\" \" \" == \" \" \" foobar\" \" \" " ;
132+ String expectedStrLeft = "hello world!" ;
133+ String expectedStrRight = "foobar" ;
134+ Expression parsed = expr (str );
135+ assertEquals (Equals .class , parsed .getClass ());
136+ Equals eq = (Equals ) parsed ;
137+ assertEquals (Literal .class , eq .left ().getClass ());
138+ assertEquals (expectedStrLeft , ((Literal ) eq .left ()).value ());
139+ assertEquals (Literal .class , eq .right ().getClass ());
140+ assertEquals (expectedStrRight , ((Literal ) eq .right ()).value ());
141+
142+ // """""hello""world!"""" == """"foo"bar""""" => ""hello""world!" = "foo""bar""
143+ str = " \" \" \" \" \" hello\" \" world!\" \" \" \" == \" \" \" \" foo\" bar\" \" \" \" \" " ;
144+ expectedStrLeft = "\" \" hello\" \" world!\" " ;
145+ expectedStrRight = "\" foo\" bar\" \" " ;
146+ parsed = expr (str );
147+ assertEquals (Equals .class , parsed .getClass ());
148+ eq = (Equals ) parsed ;
149+ assertEquals (Literal .class , eq .left ().getClass ());
150+ assertEquals (expectedStrLeft , ((Literal ) eq .left ()).value ());
151+ assertEquals (Literal .class , eq .right ().getClass ());
152+ assertEquals (expectedStrRight , ((Literal ) eq .right ()).value ());
153+
154+ // """""\""hello\\""\""world!\\""""" == """\\""\""foo""\\""\"bar""\\""\"""" =>
155+ // ""\""hello\\""\""world!\\"" == \\""\""foo""\\""\"bar""\\""\"
156+ str = " \" \" \" \" \" \\ \" \" hello\\ \\ \" \" \\ \" \" world!\\ \\ \" \" \" \" \" == " +
157+ " \" \" \" \\ \\ \" \" \\ \" \" foo\" \" \\ \\ \" \" \\ \" bar\" \" \\ \\ \" \" \\ \" \" \" \" " ;
158+ expectedStrLeft = "\" \" \\ \" \" hello\\ \\ \" \" \\ \" \" world!\\ \\ \" \" " ;
159+ expectedStrRight = "\\ \\ \" \" \\ \" \" foo\" \" \\ \\ \" \" \\ \" bar\" \" \\ \\ \" \" \\ \" " ;
160+ parsed = expr (str );
161+ assertEquals (Equals .class , parsed .getClass ());
162+ eq = (Equals ) parsed ;
163+ assertEquals (Literal .class , eq .left ().getClass ());
164+ assertEquals (expectedStrLeft , ((Literal ) eq .left ()).value ());
165+ assertEquals (Literal .class , eq .right ().getClass ());
166+ assertEquals (expectedStrRight , ((Literal ) eq .right ()).value ());
167+
168+ // """"""hello world!""" == """foobar"""
169+ ParsingException e = expectThrows (ParsingException .class , "Expected syntax error" ,
170+ () -> expr ("\" \" \" \" \" \" hello world!\" \" \" == \" \" \" foobar\" \" \" " ));
171+ assertThat (e .getMessage (), startsWith ("line 1:7: mismatched input 'hello' expecting {<EOF>," ));
172+
173+ // """""\"hello world!"""""" == """foobar"""
174+ e = expectThrows (ParsingException .class , "Expected syntax error" ,
175+ () -> expr ("\" \" \" \" \" \\ \" hello world!\" \" \" \" \" \" == \" \" \" foobar\" \" \" " ));
176+ assertThat (e .getMessage (), startsWith ("line 1:25: mismatched input '\" == \" ' expecting {<EOF>," ));
177+
178+ // """""\"hello world!""\"""" == """"""foobar"""
179+ e = expectThrows (ParsingException .class , "Expected syntax error" ,
180+ () -> expr ("\" \" \" \" \" \\ \" hello world!\" \" \\ \" \" \" \" == \" \" \" \" \" \" foobar\" \" \" " ));
181+ assertThat (e .getMessage (), startsWith ("line 1:37: mismatched input 'foobar' expecting {<EOF>," ));
182+
183+ // """""\"hello world!""\"""" == """""\"foobar\"\""""""
184+ e = expectThrows (ParsingException .class , "Expected syntax error" ,
185+ () -> expr ("\" \" \" \" \" \\ \" hello world!\" \" \\ \" \" \" \" == \" \" \" \" \" \\ \" foobar\\ \" \\ \" \" \" \" \" \" " ));
186+ assertEquals ("line 1:52: token recognition error at: '\" '" , e .getMessage ());
115187 }
116188
117189 public void testNumbers () {
0 commit comments