|
| 1 | +'use babel'; |
| 2 | + |
| 3 | +/* eslint-disable no-underscore-dangle */ |
| 4 | +import ScriptOptionsView from '../lib/script-options-view'; |
| 5 | + |
| 6 | +describe('ScriptOptionsView', () => { |
| 7 | + describe('splitArgs', () => { |
| 8 | + [{ |
| 9 | + text: '', |
| 10 | + expectedArgs: [], |
| 11 | + description: 'returns an empty array for empty string', |
| 12 | + }, { |
| 13 | + text: ' \t\n', |
| 14 | + expectedArgs: [], |
| 15 | + description: 'returns an empty array for just whitespace', |
| 16 | + }, { |
| 17 | + text: 'arg1 arg2', |
| 18 | + expectedArgs: ['arg1', 'arg2'], |
| 19 | + description: 'splits arguments on whitespace', |
| 20 | + }, { |
| 21 | + text: 'arg1=val1 arg2', |
| 22 | + expectedArgs: ['arg1=val1', 'arg2'], |
| 23 | + description: 'keeps argument values', |
| 24 | + }, { |
| 25 | + text: '"foo bar" arg2', |
| 26 | + expectedArgs: ['foo bar', 'arg2'], |
| 27 | + description: 'does not split quoted arguments on whitespace', |
| 28 | + }, { |
| 29 | + text: '\'foo bar\' arg2', |
| 30 | + expectedArgs: ['foo bar', 'arg2'], |
| 31 | + description: 'recognizes single quotes', |
| 32 | + }, { |
| 33 | + text: '"foo bar" "another string"', |
| 34 | + expectedArgs: ['foo bar', 'another string'], |
| 35 | + description: 'handles multiple quoted arguments', |
| 36 | + }, { |
| 37 | + text: '\'foo bar\' \'another string\'', |
| 38 | + expectedArgs: ['foo bar', 'another string'], |
| 39 | + description: 'handles multiple single quoted arguments', |
| 40 | + }, { |
| 41 | + text: '"foo bar" \'another string\'', |
| 42 | + expectedArgs: ['foo bar', 'another string'], |
| 43 | + description: 'handles multiple quoted arguments, with mixed single and double quotes', |
| 44 | + }, { |
| 45 | + text: 'arg1="foo bar"', |
| 46 | + expectedArgs: ['arg1=foo bar'], |
| 47 | + description: 'strips quotes from argument values', |
| 48 | + }, { |
| 49 | + text: 'arg1=\'foo bar\'', |
| 50 | + expectedArgs: ['arg1=foo bar'], |
| 51 | + description: 'strips single quotes from argument values', |
| 52 | + }, { |
| 53 | + text: '-e \'(load "{FILE_ACTIVE}")\'', |
| 54 | + expectedArgs: ['-e', '(load "{FILE_ACTIVE}")'], |
| 55 | + description: 'keeps nested quotes intact', |
| 56 | + }, { |
| 57 | + text: 'we"ird way to inc"l"ude spaces in arg"s', |
| 58 | + expectedArgs: ['weird way to include spaces in args'], |
| 59 | + description: 'supports multiple top level quotes', |
| 60 | + }].forEach(({ text, expectedArgs, description }) => { |
| 61 | + it(description, () => { |
| 62 | + const args = ScriptOptionsView.splitArgs(text); |
| 63 | + expect(args).toEqual(expectedArgs); |
| 64 | + }); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments