|
| 1 | +import QtQuick 2.0 |
| 2 | +import QtTest 1.3 |
| 3 | +import "../command-parser.js" as CommandParser |
| 4 | + |
| 5 | +TestCase { |
| 6 | + name: "QuickCommandParser" |
| 7 | + |
| 8 | + function compareValues(actual, expected) { |
| 9 | + compare(actual.length, expected.length); |
| 10 | + for (var i = 0; i < expected.length; i++) { |
| 11 | + compare(actual[i], expected[i]); |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + function test_plainValuesRemainSeparate() { |
| 16 | + var result = CommandParser.parseCommandLine("colour red green blue"); |
| 17 | + |
| 18 | + compare(result.name, "colour"); |
| 19 | + compareValues(result.values, ["red", "green", "blue"]); |
| 20 | + } |
| 21 | + |
| 22 | + function test_quotedMultiWordValue() { |
| 23 | + var result = CommandParser.parseCommandLine('myname "Firstname Lastname"'); |
| 24 | + |
| 25 | + compare(result.name, "myname"); |
| 26 | + compareValues(result.values, ["Firstname Lastname"]); |
| 27 | + } |
| 28 | + |
| 29 | + function test_mixedValues() { |
| 30 | + var result = CommandParser.parseCommandLine('greeting hello "Hello world" goodbye'); |
| 31 | + |
| 32 | + compareValues(result.values, ["hello", "Hello world", "goodbye"]); |
| 33 | + } |
| 34 | + |
| 35 | + function test_whitespace() { |
| 36 | + var result = CommandParser.parseCommandLine(' greeting\t"Hello world" goodbye '); |
| 37 | + |
| 38 | + compare(result.name, "greeting"); |
| 39 | + compareValues(result.values, ["Hello world", "goodbye"]); |
| 40 | + } |
| 41 | + |
| 42 | + function test_escapedCharacters() { |
| 43 | + var result = CommandParser.parseCommandLine('message "Say \\"hello\\" from C:\\\\Temp"'); |
| 44 | + |
| 45 | + compareValues(result.values, ['Say "hello" from C:\\Temp']); |
| 46 | + } |
| 47 | + |
| 48 | + function test_escapedSpaceOutsideQuotes() { |
| 49 | + var result = CommandParser.parseCommandLine("myname Firstname\\ Lastname"); |
| 50 | + |
| 51 | + compareValues(result.values, ["Firstname Lastname"]); |
| 52 | + } |
| 53 | + |
| 54 | + function test_invalidRows() { |
| 55 | + compare(CommandParser.parseCommandLine(""), null); |
| 56 | + compare(CommandParser.parseCommandLine("command"), null); |
| 57 | + compare(CommandParser.parseCommandLine('command ""'), null); |
| 58 | + compare(CommandParser.parseCommandLine('command "unclosed value'), null); |
| 59 | + } |
| 60 | +} |
0 commit comments