public void ParseStringSimpleTest() { var sb = new StringBuilder(" hello "); var en = CsvImporter.ParseString(sb, ",", true).GetEnumerator(); Assert.AreEqual(true, en.MoveNext(), "First Token"); Assert.AreEqual("hello", en.Current, "Token Value"); Assert.AreEqual(false, en.MoveNext(), "No more Tokens"); sb = new StringBuilder(" Bob, \"Billy Bob\""); en = CsvImporter.ParseString(sb, ",", true).GetEnumerator(); // remove quotes Assert.AreEqual(true, en.MoveNext(), "First Token"); Assert.AreEqual("Bob", en.Current, "Token 1 Value"); Assert.AreEqual(true, en.MoveNext(), "Second Token"); Assert.AreEqual("Billy Bob", en.Current, "Token 2 Value"); Assert.AreEqual(false, en.MoveNext(), "No more Tokens"); en = CsvImporter.ParseString(sb, ",", false).GetEnumerator(); // don't remove quotes Assert.AreEqual(true, en.MoveNext(), "First Token"); Assert.AreEqual("Bob", en.Current, "Token 1 Value"); Assert.AreEqual(true, en.MoveNext(), "Second Token"); Assert.AreEqual("\"Billy Bob\"", en.Current, "Token 2 Value"); Assert.AreEqual(false, en.MoveNext(), "No more Tokens"); Assert.AreEqual(false, en.MoveNext(), "No more Tokens #2"); }
public void InterestingStringParsingTest2() { // Test "quote nested" separator var sb = new StringBuilder("\" First, Name\", Last \t, Name, "); var list = CsvImporter.ParseString(sb, ",", true).ToList(); Assert.AreEqual(4, list.Count, "Count"); Assert.AreEqual(" First, Name", list[0], "0"); Assert.AreEqual("Last", list[1], "1"); Assert.AreEqual("Name", list[2], "2"); Assert.AreEqual("", list[3], "3"); }
public void InterestingStringParsingTest() { // Test "space" separator var sb = new StringBuilder(" hello to all "); var list = CsvImporter.ParseString(sb, " ", true).ToList(); Assert.AreEqual("", list[0], "0"); Assert.AreEqual("", list[1], "1"); Assert.AreEqual("hello", list[2], "2"); Assert.AreEqual("to", list[3], "3"); Assert.AreEqual("", list[4], "4"); Assert.AreEqual("all", list[5], "5"); Assert.AreEqual("", list[6], "6"); Assert.AreEqual("", list[7], "7"); Assert.AreEqual(8, list.Count, "Count 1"); }
public void ParseStringExceptionTest() { try { CsvImporter.ParseString(null, ",", false).ToList(); } catch (ArgumentNullException) { try { CsvImporter.ParseString(new StringBuilder(""), null, false).ToList(); } catch (ArgumentNullException) { return; } } Assert.Fail("Expected exception when passing in null"); }