示例#1
0
        public void Unclosed_String_Literal()
        {
            string             code;
            SourceCodeIterator iterator;
            StringLexerState   state = new StringLexerState();

            code     = " \"-just string ";
            iterator = new SourceCodeIterator(code);
            iterator.MoveToContent();
            Assert.Throws <SyntaxErrorException>(() => state.ReadNextLexem(iterator));
        }
示例#2
0
        public void Incorrect_NewLine_InString()
        {
            string             code;
            SourceCodeIterator iterator;
            StringLexerState   state = new StringLexerState();

            code     = @" ""-just 
            d|string """;
            iterator = new SourceCodeIterator(code);
            iterator.MoveToContent();
            Assert.Throws <SyntaxErrorException>(() => state.ReadNextLexem(iterator));
        }
示例#3
0
        public void StringLiteral_LexerState_WorksFine()
        {
            string             code;
            SourceCodeIterator iterator;
            Lexem            lex;
            StringLexerState state = new StringLexerState();

            code     = " \"-just string \"";
            iterator = new SourceCodeIterator(code);
            iterator.MoveToContent();
            lex = state.ReadNextLexem(iterator);
            Assert.True(lex.Type == LexemType.StringLiteral);
            Assert.Equal("-just string ", lex.Content);

            code     = @" ""-just
            |string """;
            iterator = new SourceCodeIterator(code);
            iterator.MoveToContent();
            lex = state.ReadNextLexem(iterator);
            Assert.True(lex.Type == LexemType.StringLiteral);
            Assert.Equal("-just\nstring ", lex.Content);

            code     = @" ""-just "" ""string"" ""123""";
            iterator = new SourceCodeIterator(code);
            iterator.MoveToContent();
            lex = state.ReadNextLexem(iterator);
            Assert.True(lex.Type == LexemType.StringLiteral);
            Assert.Equal("-just \nstring\n123", lex.Content);

            code     = @"""first line
            |second line
            // comment
            |third line""";
            iterator = new SourceCodeIterator(code);
            iterator.MoveToContent();
            lex = state.ReadNextLexem(iterator);
            Assert.True(lex.Type == LexemType.StringLiteral);
            Assert.Equal("first line\nsecond line\nthird line", lex.Content);
        }