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

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

            var expectedResult = SplitUsingNewline(@"onlyLine");

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

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

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

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

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

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

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

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

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

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

            var expectedResult = SplitUsingNewline(@"
line1;
line2

");

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

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

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