public void HandleCombiningCharacters() { var str = "cre\u0300me bru\u0302le\u0301e 000"; var reader = new BufferedStringReader(_createStream(str), null); Assert.AreEqual("cre\u0300me ", reader.Read(6)); Predicate <string> func = (ch) => char.IsLetter(ch, 0); Assert.AreEqual("bru\u0302le\u0301e", reader.ReadWhile(func)); Assert.AreEqual(" 000", reader.Read(10)); }
public void ReadWhile() { Predicate <string> func = (ch) => char.IsLetter(ch, 0); var str = "Foo_Bar"; var reader = new BufferedStringReader(_createStream(str), null); Assert.AreEqual("Foo", reader.ReadWhile(func)); Assert.AreEqual("", reader.ReadWhile(func)); Assert.AreEqual("", reader.ReadWhile(func)); Assert.AreEqual("_", reader.Read(1)); Assert.AreEqual("Bar", reader.ReadWhile(func)); Assert.AreEqual("", reader.ReadWhile(func)); }
public void HandlesSurrogates() { var str = "😀😈_😓ðŸ˜"; Assert.AreEqual(9, str.Length); // Each should be a surrogate pair var reader = new BufferedStringReader(_createStream(str), null); Assert.AreEqual("😀", reader.Peek(1)); Assert.AreEqual("😀😈", reader.Peek(2)); Assert.AreEqual("😀", reader.Read(1)); Assert.AreEqual("😈_😓ðŸ˜", reader.Peek(10)); Assert.AreEqual("😈_", reader.ReadUntil("_")); Assert.AreEqual("😓ðŸ˜", reader.ReadUntil("😱")); str = "😀😀😀😀😀😀_123"; Predicate <string> func = (ch) => ch == "😀"; reader = new BufferedStringReader(_createStream(str), null); Assert.AreEqual("😀😀😀😀😀😀", reader.ReadWhile(func)); Assert.AreEqual("_123", reader.Read(10)); }
public void TracksPosition() { var str = "Foo\nBar\nBaz\n\n123\n000"; var reader = new BufferedStringReader(_createStream(str), null); Assert.AreEqual("Fo", reader.Read(2)); Assert.AreEqual(3, reader.Column); Assert.AreEqual(1, reader.Line); Assert.AreEqual("o\nB", reader.Read(3)); Assert.AreEqual(2, reader.Column); Assert.AreEqual(2, reader.Line); Assert.AreEqual("ar", reader.Read(2)); Assert.AreEqual(4, reader.Column); Assert.AreEqual(2, reader.Line); Assert.AreEqual("\n", reader.Read(1)); Assert.AreEqual(1, reader.Column); Assert.AreEqual(3, reader.Line); Assert.AreEqual("Baz\n\n123\n0", reader.Read(10)); Assert.AreEqual(2, reader.Column); Assert.AreEqual(6, reader.Line); Assert.AreEqual("00", reader.Read(10)); Assert.AreEqual("", reader.Read(10)); }