PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB.Tests/Parser/GlobalScope/ImportsStatementTests.cs

http://github.com/icsharpcode/ILSpy
C# | 168 lines | 46 code | 11 blank | 111 comment | 0 complexity | ff014faa88e9af98332f6dac65478e29 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 ICSharpCode.NRefactory.VB.Parser;
  7using ICSharpCode.NRefactory.VB.Ast;
  8using NUnit.Framework;
  9
 10namespace ICSharpCode.NRefactory.VB.Tests.Ast
 11{
 12	[TestFixture]
 13	public class ImportsStatementTests
 14	{
 15		[Test]
 16		public void InvalidImportsStatement()
 17		{
 18			string program = "Imports\n";
 19			ParseUtil.ParseGlobal<ImportsStatement>(program, true);
 20		}
 21		
 22		[Test]
 23		public void InvalidImportsStatement2()
 24		{
 25			string program = "Imports ,\n";
 26			ParseUtil.ParseGlobal<ImportsStatement>(program, true);
 27		}
 28		
 29		[Test]
 30		public void SimpleImportsStatement()
 31		{
 32			string program = "Imports System\n";
 33			
 34			var clause1 = new MemberImportsClause {
 35				Member = new SimpleType("System")
 36			};
 37			
 38			var node = new ImportsStatement();
 39			node.AddChild(clause1, ImportsStatement.ImportsClauseRole);
 40			
 41			ParseUtil.AssertGlobal(program, node);
 42		}
 43		
 44		[Test]
 45		public void QualifiedTypeImportsStatement()
 46		{
 47			string program = "Imports My.Name.Space\n";
 48			
 49			var clause2 = new MemberImportsClause {
 50				Member = new QualifiedType(new QualifiedType(new SimpleType("My"), new Identifier ("Name", AstLocation.Empty)), new Identifier ("Space", AstLocation.Empty))
 51			};
 52			
 53			var node = new ImportsStatement();
 54			node.AddChild(clause2, ImportsStatement.ImportsClauseRole);
 55			
 56			ParseUtil.AssertGlobal(program, node);
 57		}
 58//
 59//		[Test]
 60//		public void VBNetUsingAliasDeclarationTest()
 61//		{
 62//			string program = "Imports TESTME=System\n" +
 63//				"Imports myAlias=My.Name.Space\n" +
 64//				"Imports StringCollection = System.Collections.Generic.List(Of string)\n";
 65//			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
 66//			parser.Parse();
 67//
 68//			Assert.AreEqual("", parser.Errors.ErrorOutput);
 69//			CheckAliases(parser.CompilationUnit);
 70//		}
 71//
 72//		[Test]
 73//		public void VBNetComplexUsingAliasDeclarationTest()
 74//		{
 75//			string program = "Imports NS1, AL=NS2, NS3, AL2=NS4, NS5\n";
 76//			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
 77//			parser.Parse();
 78//
 79//			Assert.AreEqual("", parser.Errors.ErrorOutput);
 80//			// TODO : Extend test ...
 81//		}
 82//
 83//		[Test]
 84//		public void VBNetXmlNamespaceUsingTest()
 85//		{
 86//			string program = "Imports <xmlns=\"http://icsharpcode.net/sharpdevelop/avalonedit\">";
 87//			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
 88//			parser.Parse();
 89//
 90//			Assert.AreEqual("", parser.Errors.ErrorOutput);
 91//			CompilationUnit unit = parser.CompilationUnit;
 92//
 93//			Assert.AreEqual(1, unit.Children.Count);
 94//			Assert.IsTrue(unit.Children[0] is ImportsStatement);
 95//			ImportsStatement ud = (ImportsStatement)unit.Children[0];
 96//			Assert.AreEqual(1, ud.ImportsClauses.Count);
 97//			Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
 98//			Assert.IsTrue(ud.ImportsClauses[0].IsXml);
 99//
100//			Assert.AreEqual("xmlns", ud.ImportsClauses[0].XmlPrefix);
101//			Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
102//		}
103//
104//		[Test]
105//		public void VBNetXmlNamespaceWithPrefixUsingTest()
106//		{
107//			string program = "Imports <xmlns:avalonedit=\"http://icsharpcode.net/sharpdevelop/avalonedit\">";
108//			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
109//			parser.Parse();
110//
111//			Assert.AreEqual("", parser.Errors.ErrorOutput);
112//			CompilationUnit unit = parser.CompilationUnit;
113//
114//			Assert.AreEqual(1, unit.Children.Count);
115//			Assert.IsTrue(unit.Children[0] is ImportsStatement);
116//			ImportsStatement ud = (ImportsStatement)unit.Children[0];
117//			Assert.AreEqual(1, ud.ImportsClauses.Count);
118//			Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
119//			Assert.IsTrue(ud.ImportsClauses[0].IsXml);
120//
121//			Assert.AreEqual("xmlns:avalonedit", ud.ImportsClauses[0].XmlPrefix);
122//			Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
123//		}
124//
125//		[Test]
126//		public void VBNetXmlNamespaceSingleQuotedUsingTest()
127//		{
128//			string program = "Imports <xmlns='http://icsharpcode.net/sharpdevelop/avalonedit'>";
129//			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
130//			parser.Parse();
131//
132//			Assert.AreEqual("", parser.Errors.ErrorOutput);
133//			CompilationUnit unit = parser.CompilationUnit;
134//
135//			Assert.AreEqual(1, unit.Children.Count);
136//			Assert.IsTrue(unit.Children[0] is ImportsStatement);
137//			ImportsStatement ud = (ImportsStatement)unit.Children[0];
138//			Assert.AreEqual(1, ud.ImportsClauses.Count);
139//			Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
140//			Assert.IsTrue(ud.ImportsClauses[0].IsXml);
141//
142//			Assert.AreEqual("xmlns", ud.ImportsClauses[0].XmlPrefix);
143//			Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
144//		}
145//
146//		[Test]
147//		public void VBNetXmlNamespaceSingleQuotedWithPrefixUsingTest()
148//		{
149//			string program = "Imports <xmlns:avalonedit='http://icsharpcode.net/sharpdevelop/avalonedit'>";
150//			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
151//			parser.Parse();
152//
153//			Assert.AreEqual("", parser.Errors.ErrorOutput);
154//			CompilationUnit unit = parser.CompilationUnit;
155//
156//			Assert.AreEqual(1, unit.Children.Count);
157//			Assert.IsTrue(unit.Children[0] is ImportsStatement);
158//			ImportsStatement ud = (ImportsStatement)unit.Children[0];
159//			Assert.AreEqual(1, ud.ImportsClauses.Count);
160//			Assert.IsFalse(ud.ImportsClauses[0].IsAlias);
161//			Assert.IsTrue(ud.ImportsClauses[0].IsXml);
162//
163//			Assert.AreEqual("xmlns:avalonedit", ud.ImportsClauses[0].XmlPrefix);
164//			Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.ImportsClauses[0].Name);
165//		}
166//		#endregion
167	}
168}