Пример #1
0
        public static Scanner PrepareScanner(string s)
        {
            var reader  = new StringsReader(s);
            var scanner = new Scanner(reader);

            return(scanner);
        }
Пример #2
0
        public void StringWithContent_stringReaderReadsFirstSignOnInitialization_CurrentSignCorrect()
        {
            // prepare
            var str = "example 123";

            // act
            var stringReader = new StringsReader(str);

            // validate
            Assert.Equal('e', stringReader.CurrentSign);
        }
Пример #3
0
        public void EmptyFile_stringReaderReadsFirstSignOnInitialization_CurrentSignMinusOne()
        {
            // prepare
            var str = "";

            // act
            var stringReader = new StringsReader(str);

            // validate
            Assert.Equal(-1, stringReader.CurrentSign);
        }
Пример #4
0
        public void FileWithContent_stringReaderReadsTwoSigns_CurrentSignCorrect()
        {
            // prepare
            var str = "example 123";

            // act
            var stringReader = new StringsReader(str);

            stringReader.Read();
            stringReader.Read();

            // validate
            Assert.Equal('a', stringReader.CurrentSign);
        }
Пример #5
0
        public void StreamWithStringWithEscapedQuoteMark_ReadNextTokenTillEof_TokensAreCorrect()
        {
            // prepare
            var reader  = new StringsReader("\"st\\\"ring\"");
            var scanner = new Scanner(reader);

            // act
            scanner.ReadNextToken();
            var firstToken  = scanner.Token;
            var isString    = scanner.TryReadString();
            var secondToken = scanner.Token;

            scanner.ReadNextToken();
            var thirdToken = scanner.Token;

            // validate
            Assert.Equal(TokenType.QuotationMark, firstToken.Type);
            Assert.Equal(TokenType.Text, secondToken.Type);
            Assert.Equal("st\"ring", secondToken.Value);
            Assert.Equal(TokenType.QuotationMark, thirdToken.Type);
        }