@@ -156,6 +156,30 @@ public void readQuotedString() throws Exception {
156
156
assertThat (reader .getRemaining (), equalTo ("" ));
157
157
}
158
158
159
+ @ Test
160
+ public void readSingleQuotedString () throws Exception {
161
+ final StringReader reader = new StringReader ("'hello world'" );
162
+ assertThat (reader .readQuotedString (), equalTo ("hello world" ));
163
+ assertThat (reader .getRead (), equalTo ("'hello world'" ));
164
+ assertThat (reader .getRemaining (), equalTo ("" ));
165
+ }
166
+
167
+ @ Test
168
+ public void readMixedQuotedString_doubleInsideSingle () throws Exception {
169
+ final StringReader reader = new StringReader ("'hello \" world\" '" );
170
+ assertThat (reader .readQuotedString (), equalTo ("hello \" world\" " ));
171
+ assertThat (reader .getRead (), equalTo ("'hello \" world\" '" ));
172
+ assertThat (reader .getRemaining (), equalTo ("" ));
173
+ }
174
+
175
+ @ Test
176
+ public void readMixedQuotedString_singleInsideDouble () throws Exception {
177
+ final StringReader reader = new StringReader ("\" hello 'world'\" " );
178
+ assertThat (reader .readQuotedString (), equalTo ("hello 'world'" ));
179
+ assertThat (reader .getRead (), equalTo ("\" hello 'world'\" " ));
180
+ assertThat (reader .getRemaining (), equalTo ("" ));
181
+ }
182
+
159
183
@ Test
160
184
public void readQuotedString_empty () throws Exception {
161
185
final StringReader reader = new StringReader ("" );
@@ -242,6 +266,40 @@ public void readQuotedString_invalidEscape() throws Exception {
242
266
}
243
267
}
244
268
269
+ @ Test
270
+ public void readQuotedString_invalidQuoteEscape () throws Exception {
271
+ try {
272
+ new StringReader ("'hello\\ \" \' world" ).readQuotedString ();
273
+ } catch (final CommandSyntaxException ex ) {
274
+ assertThat (ex .getType (), is (CommandSyntaxException .BUILT_IN_EXCEPTIONS .readerInvalidEscape ()));
275
+ assertThat (ex .getCursor (), is (7 ));
276
+ }
277
+ }
278
+
279
+ @ Test
280
+ public void readString_noQuotes () throws Exception {
281
+ final StringReader reader = new StringReader ("hello world" );
282
+ assertThat (reader .readString (), equalTo ("hello" ));
283
+ assertThat (reader .getRead (), equalTo ("hello" ));
284
+ assertThat (reader .getRemaining (), equalTo (" world" ));
285
+ }
286
+
287
+ @ Test
288
+ public void readString_singleQuotes () throws Exception {
289
+ final StringReader reader = new StringReader ("'hello world'" );
290
+ assertThat (reader .readString (), equalTo ("hello world" ));
291
+ assertThat (reader .getRead (), equalTo ("'hello world'" ));
292
+ assertThat (reader .getRemaining (), equalTo ("" ));
293
+ }
294
+
295
+ @ Test
296
+ public void readString_doubleQuotes () throws Exception {
297
+ final StringReader reader = new StringReader ("\" hello world\" " );
298
+ assertThat (reader .readString (), equalTo ("hello world" ));
299
+ assertThat (reader .getRead (), equalTo ("\" hello world\" " ));
300
+ assertThat (reader .getRemaining (), equalTo ("" ));
301
+ }
302
+
245
303
@ Test
246
304
public void readInt () throws Exception {
247
305
final StringReader reader = new StringReader ("1234567890" );
0 commit comments