SHL-116: Rewrote tokenizer to allow quotes escaping
* Allow unmatched quotes if at the end 30e34da977289ed52221ae0b4e9f5eabdf392a60 * Allow trailing key without an option b6814870a28f5a4bc9509556a847acec5db10523 * Allow completions in unmatched quotes f93bbc7d44461595eb299797a36bd10bc23b83f9 * Fix case where parser would think it is at end but in quotes is intended for it (as a option marker) a2a710463761668c67810448bd6803ce67bba35e * Fix corner case of empty quoted string 4fdcfbf2e2cbbee9a7a624735be81ed98fc67ed6 * Handle dangling dash dash at the end 40dd0bbc867b45c8cb8c37a82d5afe93ccbcb960 * Add author tag 9e3a6e0c0964d39e51f6496c97bfdf74c153bd9d
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.shell.core;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -112,6 +113,45 @@ public class TokenizerTests {
|
||||
assertEquals(singletonMap("foo", "bar \"fizz"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowKeyOnlyIfAtTheEnd() {
|
||||
Map<String, String> result = tokenize("--foo bar fizz --bozz ");
|
||||
Map<String, String> expected = new HashMap<String, String>();
|
||||
expected.put("", "fizz");
|
||||
expected.put("foo", "bar");
|
||||
expected.put("bozz", "");
|
||||
assertEquals(expected, result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueQuotationAllowUnfinished() {
|
||||
Tokenizer tokenizer = new Tokenizer("--foo \"bar bazz\" --bizz \"unfinished bizness ", true);
|
||||
Map<String, String> result = tokenizer.getTokens();
|
||||
Map<String, String> expected = new HashMap<String, String>();
|
||||
expected.put("foo", "bar bazz");
|
||||
expected.put("bizz", "unfinished bizness ");
|
||||
assertEquals(expected, result);
|
||||
assertTrue(tokenizer.lastValueHadQuote());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueQuotationAllowUnfinishedEvenWithEmptyContent() {
|
||||
Tokenizer tokenizer = new Tokenizer("--foo \"bar bazz\" --bizz \"", true);
|
||||
Map<String, String> result = tokenizer.getTokens();
|
||||
Map<String, String> expected = new HashMap<String, String>();
|
||||
expected.put("foo", "bar bazz");
|
||||
expected.put("bizz", "");
|
||||
assertEquals(expected, result);
|
||||
assertTrue(tokenizer.lastValueHadQuote());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPendingDashDash() {
|
||||
Map<String, String> result = tokenize("--foo bar --");
|
||||
assertEquals(singletonMap("foo", "bar"), result);
|
||||
}
|
||||
|
||||
private Map<String, String> tokenize(String what) {
|
||||
return new Tokenizer(what).getTokens();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user