public void ParseTest() { MehtodParamterConfigurationDefinitionGenerator gen = new MehtodParamterConfigurationDefinitionGenerator(); { ConfigurationInfo configuartionInfo = gen.Generate(this.GetType().GetMethod("TestEntryPoint", new Type[] { typeof(string), typeof(string) })); CommandLineParser target = new CommandLineParser(configuartionInfo); //TestParse(target, "/ test1 / test2", new object[] { "test1", "/123" }); TestParse(target, "/source test1 /dest \"/123\"", new object[] { "test1", "/123" }); TestParse(target, "", new object[] { null, null }); TestParse(target, "/source source /dest dest", new object[] { "source", "dest" }); TestParse(target, "/source \"source\" /dest dest", new object[] { "source", "dest" }); TestParse(target, "/source source /dest \"dest\"", new object[] { "source", "dest" }); TestParse(target, "/source \"source\" /dest \"dest\"", new object[] { "source", "dest" }); TestParse(target, "/source \"sou rce\" /dest \"dest\"", new object[] { "sou rce", "dest" }); TestParse(target, "/source \"so \"\"urce\" /dest dest", new object[] { "so \"urce", "dest" }); TestParse(target, "/source \"s\"\"\"\"ource\" /dest dest", new object[] { "s\"\"ource", "dest" }); TestParse(target, "/source source dest", new object[] { "source", "dest" }); TestParse(target, "/dest dest source", new object[] { "source", "dest" }); TestParse(target, "/source:source /dest dest", new object[] { "source", "dest" }); TestParse(target, "/source : source /dest dest", new object[] { "source", "dest" }); TestParse(target, "\\\\rubicon\\test \"abc\"", new object[] { "\\\\rubicon\\test", "abc"}); } { ConfigurationInfo configuartionInfo = gen.Generate(this.GetType().GetMethod("TestEntryPoint", new Type[] { typeof(string), typeof(bool), typeof(string) })); CommandLineParser target = new CommandLineParser(configuartionInfo); TestParse(target, "", new object[] { "sourceTest", true, null }); TestParse(target, "/source test1", new object[] { "test1", true, null }); TestParse(target, "/source test1 /destAlias \"/123\"", new object[] { "test1", true, "/123" }); } }
void TestParse(CommandLineParser target, string source, object[] expected) { object[] actual; actual = target.Parse(source); Assert.IsTrue(expected.SequenceEqual(actual), "expect:{0}, actual={1}", string.Join(",", expected), string.Join(",", actual)); }