|
| 1 | +import { expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { normalizeCliCommand } from './normalize-cli-command.js'; |
| 4 | + |
| 5 | +it('strips outer CLI wrapper double quotes', () => { |
| 6 | + expect(normalizeCliCommand('"echo foo"')).toBe('echo foo'); |
| 7 | +}); |
| 8 | + |
| 9 | +it('strips outer CLI wrapper single quotes', () => { |
| 10 | + expect(normalizeCliCommand("'echo foo'")).toBe('echo foo'); |
| 11 | +}); |
| 12 | + |
| 13 | +it('strips quotes around a single wrapped token', () => { |
| 14 | + expect(normalizeCliCommand('"echo"')).toBe('echo'); |
| 15 | + expect(normalizeCliCommand("'echo'")).toBe('echo'); |
| 16 | +}); |
| 17 | + |
| 18 | +it('preserves quotes in well-formed shell commands', () => { |
| 19 | + expect(normalizeCliCommand('"/usr/local/bin/mytool" --flag "some value"')).toBe( |
| 20 | + '"/usr/local/bin/mytool" --flag "some value"', |
| 21 | + ); |
| 22 | +}); |
| 23 | + |
| 24 | +it('preserves well-formed shell commands with multiple quote sets', () => { |
| 25 | + expect( |
| 26 | + normalizeCliCommand('"/usr/local/bin/mytool" --flag "some value" --other "last arg"'), |
| 27 | + ).toBe('"/usr/local/bin/mytool" --flag "some value" --other "last arg"'); |
| 28 | +}); |
| 29 | + |
| 30 | +it('preserves single quotes in well-formed shell commands', () => { |
| 31 | + expect(normalizeCliCommand("'printf' '%s %s' foo bar")).toBe("'printf' '%s %s' foo bar"); |
| 32 | +}); |
| 33 | + |
| 34 | +it('returns unquoted input unchanged', () => { |
| 35 | + expect(normalizeCliCommand('echo foo')).toBe('echo foo'); |
| 36 | +}); |
| 37 | + |
| 38 | +it('returns an empty string unchanged', () => { |
| 39 | + expect(normalizeCliCommand('')).toBe(''); |
| 40 | +}); |
| 41 | + |
| 42 | +it('leaves ambiguous input unchanged', () => { |
| 43 | + expect(normalizeCliCommand('"echo foo')).toBe('"echo foo'); |
| 44 | +}); |
| 45 | + |
| 46 | +it('leaves input with an unclosed single quote unchanged', () => { |
| 47 | + expect(normalizeCliCommand("echo foo'")).toBe("echo foo'"); |
| 48 | +}); |
| 49 | + |
| 50 | +it('leaves input with mismatched quote types unchanged', () => { |
| 51 | + expect(normalizeCliCommand('"echo foo\'')).toBe('"echo foo\''); |
| 52 | +}); |
0 commit comments