Exemple #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));
        }
Exemple #2
0
        public void ShouldHandleTextOnTheFirstLine()
        {
            var source = @"onlyLine";

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

            var expectedResult = SplitUsingNewline(@"onlyLine");

            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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));
        }
Exemple #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);
        }
Exemple #7
0
        public void ShouldProcessTwoLinesWithNoIndent()
        {
            var source = @"
line1
line2";
            var result = PreLexer.Process(SplitUsingNewline(source));

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

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #10
0
        public void ShouldProcessBraceInString()
        {
            var source = @"
line1 ""{ \"" {""
line2";

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

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

            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #14
0
        public void ShouldNotProcessIndentInBraces()
        {
            var source = @"
line1 { 
    line2 }";

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

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

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

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

            var expectedResult = SplitUsingNewline(@"
line1;
line2

");

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #19
0
        public void ShouldProcessEmptyFile()
        {
            var result = PreLexer.Process(string.Empty);

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

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