Exemplo n.º 1
0
        public void GetLocation__ReturnsCorrectLocation()
        {
            var reader        = new StringCodeReader("stri\nng\r\nanother\r\nstring");
            var expectedLines = new[]
            {
                /*s :*/ "B 00 L 1 C 1",
                /*t :*/ "B 01 L 1 C 2",
                /*r :*/ "B 02 L 1 C 3",
                /*i :*/ "B 03 L 1 C 4",
                /*\n:*/ "B 04 L 1 C 5",
                /*n :*/ "B 05 L 2 C 1",
                /*g :*/ "B 06 L 2 C 2",
                /*\r:*/ "B 07 L 2 C 3",
                /*\n:*/ "B 08 L 2 C 4",
                /*a :*/ "B 09 L 3 C 1",
                /*n :*/ "B 10 L 3 C 2",
                /*o :*/ "B 11 L 3 C 3",
                /*t :*/ "B 12 L 3 C 4",
                /*h :*/ "B 13 L 3 C 5",
                /*e :*/ "B 14 L 3 C 6",
                /*r :*/ "B 15 L 3 C 7",
                /*\r:*/ "B 16 L 3 C 8",
                /*\n:*/ "B 17 L 3 C 9",
                /*s :*/ "B 18 L 4 C 1",
                /*t :*/ "B 19 L 4 C 2",
                /*r :*/ "B 20 L 4 C 3",
                /*i :*/ "B 21 L 4 C 4",
                /*n :*/ "B 22 L 4 C 5",
                /*g :*/ "B 23 L 4 C 6",
            };
            var i = 0;

            while (reader.Position != reader.Length)
            {
                SourceLocation l = reader.GetLocation();
                reader.Advance(1);
                Assert.AreEqual(expectedLines[i++], $"B {l.Byte:00} L {l.Line} C {l.Column}");
            }
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => reader.Advance(1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => reader.Advance(-1));
        }