public void ScanSingleLineFalseTest() { var lexer = Lexer.CreateState("/X"); Assert.Throws <InvalidOperationException>(() => CommentScanner.ScanSingleLine(lexer, ref this.token)); }
public void MultiLineErrorPositionTest() { var lexer = Lexer.CreateState("/*/"); _ = CommentScanner.ScanMultiLine(lexer, ref this.token); Assert.Equal(3, lexer.Src.Index); }
public void ScanMultiLineTrueTest() { var lexer = Lexer.CreateState("/**/"); bool result = CommentScanner.ScanMultiLine(lexer, ref this.token); Assert.True(result); }
public void MultiLineNewLinePositionTest() { var lexer = Lexer.CreateState("/*" + Environment.NewLine + "*/"); _ = CommentScanner.ScanMultiLine(lexer, ref this.token); Assert.Equal(5, lexer.Src.Index); }
public void ScanMultiLineFalseTest() { foreach (string text in new[] { "/*/", "/**", "/*" }) { var lexer = Lexer.CreateState(text); bool result = CommentScanner.ScanMultiLine(lexer, ref this.token); Assert.False(result); } }
public void ScanMultiLineNewLineTest() { string comment = "/*" + Environment.NewLine + "*/"; var lexer = Lexer.CreateState(comment); bool result = CommentScanner.ScanMultiLine(lexer, ref this.token); Assert.True(result); Assert.Equal(comment, this.token.Value); }
public void TestNegativeBlockComments(string content) { var input = new TextInputRange { File = new TextFile { Content = content, Filename = "" } }; var exception = Assert.Throws <Exception>(() => CommentScanner.Scan(input)); Assert.True(exception.Message.Equals(value: "Line Comment not Escaped.")); }
public void TestNegativeLineComments(string content) { var input = new TextInputRange { File = new TextFile { Content = content, Filename = "" } }; var output = CommentScanner.Scan(input); Assert.IsFalse(output); Assert.AreEqual(content[index: 0], input.EndChar); }
public void TestPositiveLineComments(string content) { var input = new TextInputRange { File = new TextFile { Content = content, Filename = "" } }; var output = CommentScanner.Scan(input); Assert.IsTrue(output); Assert.IsFalse(input.IsEndValid); }
public void TestPositiveBlockComments(string content, int line) { var input = new TextInputRange { File = new TextFile { Content = content, Filename = "" } }; var output = CommentScanner.Scan(input); Assert.IsTrue(output); Assert.IsFalse(input.IsEndValid); Assert.AreEqual(line, input.End.Line); }
public void TestNegativeLineEndLineComments(string content) { var input = new TextInputRange { File = new TextFile { Content = content, Filename = "" } }; var output = CommentScanner.Scan(input); Assert.IsTrue(output); Assert.IsTrue(input.IsEndValid); Assert.AreEqual(expected: '\n', actual: input.EndChar); }
/// <summary> /// Used to analyse the current textwindow and retrieve/skip any /// trivia which includes things such as whitespace, newlines, /// comments and multi-line comments /// Returns them as a flat list /// </summary> /// <param name="bIsTrailing"></param> /// <returns></returns> private List <SyntaxTrivia> LexSyntaxTrivia(Boolean bIsTrailing = false) { // Initialise variables List <SyntaxTrivia> aoReturnList = new List <SyntaxTrivia>(); Boolean bNewLineCharFound = false; // Just keep lexing until we are told to stop // or we run out of characters to process while (TextWindow.HasCharactersLeftToProcess()) { // Check the next character and switch based on that char xcNextChar = TextWindow.PeekCharacter(); if (SyntaxUtilities.IsWhiteSpace(xcNextChar)) { // Try and scan the item SyntaxTrivia oNewItem = WhiteSpaceScanner.Scan(TextWindow); // Insert it aoReturnList.Add(oNewItem); } else if (SyntaxUtilities.IsNewLineCharacter(xcNextChar)) { bNewLineCharFound = true; // Do not steal trailing comments if a newline has been found if (bIsTrailing) { break; } // Try and scan the item SyntaxTrivia oNewItem = NewLineScanner.Scan(TextWindow); // Insert it aoReturnList.Add(oNewItem); } // Handle Comments else if (xcNextChar == '-') { // Do not touch a single -, only play with -- if (TextWindow.PeekCharacter(1) != '-') { return(aoReturnList); } // Only pick up inlines if they are directly trailing an item // Do not steal another nodes leading comments if (bNewLineCharFound && bIsTrailing) { break; } SyntaxTrivia oComment = CommentScanner.ScanSingleLineComment(TextWindow); aoReturnList.Add(oComment); } else if (xcNextChar == '/') { // Do not touch a single /, only play with /* if (TextWindow.PeekCharacter(1) != '*') { return(aoReturnList); } // Do not steal trailing comments if a newline has been found if (bNewLineCharFound && bIsTrailing) { break; } SyntaxTrivia oComment = CommentScanner.ScanMultiLineComment(TextWindow); aoReturnList.Add(oComment); } else { break; } } return(aoReturnList); }
public void ScanSingleLineNullTest() { Assert.Throws <ArgumentNullException>(() => CommentScanner.ScanSingleLine(null, ref this.token)); }