-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #137: Follow Windows conventions when composing cmdline
- Loading branch information
Showing
3 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var argvToCommandLine = require('../').argvToCommandLine | ||
var assert = require("assert"); | ||
|
||
function check(input, expected) { | ||
assert.equal(argvToCommandLine(input), expected); | ||
} | ||
|
||
describe("argvToCommandLine", function() { | ||
describe("Plain strings", function() { | ||
it("doesn't quote plain string", function() { | ||
check(['asdf'], 'asdf'); | ||
}); | ||
it("doesn't escape backslashes", function() { | ||
check(['\\asdf\\qwer\\'], '\\asdf\\qwer\\'); | ||
}); | ||
it("doesn't escape multiple backslashes", function() { | ||
check(['asdf\\\\qwer'], 'asdf\\\\qwer'); | ||
}); | ||
it("adds backslashes before quotes", function() { | ||
check(['"asdf"qwer"'], '\\"asdf\\"qwer\\"'); | ||
}); | ||
it("escapes backslashes before quotes", function() { | ||
check(['asdf\\"qwer'], 'asdf\\\\\\"qwer'); | ||
}); | ||
}); | ||
|
||
describe("Quoted strings", function() { | ||
it("quotes string with spaces", function() { | ||
check(['asdf qwer'], '"asdf qwer"'); | ||
}); | ||
it("quotes empty string", function() { | ||
check([''], '""'); | ||
}); | ||
it("quotes string with tabs", function() { | ||
check(['asdf\tqwer'], '"asdf\tqwer"'); | ||
}); | ||
it("escapes only the last backslash", function() { | ||
check(['\\asdf \\qwer\\'], '"\\asdf \\qwer\\\\"'); | ||
}); | ||
it("doesn't escape multiple backslashes", function() { | ||
check(['asdf \\\\qwer'], '"asdf \\\\qwer"'); | ||
}); | ||
it("adds backslashes before quotes", function() { | ||
check(['"asdf "qwer"'], '"\\"asdf \\"qwer\\""'); | ||
}); | ||
it("escapes backslashes before quotes", function() { | ||
check(['asdf \\"qwer'], '"asdf \\\\\\"qwer"'); | ||
}); | ||
it("escapes multiple backslashes at the end", function() { | ||
check(['asdf qwer\\\\'], '"asdf qwer\\\\\\\\"'); | ||
}); | ||
}); | ||
|
||
describe("Multiple arguments", function() { | ||
it("joins arguments with spaces", function() { | ||
check(['asdf', 'qwer zxcv', '', '"'], 'asdf "qwer zxcv" "" \\"'); | ||
}); | ||
}); | ||
}); |