コード例 #1
0
        private static IInput GetInputFromString(string source)
        {
            var result = PreLexer.Process(source.Split(new[] { Environment.NewLine }, StringSplitOptions.None));
            var output = result.Aggregate((x, y) => x + Environment.NewLine + y);

            return(new Input(output));
        }
コード例 #2
0
        public void ShouldHandleTextOnTheFirstLine()
        {
            var source = @"onlyLine";

            var result = PreLexer.Process(SplitUsingNewline(source)).ToArray();

            var expectedResult = SplitUsingNewline(@"onlyLine");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #3
0
        public void ShouldFailOnUnterminatedString()
        {
            var source = @"
line1 ""i'm unterminated";

            var result    = PreLexer.Process(SplitUsingNewline(source));
            var exception = Assert.Throws <ParsingException>(() => result.ToArray());

            Assert.AreEqual(ParsingError.SyntaxError, exception.Error);
        }
コード例 #4
0
        public void ShouldFailOnSingleLineMultilineComment()
        {
            var source = @"
first line
    /*something*/ second line";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var exception = Assert.Throws <ParsingException>(() => result.ToArray());

            Assert.AreEqual(ParsingError.SyntaxError, exception.Error);
        }
コード例 #5
0
        private static IInput GetInputFromString(string source)
        {
            var result = PreLexer.Process(source);

            if (!result.Any())
            {
                return(new Input(string.Empty));
            }
            var output = result.Aggregate((x, y) => x + Environment.NewLine + y);

            return(new Input(output));
        }
コード例 #6
0
        public void ShouldFailIfTheMultilineCommentFinishesBeforeEndOfLine()
        {
            var source = @"
line1 /* here we begin
    here it goes
here the comment ends*/ x: 5
line2";

            var result    = PreLexer.Process(SplitUsingNewline(source));
            var exception = Assert.Throws <ParsingException>(() => result.ToArray());

            Assert.AreEqual(ParsingError.SyntaxError, exception.Error);
        }
コード例 #7
0
        public void ShouldProcessTwoLinesWithNoIndent()
        {
            var source = @"
line1
line2";
            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1;
line2");

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
コード例 #8
0
        public void ShouldProcessDoubleDedentAtTheEndOfFile()
        {
            var source = @"first line
second line
    first indented";
            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"first line;
second line{
    first indented}");

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
コード例 #9
0
        public void ShouldHandleInitialIndent()
        {
            var source = @"
    first line
    second line
        first indented
        second indented
    third line";
            var result = PreLexer.Process(SplitUsingNewline(source));

            var exception = Assert.Throws <ParsingException>(() => result.ToArray());

            Assert.AreEqual(ParsingError.WrongIndent, exception.Error);
        }
コード例 #10
0
        public void ShouldProcessBraceInString()
        {
            var source = @"
line1 ""{ \"" {""
line2";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1 ""{ \"" {"";
line2");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #11
0
        public void ShouldHandleMultilineCommentsInOneLine()
        {
            var source = @"
line1 used as a ruler1234            123456789                1234
line 2/* first comment*/ ""string with /*"" /* second comment */ something";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1 used as a ruler1234            123456789                1234;
line 2                   ""string with /*""                      something");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #12
0
        public void ShouldHandleLineCommentsAndStrings()
        {
            var source = @"
line1 ""something with //"" ""another // pseudo comment"" { // and here goes real comment
    line2 }";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1 ""something with //"" ""another // pseudo comment"" { 
    line2 }");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #13
0
        public void ShouldHandleUncorrectLineComments()
        {
            var source = @"
line1 {// something
    line2 }";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1 {// something
    line2 }");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #14
0
        public void ShouldNotProcessIndentInBraces()
        {
            var source = @"
line1 { 
    line2 }";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1 { 
    line2 }");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #15
0
        public void ShouldHandleEmptyLinesAtTheEndOfSource()
        {
            var source = @"
line1
line2

";
            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1;
line2

");

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
コード例 #16
0
        public void ShouldProcessSimpleFile()
        {
            var source = @"first line
second line
    first indented
    second indented
third line";
            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"first line;
second line{
    first indented;
    second indented};
third line");

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
コード例 #17
0
        public void ShouldHandleMultilineCommentsWithinBraces()
        {
            var source = @"
line1 { /* here we begin
    here it goes
here the comment ends*/ x: 5 }
line2";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1 { 

                        x: 5 };
line2");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #18
0
        public void ShouldHandleMultilineComments()
        {
            var source = @"
line1/* here we begin
    here it goes
more
more
    here we finish*/
line2";

            var result = PreLexer.Process(SplitUsingNewline(source));

            var expectedResult = SplitUsingNewline(@"
line1;




line2");

            CollectionAssert.AreEqual(expectedResult, result);
        }
コード例 #19
0
ファイル: PreLexerTests.cs プロジェクト: basilfx/renode
        public void ShouldProcessEmptyFile()
        {
            var result = PreLexer.Process(string.Empty);

            CollectionAssert.AreEquivalent(string.Empty, result.First());
        }
コード例 #20
0
        public void ShouldProcessEmptyFile()
        {
            var result = PreLexer.Process(new string[0]);

            CollectionAssert.AreEquivalent(new string[0], result);
        }