PageRenderTime 32ms CodeModel.GetById 18ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB.Tests/Lexer/CustomLexerTests.cs

http://github.com/icsharpcode/ILSpy
C# | 118 lines | 104 code | 12 blank | 2 comment | 0 complexity | 25def88c1a79c76f8032fe2559dba629 MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
  3
  4using System;
  5using System.IO;
  6using NUnit.Framework;
  7using ICSharpCode.NRefactory.VB.Parser;
  8
  9namespace ICSharpCode.NRefactory.VB.Tests.Lexer
 10{
 11	[TestFixture]
 12	public class CustomLexerTests
 13	{
 14		VBLexer GenerateLexer(StringReader sr)
 15		{
 16			return new VBLexer(sr);
 17		}
 18		
 19		[Test]
 20		public void TestSingleEOLForMulitpleLines()
 21		{
 22			VBLexer lexer = GenerateLexer(new StringReader("Stop\n\n\nEnd"));
 23			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop));
 24			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 25			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End));
 26			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 27			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 28		}
 29		
 30		[Test]
 31		public void TestSingleEOLForMulitpleLinesWithContinuation()
 32		{
 33			VBLexer lexer = GenerateLexer(new StringReader("Stop\n _\n\nEnd"));
 34			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop));
 35			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 36			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End));
 37			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 38			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 39		}
 40		
 41		[Test]
 42		public void EscapedIdentifier()
 43		{
 44			VBLexer lexer = GenerateLexer(new StringReader("[Stop]"));
 45			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 46			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 47			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 48		}
 49		
 50		[Test]
 51		public void IdentifierWithTypeCharacter()
 52		{
 53			VBLexer lexer = GenerateLexer(new StringReader("Stop$"));
 54			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 55			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 56			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 57		}
 58		
 59		[Test]
 60		public void ExclamationMarkIsTypeCharacter()
 61		{
 62			VBLexer lexer = GenerateLexer(new StringReader("a!=b"));
 63			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 64			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Assign));
 65			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 66			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 67			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 68		}
 69		
 70		[Test]
 71		public void ExclamationMarkIsTypeCharacter2()
 72		{
 73			VBLexer lexer = GenerateLexer(new StringReader("a! b"));
 74			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 75			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 76			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 77			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 78		}
 79		
 80		[Test]
 81		public void ExclamationMarkIsIdentifier()
 82		{
 83			VBLexer lexer = GenerateLexer(new StringReader("a!b"));
 84			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 85			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark));
 86			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 87			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 88			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
 89		}
 90		
 91		[Test]
 92		public void ExclamationMarkIsIdentifier2()
 93		{
 94			VBLexer lexer = GenerateLexer(new StringReader("a![b]"));
 95			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 96			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark));
 97			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
 98			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
 99			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
100		}
101		
102		[Test]
103		public void RemCommentTest()
104		{
105			VBLexer lexer = GenerateLexer(new StringReader("a rem b"));
106			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier));
107			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL));
108			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
109		}
110		
111		[Test]
112		public void RemCommentTest2()
113		{
114			VBLexer lexer = GenerateLexer(new StringReader("REM c"));
115			Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF));
116		}
117	}
118}