test/Shared/UnitTests/CommandLine/CommandLineTest.cs
/// <summary>
/// Verifies that you can use alternate seperators
/// </summary>
Verifies that you can use alternate seperators
Verifies that you can use alternate seperators
[Fact]
        public void CommandLineTokenizesWithAlternateSwitchChars()
        {
            var args = new[]
                           {
                               "C:\\Foo And Bar\\Some Long File.txt", "~1|Test", "~2|Some Quoted Arg", "~3|Arg with in it", "_Y-",
                               "And another",
                               "Another", "One", "Word", "Args"
                           };
            migrate::CmdLine.CommandLine.CommandEnvironment = new TestCommandEnvironment(args);
            var oldSep = migrate::CmdLine.CommandLine.CommandSeparators;
            var oldValueSep = migrate::CmdLine.CommandLine.ValueSeparators;
            migrate::CmdLine.CommandLine.CommandSeparators = new List<string>
                                                                 {
                                                                     "~",
                                                                     "_"
                                                                 };
            migrate::CmdLine.CommandLine.ValueSeparators = new List<string>
                                                               {
                                                                   "|"
                                                               };
            var tokens = migrate::CmdLine.CommandLine.Tokenize();
            migrate::CmdLine.CommandLine.CommandSeparators = oldSep;
            migrate::CmdLine.CommandLine.ValueSeparators = oldValueSep;
            Assert.Equal(10, migrate::CmdLine.CommandLine.Args.Length);
            Assert.Equal(4, migrate::CmdLine.CommandLine.GetSwitches(tokens).Count);
            Assert.Equal(6, migrate::CmdLine.CommandLine.GetParameters(tokens).Count);
            Assert.True(tokens[0].IsParameter());
            Assert.True(tokens[1].IsCommand());
            Assert.True(tokens[2].IsCommand());
            Assert.True(tokens[3].IsCommand());
            Assert.True(tokens[4].IsCommand());
            Assert.True(tokens[5].IsParameter());
            Assert.True(tokens[6].IsParameter());
            Assert.True(tokens[7].IsParameter());
            Assert.True(tokens[8].IsParameter());
            Assert.True(tokens[9].IsParameter());
            for (var i = 0; i < args.Length; i++)
            {
                Assert.Equal(args[i], tokens[i].Token);
            }
        }
[ Fact ] public void CommandLineTokenizesWithAlternateSwitchChars ( ) { var args = new [ ] { " \\ \\ " , " " , " " , " " , " " , " " , " " , " " , " " , " " } ; migrate :: CmdLine . CommandLine . CommandEnvironment = new TestCommandEnvironment ( args ) ; var oldSep = migrate :: CmdLine . CommandLine . CommandSeparators ; var oldValueSep = migrate :: CmdLine . CommandLine . ValueSeparators ; migrate :: CmdLine . CommandLine . CommandSeparators = new List < string > { " " , " " } ; migrate :: CmdLine . CommandLine . ValueSeparators = new List < string > { " " } ; var tokens = migrate :: CmdLine . CommandLine . Tokenize ( ) ; migrate :: CmdLine . CommandLine . CommandSeparators = oldSep ; migrate :: CmdLine . CommandLine . ValueSeparators = oldValueSep ; Assert . Equal ( 10 , migrate :: CmdLine . CommandLine . Args . Length ) ; Assert . Equal ( 4 , migrate :: CmdLine . CommandLine . GetSwitches ( tokens ) . Count ) ; Assert . Equal ( 6 , migrate :: CmdLine . CommandLine . GetParameters ( tokens ) . Count ) ; Assert . True ( tokens [ 0 ] . IsParameter ( ) ) ; Assert . True ( tokens [ 1 ] . IsCommand ( ) ) ; Assert . True ( tokens [ 2 ] . IsCommand ( ) ) ; Assert . True ( tokens [ 3 ] . IsCommand ( ) ) ; Assert . True ( tokens [ 4 ] . IsCommand ( ) ) ; Assert . True ( tokens [ 5 ] . IsParameter ( ) ) ; Assert . True ( tokens [ 6 ] . IsParameter ( ) ) ; Assert . True ( tokens [ 7 ] . IsParameter ( ) ) ; Assert . True ( tokens [ 8 ] . IsParameter ( ) ) ; Assert . True ( tokens [ 9 ] . IsParameter ( ) ) ; for ( var i = 0 ; i < args . Length ; i ++ ) { Assert . Equal ( args [ i ] , tokens [ i ] . Token ) ; } }
Verifies that you can use alternate seperators
Verifies that you can use alternate seperators
// Save the seperators since they are static members // Restore the seperators