Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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));
        }