Пример #1
0
        public void TestSmartSplit()
        {
            var cases = new[] {
                new SmartSplitCase {
                    CommandString = " qwert ",
                    Args          = new[] { "qwert" }
                },
                new SmartSplitCase {
                    CommandString = "qwe qwe",
                    Args          = new[] { "qwe", "qwe" }
                },
                new SmartSplitCase {
                    CommandString = "primitive",
                    Args          = new [] { "primitive" }
                },
                new SmartSplitCase {
                    CommandString = "romdomdomCmd  dom2 Dom \"Aleksandr \\\" \\\" pushkin\\\"\" \"lalala\" rom 14 ",
                    Args          = new[] {
                        "romdomdomCmd", "dom2", "Dom", "\"Aleksandr \" \" pushkin\"\"", "\"lalala\"", "rom", "14"
                    }
                },
            };

            foreach (var test in cases)
            {
                var splitted = ParseTools.SmartSplit(test.CommandString);
                if (splitted.Count != test.Args.Length)
                {
                    Assert.Fail("Parsed and expected lengths are not equal (" + splitted.Count + " vs " + test.Args.Length + ")");
                }
                for (int i = 0; i < splitted.Count; i++)
                {
                    Assert.AreEqual(splitted[i], test.Args[i]);
                }
            }
        }