namespace GParseTests; public class QuoteAwareParserTests { [Fact] public void CanConstruct() { _ = new QuoteAwareParser("|", "{", "}"); } [Theory] [InlineData("", new string[] { "" })] [InlineData("1", new string[] { "1" })] [InlineData("1,2", new string[] { "1", "2" })] [InlineData(",", new string[] { "", "" })] [InlineData(",,", new string[] { "", "", "" })] [InlineData("1,", new string[] { "1", "" })] [InlineData(",1", new string[] { "", "1" })] [InlineData("{{a,b,c}}", new string[] { "{{a,b,c}}" })] [InlineData("{{a,b,c}},{{1,2,3}}", new string[] { "{{a,b,c}}","{{1,2,3}}" })] [InlineData("{{a,b,c}},", new string[] { "{{a,b,c}}", "" })] [InlineData(",{{a,b,c}},", new string[] { "", "{{a,b,c}}", "" })] [InlineData(",{{a,b,c}}", new string[] { "", "{{a,b,c}}" })] [InlineData("a,b,c", new string[] { "a", "b", "c" })] public void VarietyTests(string inputText, IEnumerable expected) { const string delimiter = ","; const string openQuote = "{{"; const string closeQuote = "}}"; var parser = new QuoteAwareParser(delimiter, openQuote, closeQuote); IEnumerable actual = parser.Parse(inputText); actual.ShouldBe(expected); } [Fact] public void FailsOnMismatchedQuotes() { const string delimiter = ","; const string openQuote = "{{"; const string closeQuote = "}}"; var parser = new QuoteAwareParser(delimiter, openQuote, closeQuote); const string inputText = "{{this is an unterminated quote"; Should.Throw( () => parser.Parse(inputText).ToList(), typeof(ParseException)); } }