-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better windows argument generation with tests
- Loading branch information
Showing
3 changed files
with
145 additions
and
27 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,91 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Paket.Bootstrapper.Tests | ||
{ | ||
[TestFixture] | ||
public class WindowsProcessArgumentsTests | ||
{ | ||
private void Verify(string expected, params string[] argv) | ||
{ | ||
var result = WindowsProcessArguments.ToString(argv); | ||
Assert.That(result, Is.EqualTo(expected)); | ||
} | ||
|
||
[Test] | ||
public void Multiple_parameters_are_separated_by_spaces() | ||
{ | ||
Verify("Hello World", "Hello", "World"); | ||
} | ||
|
||
[Test] | ||
public void No_quotes_are_added_when_not_needed() | ||
{ | ||
Verify("Hello_World", "Hello_World"); | ||
} | ||
|
||
[Test] | ||
public void Quotes_are_added_when_arg_contains_space() | ||
{ | ||
Verify(@"""Hello World""", "Hello World"); | ||
} | ||
|
||
[Test] | ||
public void Quote_is_escaped_inside() | ||
{ | ||
Verify(@"Hello\""World", @"Hello""World"); | ||
} | ||
|
||
[Test] | ||
public void Quote_is_escaped_at_start() | ||
{ | ||
Verify(@"\""HelloWorld", @"""HelloWorld"); | ||
} | ||
|
||
[Test] | ||
public void Quote_is_escaped_at_end() | ||
{ | ||
Verify(@"HelloWorld\""", @"HelloWorld"""); | ||
} | ||
|
||
[Test] | ||
public void Backslash_alone_not_escaped() | ||
{ | ||
Verify(@"Hello\World", @"Hello\World"); | ||
} | ||
|
||
[Test] | ||
public void Backslash_escaped_if_at_end_and_need_quote() | ||
{ | ||
Verify(@"""Hello World\\""", @"Hello World\"); | ||
} | ||
|
||
[Test] | ||
public void Backslash_not_escaped_if_at_end_and_no_need_to_need_quote() | ||
{ | ||
Verify(@"Hello_World\", @"Hello_World\"); | ||
} | ||
|
||
[Test] | ||
public void Backslash_before_quote_escaped() | ||
{ | ||
Verify(@"Hello\\\""World", @"Hello\""World"); | ||
} | ||
|
||
[Test] | ||
public void Odd_backslash_escaped() | ||
{ | ||
Verify(@"""a\\\\b c"" d e", @"a\\b c", "d", "e"); | ||
} | ||
|
||
[Test] | ||
public void Even_backslash_escaped() | ||
{ | ||
Verify(@"""a\\\\\b c"" d e", @"a\\\b c", "d", "e"); | ||
} | ||
} | ||
} |