Example #1
0
        public void TwoLines_TwoPeeksReturnsTheSame()
        {
            var line   = "theLine";
            var reader = new PeekableStreamReader(AsStream(line));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(line, reader.PeekLine());
                Assert.AreEqual(line, reader.PeekLine());
            });
        }
        public static string ReadUntilBoundaryOrThrow(PeekableStreamReader reader, string boundary)
        {
            //Вычитываем все пустые строки перед контентом
            if (!reader.ReadUntilFirstNonEmptyLine())
            {
                throw new InvalidDataException("Close boundary or content not found");
            }

            //Теперь читаем строки пока не получим боундари
            var  stringBuilder = new StringBuilder();
            bool hasOneLine    = false;

            while (true)
            {
                if (reader.EndOfStream)
                {
                    throw new InvalidDataException("Close boundary not found");
                }

                if (reader.PeekLine().StartsWith(BatchSerializeHelper.GetOpenBoundaryString(boundary)))
                {
                    return(stringBuilder.ToString());
                }
                else
                {
                    stringBuilder.Append((hasOneLine ? "\r\n" : String.Empty) + reader.ReadLine());
                    hasOneLine = true;
                }
            }
        }
Example #3
0
        public void TwoLines_PeeksAndReadsScenario()
        {
            var line1  = "theLine";
            var line2  = "theLine2";
            var reader = new PeekableStreamReader(AsStream(line1 + "\r\n" + line2));

            Assert.AreEqual(line1, reader.PeekLine());
            Assert.AreEqual(line1, reader.PeekLine());
            Assert.AreEqual(line1, reader.ReadLine());

            Assert.AreEqual(line2, reader.PeekLine());
            Assert.AreEqual(line2, reader.PeekLine());
            Assert.AreEqual(line2, reader.ReadLine());

            Assert.IsTrue(reader.EndOfStream);
        }
Example #4
0
        public void ReaderContainsSingleLine_PeekLine_EndOfStreamEqualsFalse()
        {
            var reader = new PeekableStreamReader(AsStream("theLine"));

            reader.PeekLine();
            Assert.IsFalse(reader.EndOfStream);
        }
Example #5
0
        private void ParseAttributes(PeekableStreamReader fs)
        {
            var line = fs.PeekLine();

            while (line != null && line.StartsWith("["))
            {
                if (_config.ParseTypeAttributes)
                {
                    Attributes.Add(new DumpAttribute(fs));
                }
                else
                {
                    fs.ReadLine();
                }
                line = fs.PeekLine();
            }
        }
Example #6
0
        internal DumpProperty(TypeRef declaring, PeekableStreamReader fs)
        {
            DeclaringType = declaring;
            var line = fs.PeekLine()?.Trim();

            while (line != null && line.StartsWith("["))
            {
                Attributes.Add(new DumpAttribute(fs));
                line = fs.PeekLine()?.Trim();
            }
            line = fs.ReadLine()?.Trim() ?? "";
            var split = line.Split(' ');

            if (split.Length < 5)
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Property cannot be created from: \"{line.Trim()}\"");
            }

            // Start at the end (but before the }), count back until we hit a { (or we have gone 3 steps)
            // Keep track of how far back we count
            int i;

            for (i = 0; i < 3; i++)
            {
                var val = split[split.Length - 2 - i];
                if (val == "{")
                {
                    break;
                }
                else if (val == "get;")
                {
                    GetMethod = true;
                }
                else if (val == "set;")
                {
                    SetMethod = true;
                }
            }
            Name = split[split.Length - 3 - i];
            Type = new DumpTypeRef(DumpTypeRef.FromMultiple(split, split.Length - 4 - i, out int adjust, -1, " "));
            for (int j = 0; j < adjust; j++)
            {
                Specifiers.Add(new DumpSpecifier(split[j]));
            }
        }
Example #7
0
        internal DumpField(TypeRef declaring, PeekableStreamReader fs)
        {
            DeclaringType = declaring;
            var line = fs.PeekLine()?.Trim();

            while (line != null && line.StartsWith("["))
            {
                Attributes.Add(new DumpAttribute(fs));
                line = fs.PeekLine()?.Trim();
            }
            line = fs.ReadLine()?.Trim() ?? "";
            var split = line.Split(' ');

            // Offset is at the end
            if (split.Length < 4)
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Field cannot be created from: \"{line.Trim()}\"");
            }

            Offset = Convert.ToInt32(split[^ 1], 16);
Example #8
0
        public void ReaderContainsSingleLine_PeekLineAndReadLineReturnsTheSame()
        {
            var line   = "theLine";
            var reader = new PeekableStreamReader(AsStream(line));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(line, reader.PeekLine());
                Assert.AreEqual(line, reader.ReadLine());
            });
        }
Example #9
0
        internal DumpMethod(TypeRef declaring, PeekableStreamReader fs)
        {
            DeclaringType = declaring;
            // Read Attributes
            var line = fs.PeekLine()?.Trim();

            while (line != null && line.StartsWith("["))
            {
                Attributes.Add(new DumpAttribute(fs));
                line = fs.PeekLine()?.Trim();
            }
            // Read prefix comment
            line = fs.ReadLine()?.Trim() ?? "";
            var split = line.Split(' ');

            if (split.Length < 5)
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Method cannot be created from: \"{line.Trim()}\"");
            }

            int start = split.Length - 1;

            if (split[^ 2] == "Slot:")
Example #10
0
        public void ReaderIsEmpty_ReadLineThrows()
        {
            var reader = new PeekableStreamReader(AsStream(""));

            Assert.IsNull(reader.PeekLine());
        }
Example #11
0
        public void ReaderIsEmpty_PeekLineReturnsNull()
        {
            var reader = new PeekableStreamReader(AsStream(""));

            Assert.IsNull(reader.PeekLine());
        }