mirror of https://github.com/icsharpcode/ILSpy.git
220 changed files with 0 additions and 45631 deletions
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("NRefactory Test")] |
||||
[assembly: AssemblyDescription("Unit tests for the parser and refactoring library for C# and VB.NET")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("ic#code")] |
||||
[assembly: AssemblyProduct("SharpDevelop")] |
||||
[assembly: AssemblyCopyright("2004-2006 AlphaSierraPapa")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("2.0.0.1")] |
||||
|
||||
// The following attributes specify the key for the sign of your assembly. See the
|
||||
// .NET Framework documentation for more information about signing.
|
||||
// This is not required, if you don't want signing let these attributes like they're.
|
||||
[assembly: AssemblyDelaySign(false)] |
||||
[assembly: AssemblyKeyFile("")] |
||||
@ -1,102 +0,0 @@
@@ -1,102 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class StructuralTest |
||||
{ |
||||
// [Test]
|
||||
// public void TestToStringMethods()
|
||||
// {
|
||||
// Type[] allTypes = typeof(INode).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null) {
|
||||
// MethodInfo methodInfo = type.GetMethod("ToString", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
|
||||
// Assert.IsNotNull(methodInfo, "ToString() not found in " + type.FullName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestUnitTests()
|
||||
// {
|
||||
// Type[] allTypes = typeof(StructuralTest).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.GetCustomAttributes(typeof(TestFixtureAttribute), true).Length > 0) {
|
||||
// foreach (MethodInfo m in type.GetMethods()) {
|
||||
// if (m.IsPublic && m.ReturnType == typeof(void) && m.GetParameters().Length == 0) {
|
||||
// if (m.GetCustomAttributes(typeof(TestAttribute), true).Length == 0) {
|
||||
// Assert.Fail(type.Name + "." + m.Name + " should have the [Test] attribute!");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestAcceptVisitorMethods()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && type.GetInterface(typeof(INode).FullName) != null) {
|
||||
// MethodInfo methodInfo = type.GetMethod("AcceptVisitor", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
|
||||
// Assertion.AssertNotNull("AcceptVisitor() not found in " + type.FullName, methodInfo);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestIAstVisitor()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
// Type visitor = typeof(IAstVisitor);
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) {
|
||||
// MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null);
|
||||
// Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found");
|
||||
// Assert.AreEqual(2, methodInfo.GetParameters().Length);
|
||||
// ParameterInfo first = methodInfo.GetParameters()[0];
|
||||
// Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name);
|
||||
//
|
||||
// ParameterInfo second = methodInfo.GetParameters()[1];
|
||||
// Assert.AreEqual(typeof(System.Object), second.ParameterType);
|
||||
// Assert.AreEqual("data", second.Name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestAbstractAstVisitorVisitor()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
// Type visitor = typeof(AbstractAstVisitor);
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) {
|
||||
// MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null);
|
||||
// Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found");
|
||||
//
|
||||
// Assert.AreEqual(2, methodInfo.GetParameters().Length);
|
||||
// ParameterInfo first = methodInfo.GetParameters()[0];
|
||||
// Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name);
|
||||
//
|
||||
// ParameterInfo second = methodInfo.GetParameters()[1];
|
||||
// Assert.AreEqual(typeof(System.Object), second.ParameterType);
|
||||
// Assert.AreEqual("data", second.Name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
} |
||||
} |
||||
@ -1,109 +0,0 @@
@@ -1,109 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>8.0.50215</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{870115DD-960A-4406-A6B9-600BCDC36A03}</ProjectGuid> |
||||
<RootNamespace>ICSharpCode.NRefactory.VB.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.VB.Tests</AssemblyName> |
||||
<OutputTarget>Library</OutputTarget> |
||||
<NoStdLib>False</NoStdLib> |
||||
<NoConfig>False</NoConfig> |
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> |
||||
<OutputType>Library</OutputType> |
||||
<OutputPath>bin\$(Configuration)\</OutputPath> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> |
||||
<NoWin32Manifest>False</NoWin32Manifest> |
||||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<DebugType>Full</DebugType> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<StartAction>Project</StartAction> |
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="nunit.framework"> |
||||
<HintPath>..\..\ICSharpCode.Decompiler\Tests\nunit.framework.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="General\UnitTest.cs" /> |
||||
<Compile Include="Lexer\CustomLexerTests.cs" /> |
||||
<Compile Include="Lexer\ImplicitLineContinuationTests.cs" /> |
||||
<Compile Include="Lexer\LATextReaderTests.cs" /> |
||||
<Compile Include="Lexer\LexerContextTests.cs" /> |
||||
<Compile Include="Lexer\LexerPositionTests.cs" /> |
||||
<Compile Include="Lexer\LexerTests.cs" /> |
||||
<Compile Include="Lexer\LiteralsTests.cs" /> |
||||
<Compile Include="Lexer\TokenTests.cs" /> |
||||
<Compile Include="Lexer\XmlModeLexerTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\AttributeSectionTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\NamespaceDeclarationTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\ImportsStatementTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\TypeDeclarationTests.cs" /> |
||||
<Compile Include="Parser\SnippetParserTests.cs" /> |
||||
<Compile Include="Parser\ParseUtil.cs" /> |
||||
<Compile Include="Parser\GlobalScope\OptionStatementTests.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory.VB\ICSharpCode.NRefactory.VB.csproj"> |
||||
<Project>{7b82b671-419f-45f4-b778-d9286f996efa}</Project> |
||||
<Name>ICSharpCode.NRefactory.VB</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3b2a5653-ec97-4001-bb9b-d90f1af2c371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> |
||||
</Project> |
||||
@ -1,118 +0,0 @@
@@ -1,118 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class CustomLexerTests |
||||
{ |
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleEOLForMulitpleLines() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("Stop\n\n\nEnd")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleEOLForMulitpleLinesWithContinuation() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("Stop\n _\n\nEnd")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void EscapedIdentifier() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("[Stop]")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdentifierWithTypeCharacter() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("Stop$")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsTypeCharacter() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a!=b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Assign)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsTypeCharacter2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a! b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsIdentifier() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a!b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsIdentifier2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a![b]")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemCommentTest() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a rem b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemCommentTest2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("REM c")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
} |
||||
} |
||||
@ -1,230 +0,0 @@
@@ -1,230 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class ImplicitLineContinuationTests |
||||
{ |
||||
[Test] |
||||
public void Example1() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print( |
||||
Param1 As Integer, |
||||
Param2 As Integer) |
||||
|
||||
If (Param1 < Param2) Or |
||||
(Param1 > Param2) Then |
||||
Console.WriteLine(""Not equal"") |
||||
End If |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, |
||||
Tokens.Identifier, Tokens.As, Tokens.Integer, Tokens.Comma, |
||||
Tokens.Identifier, Tokens.As, Tokens.Integer, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.If, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.LessThan, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.Or, |
||||
Tokens.OpenParenthesis, Tokens.Identifier, Tokens.GreaterThan, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.Then, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.End, Tokens.If, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void QualifierInWith() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print |
||||
With xml |
||||
Dim a = b. |
||||
d |
||||
Dim c = . |
||||
Count |
||||
End With |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.With, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Dot, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.With, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Example2() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print |
||||
Dim a = _ |
||||
|
||||
y |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.EOL, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Query() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub A |
||||
Dim q = From x In a |
||||
Select x |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Query1() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub A |
||||
Dim actions = From a in b Select Sub() |
||||
Dim i = 1 |
||||
Select Case i |
||||
End Select |
||||
End Sub |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Select, Tokens.Sub, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Select, Tokens.Case, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Select, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
/// <remarks>tests http://community.sharpdevelop.net/forums/p/12068/32893.aspx#32893</remarks>
|
||||
[Test] |
||||
public void Bug_Thread12068() |
||||
{ |
||||
string code = @"Class MainClass
|
||||
Public Shared Sub Main() |
||||
Dim categoryNames = From p In AList _ |
||||
Select p.AFunction(1,2,3) _ |
||||
Distinct |
||||
End Sub |
||||
End Class";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Public, Tokens.Shared, Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.LiteralInteger, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis, |
||||
Tokens.Distinct, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void LineContinuationAfterAttributes() |
||||
{ |
||||
string code = @"<TestFixture>
|
||||
Public Class TestContinuation |
||||
<Test> |
||||
Public Sub TestMethod |
||||
Assert.Fail |
||||
End Sub |
||||
|
||||
<Test> _ |
||||
Public Sub TestMethod2 |
||||
Assert.Fail |
||||
End Sub |
||||
End Class";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoILCAfterGlobalAttributes() |
||||
{ |
||||
string code = "<Assembly: AssemblyTitle(\"My.UnitTests\")>" + Environment.NewLine + |
||||
"<Assembly: AssemblyDescription(\"\")>"; |
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.LessThan, Tokens.Assembly, Tokens.Colon, |
||||
Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.CloseParenthesis, Tokens.GreaterThan, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Assembly, Tokens.Colon, |
||||
Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.CloseParenthesis, Tokens.GreaterThan |
||||
); |
||||
} |
||||
|
||||
#region Helpers
|
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
void CheckTokens(VBLexer lexer, params int[] tokens) |
||||
{ |
||||
for (int i = 0; i < tokens.Length; i++) { |
||||
int token = tokens[i]; |
||||
Token t = lexer.NextToken(); |
||||
int next = t.Kind; |
||||
Assert.AreEqual(token, next, "{2} of {3}: {0} != {1}; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LATextReaderTests |
||||
{ |
||||
[Test] |
||||
public void TestPeek() |
||||
{ |
||||
LATextReader reader = new LATextReader(new StringReader("abcd")); |
||||
|
||||
CheckPeek(reader, 0, 'a'); |
||||
CheckPeek(reader, 2, 'c'); |
||||
CheckPeek(reader, 3, 'd'); |
||||
CheckPeek(reader, 1, 'b'); |
||||
CheckPeek(reader, 0, 'a'); |
||||
Assert.AreEqual((int)'a', reader.Read()); |
||||
CheckPeek(reader, 1, 'c'); |
||||
CheckPeek(reader, 2, 'd'); |
||||
CheckPeek(reader, 0, 'b'); |
||||
} |
||||
|
||||
void CheckPeek(LATextReader reader, int num1, char char2) |
||||
{ |
||||
Assert.AreEqual((int)char2, reader.Peek(num1)); |
||||
} |
||||
} |
||||
} |
||||
@ -1,575 +0,0 @@
@@ -1,575 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LexerContextTests |
||||
{ |
||||
[Test] |
||||
public void SimpleGlobal() |
||||
{ |
||||
RunTest( |
||||
@"Option Explicit", |
||||
@"enter Global
|
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void VariableWithXmlLiteral() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
Dim x = <a /> |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberWithXmlLiteral() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Private xml As XElement = <b /> |
||||
|
||||
Public Sub New() |
||||
Dim x = <a /> |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Member |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void GlobalAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"<assembly: CLSCompliant(True)>
|
||||
Class Test |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter Attribute |
||||
exit Attribute |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"<Serializable>
|
||||
Class Test |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter Attribute |
||||
exit Attribute |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
<Test> |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Attribute |
||||
exit Attribute |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithBlockTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
With x |
||||
|
||||
End With |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void StatementsTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
For i As Integer = 0 To 10 |
||||
|
||||
Next |
||||
|
||||
For Each x As Integer In list |
||||
|
||||
Next |
||||
|
||||
Try |
||||
|
||||
Catch e As Exception |
||||
|
||||
End Try |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
enter Body |
||||
exit Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassTest() |
||||
{ |
||||
RunTest( |
||||
@"Class MainClass ' a comment
|
||||
Dim under_score_field As Integer |
||||
Sub SomeMethod() |
||||
simple += 1 |
||||
For Each loopVarName In collection |
||||
Next |
||||
End Sub |
||||
End Class",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
exit Member |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
[Test] |
||||
public void CollectionInitializer() |
||||
{ |
||||
RunTest(@"'
|
||||
' Created by SharpDevelop. |
||||
' User: Siegfried |
||||
' Date: 22.06.2010 |
||||
' Time: 21:29 |
||||
' |
||||
' To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
' |
||||
|
||||
Option Infer On |
||||
|
||||
Imports System.Linq |
||||
Imports System.Xml.Linq |
||||
|
||||
Module Program |
||||
Sub Main() |
||||
Console.WriteLine(""Hello World!"") |
||||
|
||||
Dim name = ""Test"" |
||||
Dim content = { 4, 5, New XAttribute(""a"", 3) } |
||||
|
||||
Dim xml = <<%= name %> <%= content %> /> |
||||
|
||||
Console.ReadKey() |
||||
End Sub |
||||
End Module",
|
||||
@"enter Global
|
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter ObjectCreation |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit ObjectCreation |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
[Test] |
||||
public void Imports() |
||||
{ |
||||
RunTest(@"Imports System
|
||||
Imports System.Linq |
||||
Imports System.Collections.Generic",
|
||||
@"enter Global
|
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
void RunTest(string code, string expectedOutput) |
||||
{ |
||||
ExpressionFinder p = new ExpressionFinder(); |
||||
VBLexer lexer = new VBLexer(new StringReader(code)); |
||||
Token t; |
||||
|
||||
do { |
||||
t = lexer.NextToken(); |
||||
p.InformToken(t); |
||||
} while (t.Kind != Tokens.EOF); |
||||
|
||||
Console.WriteLine(p.Output); |
||||
|
||||
Assert.IsEmpty(p.Errors); |
||||
|
||||
Assert.AreEqual(expectedOutput.Replace("\r", ""), |
||||
p.Output.Replace("\r", "")); |
||||
} |
||||
} |
||||
} |
||||
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LexerPositionTests |
||||
{ |
||||
VBLexer GenerateLexer(string s) |
||||
{ |
||||
return new VBLexer(new StringReader(s)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestNewLine() |
||||
{ |
||||
VBLexer l = GenerateLexer("public\nstatic"); |
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Public, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Static, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 7), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCarriageReturnNewLine() |
||||
{ |
||||
VBLexer l = GenerateLexer("public\r\nstatic"); |
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Public, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Static, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 7), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestPositionOfEOF1() |
||||
{ |
||||
VBLexer l = GenerateLexer("public"); |
||||
l.NextToken(); // public
|
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
|
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOF, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestPositionOfEOF2() |
||||
{ |
||||
VBLexer l = GenerateLexer("public _\n "); |
||||
l.NextToken(); // public
|
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.EndLocation); |
||||
|
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOF, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.EndLocation); |
||||
} |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -1,194 +0,0 @@
@@ -1,194 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public sealed class LiteralsTests |
||||
{ |
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
Token GetSingleToken(string text) |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(text)); |
||||
Token t = lexer.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, lexer.NextToken().Kind, "Tokens.EOL"); |
||||
Assert.AreEqual(Tokens.EOF, lexer.NextToken().Kind, "Tokens.EOF"); |
||||
Assert.AreEqual("", lexer.Errors.ErrorOutput); |
||||
return t; |
||||
} |
||||
|
||||
void CheckToken(string text, int tokenType, object val) |
||||
{ |
||||
Token t = GetSingleToken(text); |
||||
Assert.AreEqual(tokenType, t.Kind, "Tokens.Literal"); |
||||
Assert.IsNotNull(t.LiteralValue, "literalValue is null"); |
||||
Assert.AreEqual(val.GetType(), t.LiteralValue.GetType(), "literalValue.GetType()"); |
||||
Assert.AreEqual(val, t.LiteralValue, "literalValue"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleDigit() |
||||
{ |
||||
CheckToken("5", Tokens.LiteralInteger, 5); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestZero() |
||||
{ |
||||
CheckToken("0", Tokens.LiteralInteger, 0); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestInteger() |
||||
{ |
||||
CheckToken("15", Tokens.LiteralInteger, 15); |
||||
CheckToken("8581", Tokens.LiteralInteger, 8581); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidTypeCharacter() |
||||
{ |
||||
// just check that we don't get exceptions:
|
||||
GenerateLexer(new StringReader(".5s")).NextToken(); |
||||
GenerateLexer(new StringReader(".5ul")).NextToken(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestHexadecimalInteger() |
||||
{ |
||||
CheckToken("&H10", Tokens.LiteralInteger, 0x10); |
||||
CheckToken("&H10&", Tokens.LiteralInteger, (long)0x10); |
||||
CheckToken("&h3ff%", Tokens.LiteralInteger, 0x3ff); |
||||
CheckToken("&h8000s", Tokens.LiteralInteger, short.MinValue); |
||||
CheckToken("&h8000us", Tokens.LiteralInteger, (ushort)0x8000); |
||||
CheckToken("&HffffFFFF", Tokens.LiteralInteger, -1); |
||||
CheckToken("&HffffFFFF%", Tokens.LiteralInteger, -1); |
||||
CheckToken("&HffffFFFFui", Tokens.LiteralInteger, uint.MaxValue); |
||||
CheckToken("&HffffFFFF&", Tokens.LiteralInteger, (long)uint.MaxValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestLongHexadecimalInteger() |
||||
{ |
||||
CheckToken("&H4244636f446c6d58", Tokens.LiteralInteger, 0x4244636f446c6d58); |
||||
CheckToken("&hf244636f446c6d58", Tokens.LiteralInteger, -989556688574190248); |
||||
CheckToken("&hf244636f446c6d58&", Tokens.LiteralInteger, -989556688574190248); |
||||
CheckToken("&hf244636f446c6d58ul", Tokens.LiteralInteger, 0xf244636f446c6d58); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidHexadecimalInteger() |
||||
{ |
||||
// just check that we don't get exceptions:
|
||||
GenerateLexer(new StringReader("&H")).NextToken(); |
||||
// >ulong.MaxValue
|
||||
GenerateLexer(new StringReader("&hff244636f446c6d58")).NextToken(); |
||||
// needs an ulong, but "i" postfix specified integer
|
||||
GenerateLexer(new StringReader("&hf244636f446c6d58i")).NextToken(); |
||||
GenerateLexer(new StringReader("&hf244636f446c6d58ui")).NextToken(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestIncompleteHexadecimal() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("&H\r\nabc")); |
||||
Token t = lexer.NextToken(); |
||||
Assert.AreEqual(Tokens.LiteralInteger, t.Kind); |
||||
Assert.AreEqual(0, (int)t.LiteralValue); |
||||
Assert.AreEqual(Tokens.EOL, lexer.NextToken().Kind, "Tokens.EOL (1)"); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind, "Tokens.Identifier"); |
||||
Assert.AreEqual(Tokens.EOL, lexer.NextToken().Kind, "Tokens.EOL (2)"); |
||||
Assert.AreEqual(Tokens.EOF, lexer.NextToken().Kind, "Tokens.EOF"); |
||||
Assert.AreNotEqual("", lexer.Errors.ErrorOutput); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestStringLiterals() |
||||
{ |
||||
CheckToken("\"\"", Tokens.LiteralString, ""); |
||||
CheckToken("\"Hello, World!\"", Tokens.LiteralString, "Hello, World!"); |
||||
CheckToken("\"\"\"\"", Tokens.LiteralString, "\""); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCharacterLiterals() |
||||
{ |
||||
CheckToken("\" \"c", Tokens.LiteralCharacter, ' '); |
||||
CheckToken("\"!\"c", Tokens.LiteralCharacter, '!'); |
||||
CheckToken("\"\"\"\"c", Tokens.LiteralCharacter, '"'); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDateLiterals() |
||||
{ |
||||
CheckToken("# 8/23/1970 #", Tokens.LiteralDate, new DateTime(1970, 8, 23, 0, 0, 0)); |
||||
CheckToken("#8/23/1970#", Tokens.LiteralDate, new DateTime(1970, 8, 23, 0, 0, 0)); |
||||
CheckToken("# 8/23/1970 3:45:39AM #", Tokens.LiteralDate, new DateTime(1970, 8, 23, 3, 45, 39)); |
||||
CheckToken("# 3:45:39AM #", Tokens.LiteralDate, new DateTime(1, 1, 1, 3, 45, 39)); |
||||
CheckToken("# 3:45:39 PM #", Tokens.LiteralDate, new DateTime(1, 1, 1, 15, 45, 39)); |
||||
CheckToken("# 3:45:39 #", Tokens.LiteralDate, new DateTime(1, 1, 1, 3, 45, 39)); |
||||
CheckToken("# 13:45:39 #", Tokens.LiteralDate, new DateTime(1, 1, 1, 13, 45, 39)); |
||||
CheckToken("# 1AM #", Tokens.LiteralDate, new DateTime(1, 1, 1, 1, 0, 0)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDouble() |
||||
{ |
||||
CheckToken("1.0", Tokens.LiteralDouble, 1.0); |
||||
CheckToken("1.1", Tokens.LiteralDouble, 1.1); |
||||
CheckToken("2e-5", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2.0e-5", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2e5", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e5", Tokens.LiteralDouble, 2.2e5); |
||||
CheckToken("2e+5", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e+5", Tokens.LiteralDouble, 2.2e5); |
||||
|
||||
CheckToken("1r", Tokens.LiteralDouble, 1.0); |
||||
CheckToken("1.0r", Tokens.LiteralDouble, 1.0); |
||||
CheckToken("1.1r", Tokens.LiteralDouble, 1.1); |
||||
CheckToken("2e-5r", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2.0e-5r", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2e5r", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e5r", Tokens.LiteralDouble, 2.2e5); |
||||
CheckToken("2e+5r", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e+5r", Tokens.LiteralDouble, 2.2e5); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingle() |
||||
{ |
||||
CheckToken("1f", Tokens.LiteralSingle, 1.0f); |
||||
CheckToken("1.0f", Tokens.LiteralSingle, 1.0f); |
||||
CheckToken("1.1f", Tokens.LiteralSingle, 1.1f); |
||||
CheckToken("2e-5f", Tokens.LiteralSingle, 2e-5f); |
||||
CheckToken("2.0e-5f", Tokens.LiteralSingle, 2e-5f); |
||||
CheckToken("2e5f", Tokens.LiteralSingle, 2e5f); |
||||
CheckToken("2.2e5f", Tokens.LiteralSingle, 2.2e5f); |
||||
CheckToken("2e+5f", Tokens.LiteralSingle, 2e5f); |
||||
CheckToken("2.2e+5f", Tokens.LiteralSingle, 2.2e5f); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDecimal() |
||||
{ |
||||
CheckToken("1d", Tokens.LiteralDecimal, 1m); |
||||
CheckToken("1.0d", Tokens.LiteralDecimal, 1.0m); |
||||
CheckToken("1.1d", Tokens.LiteralDecimal, 1.1m); |
||||
CheckToken("2e-5d", Tokens.LiteralDecimal, 2e-5m); |
||||
CheckToken("2.0e-5d", Tokens.LiteralDecimal, 2.0e-5m); |
||||
CheckToken("2e5d", Tokens.LiteralDecimal, 2e5m); |
||||
CheckToken("2.2e5d", Tokens.LiteralDecimal, 2.2e5m); |
||||
CheckToken("2e+5d", Tokens.LiteralDecimal, 2e5m); |
||||
CheckToken("2.2e+5d", Tokens.LiteralDecimal, 2.2e5m); |
||||
} |
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class TokenTests |
||||
{ |
||||
[Test] |
||||
public void TokenToStringDoesNotThrowException() |
||||
{ |
||||
Assert.DoesNotThrow( |
||||
() => { |
||||
string text = new Token(71, 1, 1).ToString(); |
||||
} |
||||
); |
||||
} |
||||
} |
||||
} |
||||
@ -1,993 +0,0 @@
@@ -1,993 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class XmlModeLexerTests |
||||
{ |
||||
#region Xml Tests
|
||||
[Test] |
||||
public void TagWithContent() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <Test>Hello World</Test>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
Assert.AreEqual(Tokens.Dim, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Assign, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlText() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <div><h1>Title</h1>" + |
||||
"<p>test test <br /> test</p></div>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
Assert.AreEqual(Tokens.Dim, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Assign, lexer.NextToken().Kind); |
||||
|
||||
// <div>
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// <h1>
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// Title
|
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
|
||||
// </h1>
|
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// <p>
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// test test
|
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
|
||||
// <br />
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTagEmptyElement, lexer.NextToken().Kind); |
||||
|
||||
// test
|
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
|
||||
// </p>
|
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// </div>
|
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlLiteralsExample1() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim xml = <menu>\n" + |
||||
" <course name=\"appetizer\">\n" + |
||||
" <dish>Shrimp Cocktail</dish>\n" + |
||||
" <dish>Escargot</dish>\n" + |
||||
" </course>\n" + |
||||
" <course name=\"main\">\n" + |
||||
" <dish>Filet Mignon</dish>\n" + |
||||
" <dish>Garlic Potatoes</dish>\n" + |
||||
" <dish>Broccoli</dish>\n" + |
||||
" </course>\n" + |
||||
" <course name=\"dessert\">\n" + |
||||
" <dish>Chocolate Cheesecake</dish>\n" + |
||||
" </course>\n" + |
||||
" </menu>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
// <menu>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <course name=\"appetizer\">
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Shrimp Cocktail</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Escargot</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </course>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <course name=\"main\">
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Filet Mignon</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Garlic Potatoes</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Broccoli</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </course>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <course name=\"dessert\">
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Chocolate Cheesecake</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </course>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </menu>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleXmlWithComments() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim x = <?xml version=""1.0""?> <!-- Test file -->
|
||||
<Test> |
||||
<!-- Test data --> |
||||
<Data /> |
||||
</Test> |
||||
<!-- eof --> |
||||
<!-- hey, wait! --> |
||||
<?target some data?>")));
|
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlProcessingInstruction, Tokens.XmlContent, Tokens.XmlComment, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlComment, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlComment, Tokens.XmlComment, Tokens.XmlProcessingInstruction); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleEmptyTag() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <Test />"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleTag() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <Test></Test>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlImport() |
||||
{ |
||||
string code = @"Imports System
|
||||
Imports System.Linq |
||||
|
||||
Imports <xmlns='http://icsharpcode.net/sharpdevelop/avalonedit'>
|
||||
Imports <xmlns:h='http://www.w3.org/TR/html4/'>
|
||||
|
||||
Class TestClass |
||||
Sub TestSub() |
||||
Dim xml = <h:table> |
||||
<h:tr> |
||||
<h:td>1. Cell</h:td> |
||||
</h:tr> |
||||
</h:table> |
||||
End Sub |
||||
End Class";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Imports, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Imports, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Imports, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.EOL, |
||||
Tokens.Imports, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.EOL, |
||||
Tokens.Class, Tokens.Identifier, Tokens.EOL, Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.EOL, Tokens.End, Tokens.Sub, Tokens.EOL, Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void CDataSection() |
||||
{ |
||||
string xml = @"Dim xml = <template>
|
||||
<name>test</name> |
||||
<language>VB</languge> |
||||
<file language='XAML'> |
||||
<![CDATA[<Window x:Class='DefaultNamespace.Window1' |
||||
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
|
||||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
||||
Title='DefaultNamespace' Height='300' Width='300'> |
||||
<Grid> |
||||
|
||||
</Grid> |
||||
</Window>]]> |
||||
</file> |
||||
<file language='CSharp'> |
||||
<![CDATA[using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
namespace DefaultNamespace |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for Window1.xaml
|
||||
/// </summary>
|
||||
public partial class Window1 : Window |
||||
{ |
||||
public Window1() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
||||
}]]> |
||||
</file> |
||||
</template> |
||||
";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(xml))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, // 2
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 6
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 10
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 14
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 18
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 22
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, // 28
|
||||
Tokens.XmlContent, Tokens.XmlCData, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, // 34
|
||||
Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlCData, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void InlineVB() |
||||
{ |
||||
string code = @"Dim xml = <?xml version='1.0'?>
|
||||
<menu> |
||||
<course name=""appetizer""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""appetizer"" _ |
||||
Select <dish><%= m.Food %></dish> _ |
||||
%> |
||||
</course> |
||||
<course name=""main""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""main"" _ |
||||
Select <dish><%= m.Food %></dish> _ |
||||
%> |
||||
</course> |
||||
<course name=""dessert""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""dessert"" _ |
||||
Select <dish><%= m.Food %></dish> _ |
||||
%> |
||||
</course> |
||||
</menu>";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(code))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlProcessingInstruction, Tokens.XmlContent, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlStartInlineVB, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Where, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.Select, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlEndInlineVB, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlStartInlineVB, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Where, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.Select, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlEndInlineVB, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlStartInlineVB, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Where, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.Select, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlEndInlineVB, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void InlineVB2() |
||||
{ |
||||
string code = @"Dim contact As XElement = <<%=elementName %>>
|
||||
<name><%= MyName %></name> |
||||
</>";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(code))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.As, Tokens.Identifier, Tokens.Assign, Tokens.XmlOpenTag, |
||||
Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.XmlEndInlineVB, Tokens.XmlCloseTag, Tokens.XmlContent, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.XmlCloseTag); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlAccessOperators() |
||||
{ |
||||
string code = @"Dim childAxis = xml.<menu>.<course>
|
||||
Dim course3 = xml...<course>(2) |
||||
Dim childAxis = xml...<course> |
||||
For Each item In childAxis |
||||
Console.WriteLine(item.@name) |
||||
Next";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(code))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.Dot, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.Dot, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.EOL, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.TripleDot, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.OpenParenthesis, Tokens.LiteralInteger, Tokens.CloseParenthesis, |
||||
Tokens.EOL, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.TripleDot, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.EOL, Tokens.For, Tokens.Each, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.DotAt, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Next); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetXmlNamespace() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim name = GetXmlNamespace(x)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.GetXmlNamespace, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetXmlNamespace2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim name = GetXmlNamespace(db-name)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.GetXmlNamespace, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.CloseParenthesis); |
||||
|
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlInSelect() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim data = From x In list Select <test>x</test>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Select, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfExpressionTest() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim name = If(a <> 2, 4, 8)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.If, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.NotEqual, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.LiteralInteger, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfStatementTest() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("If a <> 2 Then Return"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.If, Tokens.Identifier, Tokens.NotEqual, Tokens.LiteralInteger, |
||||
Tokens.Then, Tokens.Return); |
||||
|
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug1() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim xml = <!-- test -->"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlComment); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim xml = <?xml?><Data /><!-- test -->"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlProcessingInstruction, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTagEmptyElement, Tokens.XmlComment); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug3() |
||||
{ |
||||
VBLexer lexer = GenerateLexerForSnippet(new StringReader("New String() {}"), SnippetType.Expression); |
||||
|
||||
CheckTokens(lexer, Tokens.New, Tokens.String, Tokens.OpenParenthesis, |
||||
Tokens.CloseParenthesis, Tokens.OpenCurlyBrace, Tokens.CloseCurlyBrace); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug4() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) In styleCache.CellStyleCache _
|
||||
Select includeStyle(kvp.Key, kvp.Value)")));
|
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.As, Tokens.Identifier, |
||||
Tokens.OpenParenthesis, Tokens.Of, Tokens.String, Tokens.Comma, Tokens.Identifier, Tokens.CloseParenthesis, |
||||
Tokens.In, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.Dot, Tokens.Key, Tokens.Comma, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void LessThanCheck() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim xml = <!-- test --><Data"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlComment, Tokens.LessThan, Tokens.Identifier); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Context Tests
|
||||
[Test] |
||||
public void MethodInvocation() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("DoSomething(<Test />, True)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, Tokens.True, |
||||
Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddHandlerStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("AddHandler <Test />, True"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.AddHandler, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, Tokens.True); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddHandlerStatement2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("AddHandler <x />, <y />"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.AddHandler, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveHandlerStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("RemoveHandler <x />, <Data>5</Data>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.RemoveHandler, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorHandlingStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("On Error Resume Next\n" + |
||||
"On Error GoTo -1\n" + |
||||
"On Error GoTo 0\n" + |
||||
"On Error GoTo Test\n" + |
||||
"Error 5\n" + |
||||
"Error <Test />\n" + |
||||
"Resume Next\n" + |
||||
"Resume Label\n" + |
||||
"Resume 4"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.On, Tokens.Error, Tokens.Resume, Tokens.Next, Tokens.EOL, |
||||
Tokens.On, Tokens.Error, Tokens.GoTo, Tokens.Minus, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.On, Tokens.Error, Tokens.GoTo, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.On, Tokens.Error, Tokens.GoTo, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Error, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Error, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Resume, Tokens.Next, Tokens.EOL, |
||||
Tokens.Resume, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Resume, Tokens.LiteralInteger |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForLoopStatement() |
||||
{ |
||||
string statement = @"For <Test /> = <Test /> To <Test /> Step <Test />
|
||||
Next <Test />, <Test /> |
||||
|
||||
For Each <Test /> In <Test /> |
||||
Next <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.For, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.Assign, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.To, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.Step, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Next, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.For, Tokens.Each, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.In, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Next, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileLoopStatement() |
||||
{ |
||||
string statement = @"While <Test />
|
||||
End While";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.While, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.End, Tokens.While |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileLoopStatement2() |
||||
{ |
||||
string statement = @"Do While <Test />
|
||||
Loop";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.While, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Loop |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileLoopStatement3() |
||||
{ |
||||
string statement = @"Do
|
||||
Loop While <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.EOL, |
||||
Tokens.Loop, Tokens.While, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntilLoopStatement() |
||||
{ |
||||
string statement = @"Do Until <Test />
|
||||
Loop";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.Until, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Loop |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntilLoopStatement2() |
||||
{ |
||||
string statement = @"Do
|
||||
Loop Until <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.EOL, |
||||
Tokens.Loop, Tokens.Until, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfStatementLarge() |
||||
{ |
||||
string statement = @"If <Test /> Then
|
||||
Else If <Test /> Then |
||||
ElseIf <Test></Test> Then |
||||
Else |
||||
End If";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.If, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Then, Tokens.EOL, |
||||
Tokens.Else, Tokens.If, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Then, Tokens.EOL, |
||||
Tokens.ElseIf, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.Then, Tokens.EOL, |
||||
Tokens.Else, Tokens.EOL, |
||||
Tokens.End, Tokens.If |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectStatement() |
||||
{ |
||||
string statement = @"Select Case <Test />
|
||||
Case <Test />, <Test /> |
||||
Case Else |
||||
End Select";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Select, Tokens.Case, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Case, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Case, Tokens.Else, Tokens.EOL, |
||||
Tokens.End, Tokens.Select |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void TryStatement() |
||||
{ |
||||
string statement = @"Try
|
||||
Catch x |
||||
Catch y As Exception |
||||
Catch When <Test /> |
||||
Finally |
||||
End Try";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Try, Tokens.EOL, |
||||
Tokens.Catch, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Catch, Tokens.Identifier, Tokens.As, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Catch, Tokens.When, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Finally, Tokens.EOL, |
||||
Tokens.End, Tokens.Try |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThrowStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Throw <Test />"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Throw, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void BranchStatements() |
||||
{ |
||||
string statement = @"GoTo 5
|
||||
GoTo LabelName |
||||
Exit Do |
||||
Exit For |
||||
Exit While |
||||
Exit Select |
||||
Exit Sub |
||||
Exit Function |
||||
Exit Property |
||||
Exit Try |
||||
Continue Do |
||||
Continue For |
||||
Continue While |
||||
Stop |
||||
End |
||||
Return |
||||
Return 5 |
||||
Return <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.GoTo, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.GoTo, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Do, Tokens.EOL, |
||||
Tokens.Exit, Tokens.For, Tokens.EOL, |
||||
Tokens.Exit, Tokens.While, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Select, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Sub, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Function, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Property, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Try, Tokens.EOL, |
||||
Tokens.Continue, Tokens.Do, Tokens.EOL, |
||||
Tokens.Continue, Tokens.For, Tokens.EOL, |
||||
Tokens.Continue, Tokens.While, Tokens.EOL, |
||||
Tokens.Stop, Tokens.EOL, |
||||
Tokens.End, Tokens.EOL, |
||||
Tokens.Return, Tokens.EOL, |
||||
Tokens.Return, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Return, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayHandlingStatements() |
||||
{ |
||||
string statement = @"Erase <Test />
|
||||
Erase <Test />, <Test /> |
||||
ReDim Preserve <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Erase, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Erase, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.ReDim, Tokens.Preserve, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void UsingStatement() |
||||
{ |
||||
string statement = @"Using <Test />
|
||||
End Using";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Using, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.End, Tokens.Using |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewExpressionWithObjectInitializer() |
||||
{ |
||||
string code = @"New Common.ComboBoxItem With {.Item = _
|
||||
Localizer.GetString(""Month"" & initParameters.SelectedDate.FirstDayOfPreviousMonth.Month) & "" "" & |
||||
initParameters.SelectedDate.FirstDayOfPreviousMonth.Year, .Value = New Date(2010, initParameters.SelectedDate.FirstDayOfPreviousMonth.Month, 1)}";
|
||||
|
||||
VBLexer lexer = GenerateLexerForSnippet(new StringReader(code), SnippetType.Expression); |
||||
|
||||
CheckTokens(lexer, Tokens.New, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, |
||||
Tokens.With, Tokens.OpenCurlyBrace, Tokens.Dot, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.ConcatString, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.ConcatString, |
||||
Tokens.LiteralString, Tokens.ConcatString, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, |
||||
Tokens.Dot, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Comma, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.New, Tokens.Date, Tokens.OpenParenthesis, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis, Tokens.CloseCurlyBrace); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
VBLexer GenerateLexerForSnippet(StringReader sr, SnippetType type) |
||||
{ |
||||
var lexer = new VBLexer(sr); |
||||
lexer.SetInitialContext(type); |
||||
return lexer; |
||||
} |
||||
|
||||
string TestStatement(string stmt) |
||||
{ |
||||
return "Class Test\n" + |
||||
"Sub A\n" + |
||||
stmt + "\n" + |
||||
"End Sub\n" + |
||||
"End Class"; |
||||
} |
||||
|
||||
void CheckFoot(VBLexer lexer) |
||||
{ |
||||
CheckTokens(lexer, Tokens.EOL, Tokens.End, Tokens.Sub, Tokens.EOL, Tokens.End, Tokens.Class); |
||||
} |
||||
|
||||
void CheckHead(VBLexer lexer) |
||||
{ |
||||
CheckTokens(lexer, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL); |
||||
} |
||||
|
||||
void CheckTokens(VBLexer lexer, params int[] tokens) |
||||
{ |
||||
for (int i = 0; i < tokens.Length; i++) { |
||||
int token = tokens[i]; |
||||
Token t = lexer.NextToken(); |
||||
int next = t.Kind; |
||||
Assert.IsEmpty(lexer.Errors.ErrorOutput); |
||||
Assert.AreEqual(token, next, "{2} of {3}: expected: \"{0}\", was: \"{1}\"; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class CodeDOMParenthesizedExpressionTest |
||||
{ |
||||
[Test] |
||||
public void TestParenthesizedExpression() |
||||
{ |
||||
object output = new ParenthesizedExpression(new PrimitiveExpression(5, "5")).AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodePrimitiveExpression); |
||||
} |
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class CodeDOMPrimitiveExpressionsTests |
||||
{ |
||||
[Test] |
||||
public void TestPrimitiveExpression() |
||||
{ |
||||
object output = new PrimitiveExpression(5, "5").AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodePrimitiveExpression); |
||||
Assert.AreEqual(((CodePrimitiveExpression)output).Value, 5); |
||||
} |
||||
} |
||||
} |
||||
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class CodeDOMTypeReferenceTest |
||||
{ |
||||
[TestAttribute] |
||||
public void InnerClassTypeReferencTest() |
||||
{ |
||||
InnerClassTypeReference ictr = new InnerClassTypeReference( |
||||
new TypeReference("OuterClass", new List<TypeReference> { new TypeReference("String") }), |
||||
"InnerClass", |
||||
new List<TypeReference> { new TypeReference("Int32"), new TypeReference("Int64") }); |
||||
Assert.AreEqual("OuterClass<String>+InnerClass<Int32,Int64>", ictr.ToString()); |
||||
CodeTypeOfExpression result = (CodeTypeOfExpression)new TypeOfExpression(ictr).AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.AreEqual("OuterClass`1+InnerClass`2", result.Type.BaseType); |
||||
Assert.AreEqual(3, result.Type.TypeArguments.Count); |
||||
} |
||||
} |
||||
} |
||||
@ -1,59 +0,0 @@
@@ -1,59 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class InvocationExpressionsTests |
||||
{ |
||||
[Test] |
||||
public void IdentifierOnlyInvocation() |
||||
{ |
||||
// InitializeComponents();
|
||||
SimpleNameExpression identifier = new SimpleNameExpression("InitializeComponents"); |
||||
InvocationExpression invocation = new InvocationExpression(identifier, new List<Expression>()); |
||||
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodeMethodInvokeExpression); |
||||
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; |
||||
Assert.AreEqual("InitializeComponents", mie.Method.MethodName); |
||||
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodOnThisReferenceInvocation() |
||||
{ |
||||
// InitializeComponents();
|
||||
MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents"); |
||||
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); |
||||
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodeMethodInvokeExpression); |
||||
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; |
||||
Assert.AreEqual("InitializeComponents", mie.Method.MethodName); |
||||
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvocationOfStaticMethod() |
||||
{ |
||||
// System.Drawing.Color.FromArgb();
|
||||
MemberReferenceExpression field = new MemberReferenceExpression(new SimpleNameExpression("System"), "Drawing"); |
||||
field = new MemberReferenceExpression(field, "Color"); |
||||
field = new MemberReferenceExpression(field, "FromArgb"); |
||||
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); |
||||
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodeMethodInvokeExpression); |
||||
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; |
||||
Assert.AreEqual("FromArgb", mie.Method.MethodName); |
||||
Assert.IsTrue(mie.Method.TargetObject is CodeTypeReferenceExpression); |
||||
Assert.AreEqual("System.Drawing.Color", (mie.Method.TargetObject as CodeTypeReferenceExpression).Type.BaseType); |
||||
} |
||||
} |
||||
} |
||||
@ -1,79 +0,0 @@
@@ -1,79 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.PrettyPrinter |
||||
{ |
||||
[TestFixture] |
||||
public class SpecialOutputVisitorTest |
||||
{ |
||||
void TestProgram(string program) |
||||
{ |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); |
||||
outputVisitor.Options.IndentationChar = ' '; |
||||
outputVisitor.Options.TabSize = 2; |
||||
outputVisitor.Options.IndentSize = 2; |
||||
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), |
||||
outputVisitor)) { |
||||
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); |
||||
} |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", "")); |
||||
parser.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void Enum() |
||||
{ |
||||
TestProgram("Enum Test\n" + |
||||
" ' a\n" + |
||||
" m1\n" + |
||||
" ' b\n" + |
||||
" m2\n" + |
||||
" ' c\n" + |
||||
"End Enum\n" + |
||||
"' d"); |
||||
} |
||||
|
||||
[Test] |
||||
public void CommentsInsideMethod() |
||||
{ |
||||
TestProgram(@"Public Class Class1
|
||||
Private Function test(l As Integer, lvw As Integer) As Boolean |
||||
' Begin |
||||
Dim i As Integer = 1 |
||||
Return False |
||||
' End of method |
||||
End Function |
||||
End Class");
|
||||
} |
||||
|
||||
[Test] |
||||
public void BlankLines() |
||||
{ |
||||
TestProgram("Imports System\n" + |
||||
"\n" + |
||||
"Imports System.IO"); |
||||
TestProgram("Imports System\n" + |
||||
"\n" + |
||||
"\n" + |
||||
"Imports System.IO"); |
||||
TestProgram("\n" + |
||||
"' Some comment\n" + |
||||
"\n" + |
||||
"Imports System.IO"); |
||||
} |
||||
} |
||||
} |
||||
@ -1,670 +0,0 @@
@@ -1,670 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.PrettyPrinter |
||||
{ |
||||
[TestFixture] |
||||
public class VBNetOutputTest |
||||
{ |
||||
void TestProgram(string program) |
||||
{ |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); |
||||
outputVisitor.Options.OutputByValModifier = true; |
||||
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text)); |
||||
} |
||||
|
||||
string StripWhitespace(string text) |
||||
{ |
||||
text = text.Trim().Replace("\t", "").Replace("\r", "").Replace("\n", " ").Replace(" ", " "); |
||||
while (text.Contains(" ")) { |
||||
text = text.Replace(" ", " "); |
||||
} |
||||
return text; |
||||
} |
||||
|
||||
void TestTypeMember(string program) |
||||
{ |
||||
TestProgram("Class A\n" + program + "\nEnd Class"); |
||||
} |
||||
|
||||
void TestStatement(string statement) |
||||
{ |
||||
TestTypeMember("Sub Method()\n" + statement + "\nEnd Sub"); |
||||
} |
||||
|
||||
void TestExpression(string expression) |
||||
{ |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(expression)); |
||||
Expression e = parser.ParseExpression(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); |
||||
e.AcceptVisitor(outputVisitor, null); |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text)); |
||||
} |
||||
|
||||
[Test] |
||||
public void Field() |
||||
{ |
||||
TestTypeMember("Private a As Integer"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Method() |
||||
{ |
||||
TestTypeMember("Sub Method()\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumWithBaseType() |
||||
{ |
||||
TestProgram("Public Enum Foo As UShort\nEnd Enum"); |
||||
} |
||||
|
||||
[Test] |
||||
public void PartialModifier() |
||||
{ |
||||
TestProgram("Public Partial Class Foo\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MustInheritClass() |
||||
{ |
||||
TestProgram("Public MustInherit Class Foo\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericClassDefinition() |
||||
{ |
||||
TestProgram("Public Class Foo(Of T As {IDisposable, ICloneable})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericClassDefinitionWithBaseType() |
||||
{ |
||||
TestProgram("Public Class Foo(Of T As IDisposable)\nInherits BaseType\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodDefinition() |
||||
{ |
||||
TestTypeMember("Public Sub Foo(Of T As {IDisposable, ICloneable})(ByVal arg As T)\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayRank() |
||||
{ |
||||
TestStatement("Dim a As Object(,,)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayInitialization() |
||||
{ |
||||
TestStatement("Dim a As Object() = New Object(10) {}"); |
||||
TestTypeMember("Private MultiDim As Integer(,) = {{1, 2}, {1, 3}}"); |
||||
TestExpression("New Integer(, ) {{1, 1}, {1, 1}}"); |
||||
TestTypeMember("Private _titles As String() = New String() {}"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodCallWithOptionalArguments() |
||||
{ |
||||
TestExpression("M(, )"); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfStatement() |
||||
{ |
||||
TestStatement("If a Then\n" + |
||||
"\tm1()\n" + |
||||
"ElseIf b Then\n" + |
||||
"\tm2()\n" + |
||||
"Else\n" + |
||||
"\tm3()\n" + |
||||
"End If"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForNextLoop() |
||||
{ |
||||
TestStatement("For i = 0 To 10\n" + |
||||
"Next"); |
||||
TestStatement("For i As Long = 10 To 0 Step -1\n" + |
||||
"Next"); |
||||
} |
||||
|
||||
[Test] |
||||
public void DoLoop() |
||||
{ |
||||
TestStatement("Do\n" + |
||||
"Loop"); |
||||
TestStatement("Do\n" + |
||||
"Loop While Not (i = 10)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectCase() |
||||
{ |
||||
TestStatement(@"Select Case i
|
||||
Case 0 |
||||
Case 1 To 4 |
||||
Case Else |
||||
End Select");
|
||||
} |
||||
|
||||
[Test] |
||||
public void UsingStatement() |
||||
{ |
||||
TestStatement(@"Using nf As New Font(), nf2 As New List(Of Font)(), nf3 = Nothing
|
||||
Bla(nf) |
||||
End Using");
|
||||
} |
||||
|
||||
[Test] |
||||
public void UntypedVariable() |
||||
{ |
||||
TestStatement("Dim x = 0"); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntypedField() |
||||
{ |
||||
TestTypeMember("Dim x = 0"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Assignment() |
||||
{ |
||||
TestExpression("a = b"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SpecialIdentifiers() |
||||
{ |
||||
// Assembly, Ansi and Until are contextual keywords
|
||||
// Custom is valid inside methods, but not valid for field names
|
||||
TestExpression("Assembly = Ansi * [For] + Until - [Custom]"); |
||||
} |
||||
|
||||
[Test] |
||||
public void DictionaryAccess() |
||||
{ |
||||
TestExpression("c!key"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodInvocation() |
||||
{ |
||||
TestExpression("GenericMethod(Of T)(arg)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SpecialIdentifierName() |
||||
{ |
||||
TestExpression("[Class]"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericDelegate() |
||||
{ |
||||
TestProgram("Public Delegate Function Predicate(Of T)(ByVal item As T) As String"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Enum() |
||||
{ |
||||
TestProgram("Enum MyTest\nRed\n Green\n Blue\nYellow\n End Enum"); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumWithInitializers() |
||||
{ |
||||
TestProgram("Enum MyTest\nRed = 1\n Green = 2\n Blue = 4\n Yellow = 8\n End Enum"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SyncLock() |
||||
{ |
||||
TestStatement("SyncLock a\nWork()\nEnd SyncLock"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Using() |
||||
{ |
||||
TestStatement("Using a As New A()\na.Work()\nEnd Using"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Cast() |
||||
{ |
||||
TestExpression("CType(a, T)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void DirectCast() |
||||
{ |
||||
TestExpression("DirectCast(a, T)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TryCast() |
||||
{ |
||||
TestExpression("TryCast(a, T)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void PrimitiveCast() |
||||
{ |
||||
TestExpression("CStr(a)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeOfIs() |
||||
{ |
||||
TestExpression("TypeOf a Is String"); |
||||
} |
||||
|
||||
[Test] |
||||
public void PropertyWithAccessorAccessModifiers() |
||||
{ |
||||
TestTypeMember("Public Property ExpectsValue() As Boolean\n" + |
||||
"\tPublic Get\n" + |
||||
"\tEnd Get\n" + |
||||
"\tProtected Set\n" + |
||||
"\tEnd Set\n" + |
||||
"End Property"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AutoProperty() |
||||
{ |
||||
TestTypeMember("Public Property Value()"); |
||||
TestTypeMember("Public Property Value() As Integer"); |
||||
TestTypeMember("Public Property Value() As Integer = 5"); |
||||
TestTypeMember("Public Property Value() As New List()"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AbstractProperty() |
||||
{ |
||||
TestTypeMember("Public MustOverride Property ExpectsValue() As Boolean"); |
||||
TestTypeMember("Public MustOverride ReadOnly Property ExpectsValue() As Boolean"); |
||||
TestTypeMember("Public MustOverride WriteOnly Property ExpectsValue() As Boolean"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AbstractMethod() |
||||
{ |
||||
TestTypeMember("Public MustOverride Sub Run()"); |
||||
TestTypeMember("Public MustOverride Function Run() As Boolean"); |
||||
} |
||||
|
||||
[Test] |
||||
public void InterfaceImplementingMethod() |
||||
{ |
||||
TestTypeMember("Public Sub Run() Implements SomeInterface.Run\nEnd Sub"); |
||||
TestTypeMember("Public Function Run() As Boolean Implements SomeInterface.Bla\nEnd Function"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamedAttributeArgument() |
||||
{ |
||||
TestProgram("<Attribute(ArgName := \"value\")> _\n" + |
||||
"Class Test\n" + |
||||
"End Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReturnTypeAttribute() |
||||
{ |
||||
TestTypeMember("Function A() As <Attribute> String\n" + |
||||
"End Function"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AssemblyAttribute() |
||||
{ |
||||
TestProgram("<Assembly: CLSCompliant>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ModuleAttribute() |
||||
{ |
||||
TestProgram("<Module: SuppressMessageAttribute>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Interface() |
||||
{ |
||||
TestProgram("Interface ITest\n" + |
||||
"Property GetterAndSetter() As Boolean\n" + |
||||
"ReadOnly Property GetterOnly() As Boolean\n" + |
||||
"WriteOnly Property SetterOnly() As Boolean\n" + |
||||
"Sub InterfaceMethod()\n" + |
||||
"Function InterfaceMethod2() As String\n" + |
||||
"End Interface"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnErrorStatement() |
||||
{ |
||||
TestStatement("On Error Resume Next"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverloadedConversionOperators() |
||||
{ |
||||
TestTypeMember("Public Shared Narrowing Operator CType(ByVal xmlNode As XmlNode) As TheBug\nEnd Operator"); |
||||
TestTypeMember("Public Shared Widening Operator CType(ByVal bugNode As TheBug) As XmlNode\nEnd Operator"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverloadedTrueFalseOperators() |
||||
{ |
||||
TestTypeMember("Public Shared Operator IsTrue(ByVal a As TheBug) As Boolean\nEnd Operator"); |
||||
TestTypeMember("Public Shared Operator IsFalse(ByVal a As TheBug) As Boolean\nEnd Operator"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverloadedOperators() |
||||
{ |
||||
TestTypeMember("Public Shared Operator +(ByVal bugNode As TheBug, ByVal bugNode2 As TheBug) As TheBug\nEnd Operator"); |
||||
TestTypeMember("Public Shared Operator >>(ByVal bugNode As TheBug, ByVal b As Integer) As TheBug\nEnd Operator"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeOnParameter() |
||||
{ |
||||
TestTypeMember("Sub Main(ByRef one As Integer, ByRef two As Integer, <Out> ByRef three As Integer)\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FieldWithoutType() |
||||
{ |
||||
TestTypeMember("Dim X"); |
||||
} |
||||
|
||||
[Test] |
||||
public void UsingStatementForExistingVariable() |
||||
{ |
||||
TestStatement("Using obj\nEnd Using"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContinueFor() |
||||
{ |
||||
TestStatement("Continue For"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForNextStatementWithFieldLoopVariable() |
||||
{ |
||||
TestStatement("For Me.Field = 0 To 10\n" + |
||||
"Next Me.Field"); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithStatement() |
||||
{ |
||||
TestStatement("With Ejes\n" + |
||||
"\t.AddLine(New Point(Me.ClientSize.Width / 2, 0), (New Point(Me.ClientSize.Width / 2, Me.ClientSize.Height)))\n" + |
||||
"End With"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewConstraint() |
||||
{ |
||||
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), New})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void StructConstraint() |
||||
{ |
||||
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), Structure})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassConstraint() |
||||
{ |
||||
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), Class})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Integer() |
||||
{ |
||||
TestExpression("16"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Double() |
||||
{ |
||||
TestExpression("1.0"); |
||||
} |
||||
|
||||
[Test] |
||||
public void HexadecimalInteger() |
||||
{ |
||||
TestExpression("&H10"); |
||||
} |
||||
|
||||
[Test] |
||||
public void HexadecimalMinusOne() |
||||
{ |
||||
TestExpression("&Hffffffff"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeCharacters() |
||||
{ |
||||
TestExpression("347S"); |
||||
TestExpression("347L"); |
||||
TestExpression("347D"); |
||||
TestExpression("347F"); |
||||
TestExpression("347US"); |
||||
TestExpression("347UI"); |
||||
TestExpression("347UL"); |
||||
TestExpression("\".\"C"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddressOf() |
||||
{ |
||||
TestExpression("AddressOf Abc"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ChainedConstructorCall() |
||||
{ |
||||
TestExpression("MyBase.New()"); |
||||
TestExpression("Me.New()"); |
||||
TestExpression("MyClass.New()"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewMethodCall() |
||||
{ |
||||
TestExpression("something.[New]()"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ObjectInitializer() |
||||
{ |
||||
TestExpression("New StringWriter() With { _\n" + |
||||
" .NewLine = Environment.NewLine, _\n" + |
||||
" .Encoding = Encoding.UTF8 _\n" + |
||||
"}"); |
||||
} |
||||
|
||||
[Test] |
||||
public void EventDefinition() |
||||
{ |
||||
TestTypeMember("Public Event MyEvent(ByVal sender As Object)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Options() |
||||
{ |
||||
TestProgram("Option Strict On\n" + |
||||
"Option Explicit On\n" + |
||||
"Option Infer On\n" + |
||||
"Option Compare Text"); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntypedForeach() |
||||
{ |
||||
TestStatement("For Each x In myGuidArray\nNext"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodDefinitionWithOptionalParameter() |
||||
{ |
||||
TestTypeMember("Sub M(Optional ByVal msg As String = Nothing, Optional ByRef output As String = Nothing)\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Module() |
||||
{ |
||||
TestProgram("Module Test\n" + |
||||
" Sub M()\n" + |
||||
" End Sub\n" + |
||||
"End Module"); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithEvents() |
||||
{ |
||||
TestTypeMember("Dim WithEvents a As Button"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FriendWithEventsField() |
||||
{ |
||||
TestTypeMember("Friend WithEvents Button1 As System.Windows.Forms.Button"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleFunctionLambda() |
||||
{ |
||||
TestExpression("Function(x) x * x"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleFunctionLambdaWithType() |
||||
{ |
||||
TestExpression("Function(x As Integer) x * x"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleSubLambdaWithType() |
||||
{ |
||||
TestExpression("Sub(x As Integer) Console.WriteLine(x)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void BlockSubLambdaWithType() |
||||
{ |
||||
TestExpression("Sub(x As Integer)\n" + |
||||
" Console.WriteLine(x)\n" + |
||||
"End Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void BlockFunctionLambdaWithType() |
||||
{ |
||||
TestExpression("Function(x As Integer) As Integer\n" + |
||||
" If x < 2 Then\n" + |
||||
" Return x\n" + |
||||
" End If\n" + |
||||
" Return x * x\n" + |
||||
"End Function"); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlSimple() |
||||
{ |
||||
TestExpression("<?xml?>\n" + |
||||
"<!-- test -->\n" + |
||||
"<Test>\n" + |
||||
" <A />\n" + |
||||
" <B test='a' <%= test %> />\n" + |
||||
"</Test>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlNested() |
||||
{ |
||||
TestExpression(@"<menu>
|
||||
<course name=""appetizer""> |
||||
<dish>Shrimp Cocktail</dish> |
||||
<dish>Escargot</dish> |
||||
</course> |
||||
<course name=""main""> |
||||
<dish>Filet Mignon</dish> |
||||
<dish>Garlic Potatoes</dish> |
||||
<dish>Broccoli</dish> |
||||
</course> |
||||
<course name=""dessert""> |
||||
<dish>Chocolate Cheesecake</dish> |
||||
</course> |
||||
</menu>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void XmlDocument() |
||||
{ |
||||
TestExpression(@"<?xml version=""1.0""?>
|
||||
<menu> |
||||
<course name=""appetizer""> |
||||
<dish>Shrimp Cocktail</dish> |
||||
<dish>Escargot</dish> |
||||
</course> |
||||
</menu>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void XmlNestedWithExpressions() |
||||
{ |
||||
TestExpression(@"<?xml version=""1.0""?>
|
||||
<menu> |
||||
<course name=""appetizer""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""appetizer"" _ |
||||
Select <dish><%= m.Food %></dish> %> |
||||
</course> |
||||
<course name=""main""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""main"" _ |
||||
Select <dish><%= m.Food %></dish> %> |
||||
</course> |
||||
<course name=""dessert""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""dessert"" _ |
||||
Select <dish><%= m.Food %></dish> %> |
||||
</course> |
||||
</menu>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void XmlAccessExpressions() |
||||
{ |
||||
TestExpression("xml.<menu>.<course>"); |
||||
TestExpression("xml...<course>"); |
||||
TestExpression("xml...<course>(2)"); |
||||
TestExpression("item.@name"); |
||||
} |
||||
} |
||||
} |
||||
@ -1,45 +0,0 @@
@@ -1,45 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class AddressOfExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleAddressOfExpressionTest() |
||||
{ |
||||
AddressOfExpression ae = ParseUtil.ParseExpression<AddressOfExpression>("AddressOf t"); |
||||
Assert.IsNotNull(ae); |
||||
Assert.IsInstanceOf(typeof(IdentifierExpression), ae.Expression); |
||||
Assert.AreEqual("t", ((IdentifierExpression)ae.Expression).Identifier, "t"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericAddressOfExpressionTest() |
||||
{ |
||||
AddressOfExpression ae = ParseUtil.ParseExpression<AddressOfExpression>("AddressOf t(Of X)"); |
||||
Assert.IsNotNull(ae); |
||||
Assert.IsInstanceOf(typeof(IdentifierExpression), ae.Expression); |
||||
Assert.AreEqual("t", ((IdentifierExpression)ae.Expression).Identifier, "t"); |
||||
Assert.AreEqual(1, ((IdentifierExpression)ae.Expression).TypeArguments.Count); |
||||
Assert.AreEqual("X", ((IdentifierExpression)ae.Expression).TypeArguments[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberReferenceAddressOfExpressionTest() |
||||
{ |
||||
AddressOfExpression ae = ParseUtil.ParseExpression<AddressOfExpression>("AddressOf Me.t(Of X)"); |
||||
Assert.IsNotNull(ae); |
||||
Assert.IsInstanceOf(typeof(MemberReferenceExpression), ae.Expression); |
||||
Assert.AreEqual("t", ((MemberReferenceExpression)ae.Expression).MemberName, "t"); |
||||
Assert.IsInstanceOf(typeof(ThisReferenceExpression), ((MemberReferenceExpression)ae.Expression).TargetObject); |
||||
} |
||||
} |
||||
} |
||||
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ArrayCreateExpressionTests |
||||
{ |
||||
[Test] |
||||
public void ArrayCreateExpressionTest1() |
||||
{ |
||||
ArrayCreateExpression ace = ParseUtil.ParseExpression<ArrayCreateExpression>("new Integer() {1, 2, 3, 4}"); |
||||
|
||||
Assert.AreEqual("System.Int32", ace.CreateType.Type); |
||||
Assert.AreEqual(0, ace.Arguments.Count); |
||||
Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayCreateExpressionTest2() |
||||
{ |
||||
ArrayCreateExpression ace = ParseUtil.ParseExpression<ArrayCreateExpression>("New Integer(0 To 5){0, 1, 2, 3, 4, 5}"); |
||||
|
||||
Assert.AreEqual("System.Int32", ace.CreateType.Type); |
||||
Assert.AreEqual(1, ace.Arguments.Count); |
||||
Assert.AreEqual(5, (ace.Arguments[0] as PrimitiveExpression).Value); |
||||
Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier); |
||||
} |
||||
} |
||||
} |
||||
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class AssignmentExpressionTests |
||||
{ |
||||
void TestAssignmentExpression(string program, AssignmentOperatorType op) |
||||
{ |
||||
ExpressionStatement se = ParseUtil.ParseStatement<ExpressionStatement>(program); |
||||
AssignmentExpression ae = se.Expression as AssignmentExpression; |
||||
Assert.AreEqual(op, ae.Op); |
||||
|
||||
Assert.IsTrue(ae.Left is IdentifierExpression); |
||||
Assert.IsTrue(ae.Right is IdentifierExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void AssignTest() |
||||
{ |
||||
TestAssignmentExpression("a = b", AssignmentOperatorType.Assign); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddTest() |
||||
{ |
||||
TestAssignmentExpression("a += b", AssignmentOperatorType.Add); |
||||
} |
||||
|
||||
[Test] |
||||
public void SubtractTest() |
||||
{ |
||||
TestAssignmentExpression("a -= b", AssignmentOperatorType.Subtract); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultiplyTest() |
||||
{ |
||||
TestAssignmentExpression("a *= b", AssignmentOperatorType.Multiply); |
||||
} |
||||
|
||||
[Test] |
||||
public void DivideTest() |
||||
{ |
||||
TestAssignmentExpression("a /= b", AssignmentOperatorType.Divide); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclusiveOrTest() |
||||
{ |
||||
TestAssignmentExpression("a ^= b", AssignmentOperatorType.Power); |
||||
} |
||||
|
||||
[Test] |
||||
public void StringConcatTest() |
||||
{ |
||||
TestAssignmentExpression("a &= b", AssignmentOperatorType.ConcatString); |
||||
} |
||||
|
||||
[Test] |
||||
public void ModulusTest() |
||||
{ |
||||
TestAssignmentExpression("a \\= b", AssignmentOperatorType.DivideInteger); |
||||
} |
||||
} |
||||
} |
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class BaseReferenceExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetBaseReferenceExpressionTest1() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("MyBase.myField"); |
||||
Assert.IsTrue(fre.TargetObject is BaseReferenceExpression); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,268 +0,0 @@
@@ -1,268 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class BinaryOperatorExpressionTests |
||||
{ |
||||
void OperatorPrecedenceTest(string strongOperator, BinaryOperatorType strongOperatorType, |
||||
string weakOperator, BinaryOperatorType weakOperatorType) |
||||
{ |
||||
string program = "a " + weakOperator + " b " + strongOperator + " c"; |
||||
BinaryOperatorExpression boe; |
||||
boe = ParseUtil.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(weakOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
boe = (BinaryOperatorExpression)boe.Right; |
||||
Assert.AreEqual(strongOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
|
||||
program = "a " + strongOperator + " b " + weakOperator + " c"; |
||||
boe = ParseUtil.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(weakOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
boe = (BinaryOperatorExpression)boe.Left; |
||||
Assert.AreEqual(strongOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
} |
||||
|
||||
void SameOperatorPrecedenceTest(string firstOperator, BinaryOperatorType firstOperatorType, |
||||
string secondOperator, BinaryOperatorType secondOperatorType) |
||||
{ |
||||
string program = "a " + secondOperator + " b " + firstOperator + " c"; |
||||
BinaryOperatorExpression boe; |
||||
boe = ParseUtil.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(firstOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
boe = (BinaryOperatorExpression)boe.Left; |
||||
Assert.AreEqual(secondOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
|
||||
program = "a " + firstOperator + " b " + secondOperator + " c"; |
||||
boe = ParseUtil.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(secondOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
boe = (BinaryOperatorExpression)boe.Left; |
||||
Assert.AreEqual(firstOperatorType, boe.Op); |
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
} |
||||
|
||||
#region VB.NET
|
||||
void VBNetTestBinaryOperatorExpressionTest(string program, BinaryOperatorType op) |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtil.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(op, boe.Op); |
||||
|
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
Assert.IsTrue(boe.Right is SimpleNameExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBOperatorPrecedenceTest() |
||||
{ |
||||
OperatorPrecedenceTest("^", BinaryOperatorType.Power, "*", BinaryOperatorType.Multiply); |
||||
SameOperatorPrecedenceTest("*", BinaryOperatorType.Multiply, "/", BinaryOperatorType.Divide); |
||||
OperatorPrecedenceTest("/", BinaryOperatorType.Divide, "\\", BinaryOperatorType.DivideInteger); |
||||
OperatorPrecedenceTest("\\", BinaryOperatorType.DivideInteger, "Mod", BinaryOperatorType.Modulus); |
||||
OperatorPrecedenceTest("Mod", BinaryOperatorType.Modulus, "+", BinaryOperatorType.Add); |
||||
SameOperatorPrecedenceTest("+", BinaryOperatorType.Add, "-", BinaryOperatorType.Subtract); |
||||
OperatorPrecedenceTest("-", BinaryOperatorType.Subtract, "&", BinaryOperatorType.Concat); |
||||
OperatorPrecedenceTest("&", BinaryOperatorType.Concat, "<<", BinaryOperatorType.ShiftLeft); |
||||
SameOperatorPrecedenceTest("<<", BinaryOperatorType.ShiftLeft, ">>", BinaryOperatorType.ShiftRight); |
||||
OperatorPrecedenceTest("<<", BinaryOperatorType.ShiftLeft, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest("<>", BinaryOperatorType.InEquality, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest("<", BinaryOperatorType.LessThan, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest("<=", BinaryOperatorType.LessThanOrEqual, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest(">", BinaryOperatorType.GreaterThan, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest(">=", BinaryOperatorType.GreaterThanOrEqual, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest("Like", BinaryOperatorType.Like, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest("Is", BinaryOperatorType.ReferenceEquality, "=", BinaryOperatorType.Equality); |
||||
SameOperatorPrecedenceTest("IsNot", BinaryOperatorType.ReferenceInequality, "=", BinaryOperatorType.Equality); |
||||
OperatorPrecedenceTest("=", BinaryOperatorType.Equality, "And", BinaryOperatorType.BitwiseAnd); |
||||
SameOperatorPrecedenceTest("And", BinaryOperatorType.BitwiseAnd, "AndAlso", BinaryOperatorType.LogicalAnd); |
||||
OperatorPrecedenceTest("And", BinaryOperatorType.BitwiseAnd, "Or", BinaryOperatorType.BitwiseOr); |
||||
SameOperatorPrecedenceTest("Or", BinaryOperatorType.BitwiseOr, "OrElse", BinaryOperatorType.LogicalOr); |
||||
SameOperatorPrecedenceTest("Or", BinaryOperatorType.BitwiseOr, "Xor", BinaryOperatorType.ExclusiveOr); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetPowerTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a ^ b", BinaryOperatorType.Power); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetConcatTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a & b", BinaryOperatorType.Concat); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLogicalAndTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a AndAlso b", BinaryOperatorType.LogicalAnd); |
||||
} |
||||
[Test] |
||||
public void VBNetLogicalAndNotLazyTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a And b", BinaryOperatorType.BitwiseAnd); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLogicalOrTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a OrElse b", BinaryOperatorType.LogicalOr); |
||||
} |
||||
[Test] |
||||
public void VBNetLogicalOrNotLazyTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a Or b", BinaryOperatorType.BitwiseOr); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetExclusiveOrTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a Xor b", BinaryOperatorType.ExclusiveOr); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void VBNetGreaterThanTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a > b", BinaryOperatorType.GreaterThan); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGreaterThanOrEqualTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a >= b", BinaryOperatorType.GreaterThanOrEqual); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetEqualityTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a = b", BinaryOperatorType.Equality); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInEqualityTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a <> b", BinaryOperatorType.InEquality); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLessThanTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a < b", BinaryOperatorType.LessThan); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLessThanOrEqualTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a <= b", BinaryOperatorType.LessThanOrEqual); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetAddTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a + b", BinaryOperatorType.Add); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSubtractTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a - b", BinaryOperatorType.Subtract); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMultiplyTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a * b", BinaryOperatorType.Multiply); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetDivideTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a / b", BinaryOperatorType.Divide); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetDivideIntegerTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a \\ b", BinaryOperatorType.DivideInteger); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetModulusTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a Mod b", BinaryOperatorType.Modulus); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetShiftLeftTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a << b", BinaryOperatorType.ShiftLeft); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetShiftRightTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a >> b", BinaryOperatorType.ShiftRight); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetISTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a is b", BinaryOperatorType.ReferenceEquality); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetISNotTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a IsNot b", BinaryOperatorType.ReferenceInequality); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLikeTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("a Like b", BinaryOperatorType.Like); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNullCoalescingTest() |
||||
{ |
||||
VBNetTestBinaryOperatorExpressionTest("If(a, b)", BinaryOperatorType.NullCoalescing); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetDictionaryAccess() |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtil.ParseExpression<BinaryOperatorExpression>("a!b"); |
||||
Assert.AreEqual(BinaryOperatorType.DictionaryAccess, boe.Op); |
||||
Assert.IsTrue(boe.Left is SimpleNameExpression); |
||||
Assert.IsTrue(boe.Right is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetWithDictionaryAccess() |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtil.ParseExpression<BinaryOperatorExpression>("!b"); |
||||
Assert.AreEqual(BinaryOperatorType.DictionaryAccess, boe.Op); |
||||
Assert.IsTrue(boe.Left.IsNull); |
||||
Assert.IsTrue(boe.Right is PrimitiveExpression); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,181 +0,0 @@
@@ -1,181 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class CastExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
void TestSpecializedCast(string castExpression, Type castType) |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>(castExpression); |
||||
Assert.AreEqual(castType.FullName, ce.CastTo.Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.PrimitiveConversion, ce.CastType); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void VBNetSimpleCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>("CType(o, MyObject)"); |
||||
Assert.AreEqual("MyObject", ce.CastTo.Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.Conversion, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>("CType(o, List(of T))"); |
||||
Assert.AreEqual("List", ce.CastTo.Type); |
||||
Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.Conversion, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleDirectCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>("DirectCast(o, MyObject)"); |
||||
Assert.AreEqual("MyObject", ce.CastTo.Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericDirectCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>("DirectCast(o, List(of T))"); |
||||
Assert.AreEqual("List", ce.CastTo.Type); |
||||
Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleTryCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>("TryCast(o, MyObject)"); |
||||
Assert.AreEqual("MyObject", ce.CastTo.Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.TryCast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericTryCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtil.ParseExpression<CastExpression>("TryCast(o, List(of T))"); |
||||
Assert.AreEqual("List", ce.CastTo.Type); |
||||
Assert.AreEqual("T", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
Assert.AreEqual(CastType.TryCast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedBoolCastExpression() |
||||
{ |
||||
TestSpecializedCast("CBool(o)", typeof(System.Boolean)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedCharCastExpression() |
||||
{ |
||||
TestSpecializedCast("CChar(o)", typeof(System.Char)); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void VBNetSpecializedStringCastExpression() |
||||
{ |
||||
TestSpecializedCast("CStr(o)", typeof(System.String)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedDateTimeCastExpression() |
||||
{ |
||||
TestSpecializedCast("CDate(o)", typeof(System.DateTime)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedDecimalCastExpression() |
||||
{ |
||||
TestSpecializedCast("CDec(o)", typeof(System.Decimal)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedSingleCastExpression() |
||||
{ |
||||
TestSpecializedCast("CSng(o)", typeof(System.Single)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedDoubleCastExpression() |
||||
{ |
||||
TestSpecializedCast("CDbl(o)", typeof(System.Double)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedByteCastExpression() |
||||
{ |
||||
TestSpecializedCast("CByte(o)", typeof(System.Byte)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedInt16CastExpression() |
||||
{ |
||||
TestSpecializedCast("CShort(o)", typeof(System.Int16)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedInt32CastExpression() |
||||
{ |
||||
TestSpecializedCast("CInt(o)", typeof(System.Int32)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedInt64CastExpression() |
||||
{ |
||||
TestSpecializedCast("CLng(o)", typeof(System.Int64)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedSByteCastExpression() |
||||
{ |
||||
TestSpecializedCast("CSByte(o)", typeof(System.SByte)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedUInt16CastExpression() |
||||
{ |
||||
TestSpecializedCast("CUShort(o)", typeof(System.UInt16)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedUInt32CastExpression() |
||||
{ |
||||
TestSpecializedCast("CUInt(o)", typeof(System.UInt32)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSpecializedUInt64CastExpression() |
||||
{ |
||||
TestSpecializedCast("CULng(o)", typeof(System.UInt64)); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void VBNetSpecializedObjectCastExpression() |
||||
{ |
||||
TestSpecializedCast("CObj(o)", typeof(System.Object)); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ClassReferenceExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetClassReferenceExpressionTest1() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("MyClass.myField"); |
||||
Assert.IsTrue(fre.TargetObject is ClassReferenceExpression); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,29 +0,0 @@
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ConditionalExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
|
||||
[Test] |
||||
public void VBNetConditionalExpressionTest() |
||||
{ |
||||
ConditionalExpression ce = ParseUtil.ParseExpression<ConditionalExpression>("If(x IsNot Nothing, x.Test, \"nothing\")"); |
||||
|
||||
Assert.IsTrue(ce.Condition is BinaryOperatorExpression); |
||||
Assert.IsTrue(ce.TrueExpression is MemberReferenceExpression); |
||||
Assert.IsTrue(ce.FalseExpression is PrimitiveExpression); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class GlobalReferenceExpressionTests |
||||
{ |
||||
[Test] |
||||
public void VBNetGlobalReferenceExpressionTest() |
||||
{ |
||||
TypeReferenceExpression tre = ParseUtil.ParseExpression<TypeReferenceExpression>("Global.System"); |
||||
Assert.IsTrue(tre.TypeReference.IsGlobal); |
||||
Assert.AreEqual("System", tre.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGlobalTypeDeclaration() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As Global.System.String"); |
||||
TypeReference typeRef = lvd.GetTypeForVariable(0); |
||||
Assert.IsTrue(typeRef.IsGlobal); |
||||
Assert.AreEqual("System.String", typeRef.Type); |
||||
} |
||||
} |
||||
} |
||||
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class IdentifierExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetIdentifierExpressionTest1() |
||||
{ |
||||
IdentifierExpression ie = ParseUtil.ParseExpression<IdentifierExpression>("MyIdentifier"); |
||||
Assert.AreEqual("MyIdentifier", ie.Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetIdentifierExpressionTest2() |
||||
{ |
||||
IdentifierExpression ie = ParseUtil.ParseExpression<IdentifierExpression>("[Public]"); |
||||
Assert.AreEqual("Public", ie.Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetContextKeywordsTest() |
||||
{ |
||||
Assert.AreEqual("Assembly", ParseUtil.ParseExpression<IdentifierExpression>("Assembly").Identifier); |
||||
Assert.AreEqual("Custom", ParseUtil.ParseExpression<IdentifierExpression>("Custom").Identifier); |
||||
Assert.AreEqual("Off", ParseUtil.ParseExpression<IdentifierExpression>("Off").Identifier); |
||||
Assert.AreEqual("Explicit", ParseUtil.ParseExpression<IdentifierExpression>("Explicit").Identifier); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,116 +0,0 @@
@@ -1,116 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class InvocationExpressionTests |
||||
{ |
||||
void CheckSimpleInvoke(InvocationExpression ie) |
||||
{ |
||||
Assert.AreEqual(0, ie.Arguments.Count); |
||||
Assert.IsTrue(ie.TargetObject is SimpleNameExpression); |
||||
Assert.AreEqual("myMethod", ((SimpleNameExpression)ie.TargetObject).Identifier); |
||||
} |
||||
|
||||
void CheckGenericInvoke(InvocationExpression expr) |
||||
{ |
||||
Assert.AreEqual(1, expr.Arguments.Count); |
||||
Assert.IsTrue(expr.TargetObject is SimpleNameExpression); |
||||
SimpleNameExpression ident = (SimpleNameExpression)expr.TargetObject; |
||||
Assert.AreEqual("myMethod", ident.Identifier); |
||||
Assert.AreEqual(1, ident.TypeArguments.Count); |
||||
Assert.AreEqual("System.Char", ident.TypeArguments[0].Type); |
||||
} |
||||
|
||||
void CheckGenericInvoke2(InvocationExpression expr) |
||||
{ |
||||
Assert.AreEqual(0, expr.Arguments.Count); |
||||
Assert.IsTrue(expr.TargetObject is SimpleNameExpression); |
||||
SimpleNameExpression ident = (SimpleNameExpression)expr.TargetObject; |
||||
Assert.AreEqual("myMethod", ident.Identifier); |
||||
Assert.AreEqual(2, ident.TypeArguments.Count); |
||||
Assert.AreEqual("T", ident.TypeArguments[0].Type); |
||||
Assert.IsFalse(ident.TypeArguments[0].IsKeyword); |
||||
Assert.AreEqual("System.Boolean", ident.TypeArguments[1].Type); |
||||
Assert.IsTrue(ident.TypeArguments[1].IsKeyword); |
||||
} |
||||
|
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleInvocationExpressionTest() |
||||
{ |
||||
CheckSimpleInvoke(ParseUtil.ParseExpression<InvocationExpression>("myMethod()")); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericInvocationExpressionTest() |
||||
{ |
||||
CheckGenericInvoke(ParseUtil.ParseExpression<InvocationExpression>("myMethod(Of Char)(\"a\"c)")); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericInvocation2ExpressionTest() |
||||
{ |
||||
CheckGenericInvoke2(ParseUtil.ParseExpression<InvocationExpression>("myMethod(Of T, Boolean)()")); |
||||
} |
||||
|
||||
[Test] |
||||
public void PrimitiveExpression1Test() |
||||
{ |
||||
InvocationExpression ie = ParseUtil.ParseExpression<InvocationExpression>("546.ToString()"); |
||||
Assert.AreEqual(0, ie.Arguments.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBInvocationOnGenericType() |
||||
{ |
||||
InvocationExpression expr = ParseUtil.ParseExpression<InvocationExpression>("A(Of T).Foo()"); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual("Foo", mre.MemberName); |
||||
SimpleNameExpression tre = (SimpleNameExpression)mre.TargetObject; |
||||
Assert.AreEqual("A", tre.Identifier); |
||||
Assert.AreEqual("T", tre.TypeArguments[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBInvocationOnInnerClassInGenericType() |
||||
{ |
||||
InvocationExpression expr = ParseUtil.ParseExpression<InvocationExpression>("A(Of T).B.Foo()"); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual("Foo", mre.MemberName); |
||||
MemberReferenceExpression mre2 = (MemberReferenceExpression)mre.TargetObject; |
||||
Assert.AreEqual("B", mre2.MemberName); |
||||
SimpleNameExpression tre = (SimpleNameExpression)mre2.TargetObject; |
||||
Assert.AreEqual("A", tre.Identifier); |
||||
Assert.AreEqual("T", tre.TypeArguments[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBInvocationOnGenericInnerClassInGenericType() |
||||
{ |
||||
InvocationExpression expr = ParseUtil.ParseExpression<InvocationExpression>("A(Of T).B.C(Of U).Foo()"); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual("Foo", mre.MemberName); |
||||
|
||||
MemberReferenceExpression mre2 = (MemberReferenceExpression)mre.TargetObject; |
||||
Assert.AreEqual("C", mre2.MemberName); |
||||
Assert.AreEqual("U", mre2.TypeArguments[0].Type); |
||||
|
||||
MemberReferenceExpression mre3 = (MemberReferenceExpression)mre2.TargetObject; |
||||
Assert.AreEqual("B", mre3.MemberName); |
||||
|
||||
SimpleNameExpression tre = (SimpleNameExpression)mre3.TargetObject; |
||||
Assert.AreEqual("A", tre.Identifier); |
||||
Assert.AreEqual("T", tre.TypeArguments[0].Type); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,137 +0,0 @@
@@ -1,137 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class LambdaExpressionTests |
||||
{ |
||||
static LambdaExpression Parse(string program) |
||||
{ |
||||
return ParseUtil.ParseExpression<LambdaExpression>(program); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaWithParameters() |
||||
{ |
||||
LambdaExpression e = Parse("Function(x As Boolean) x Or True"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.AreEqual("System.Boolean", e.Parameters[0].TypeReference.Type); |
||||
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaWithoutParameters() |
||||
{ |
||||
LambdaExpression e = Parse("Function() x Or True"); |
||||
Assert.AreEqual(0, e.Parameters.Count); |
||||
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); |
||||
Assert.IsTrue(e.ReturnType.IsNull, "ReturnType"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedLambda() |
||||
{ |
||||
LambdaExpression e = Parse("Function(x As Boolean) Function(y As Boolean) x And y"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.IsTrue(e.ExpressionBody is LambdaExpression); |
||||
Assert.IsTrue(e.ReturnType.IsNull, "ReturnType"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SubLambda() |
||||
{ |
||||
LambdaExpression e = Parse("Sub(x As Integer) Console.WriteLine(x)"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.IsTrue(e.StatementBody is ExpressionStatement); |
||||
Assert.IsNotNull(e.ReturnType); |
||||
Assert.AreEqual("System.Void", e.ReturnType.Type); |
||||
Assert.IsTrue(e.ReturnType.IsKeyword); |
||||
} |
||||
|
||||
[Test] |
||||
public void SubWithStatementLambda() |
||||
{ |
||||
LambdaExpression e = Parse("Sub(x As Integer) Call Console.WriteLine(x)"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.IsTrue(e.StatementBody is ExpressionStatement); |
||||
Assert.IsNotNull(e.ReturnType); |
||||
Assert.AreEqual("System.Void", e.ReturnType.Type); |
||||
Assert.IsTrue(e.ReturnType.IsKeyword); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultilineSubLambda() |
||||
{ |
||||
LambdaExpression e = Parse("Sub(x As Integer)\n" + |
||||
" For i As Integer = 0 To x\n" + |
||||
" Console.WriteLine(i)\n" + |
||||
" Next\n" + |
||||
"End Sub"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.IsTrue(e.StatementBody is BlockStatement); |
||||
Assert.IsNotNull(e.ReturnType); |
||||
Assert.AreEqual("System.Void", e.ReturnType.Type); |
||||
Assert.IsTrue(e.ReturnType.IsKeyword); |
||||
|
||||
BlockStatement b = e.StatementBody as BlockStatement; |
||||
|
||||
Assert.AreEqual(1, b.Children.Count); |
||||
Assert.IsTrue(b.Children[0] is ForNextStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultilineFunctionLambda() |
||||
{ |
||||
LambdaExpression e = Parse("Function(x As Integer)\n" + |
||||
" Dim prod As Integer = 1\n" + |
||||
" For i As Integer = 1 To x\n" + |
||||
" prod = prod * i\n" + |
||||
" Next\n" + |
||||
" Return prod\n" + |
||||
"End Function"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.IsTrue(e.StatementBody is BlockStatement); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
|
||||
BlockStatement b = e.StatementBody as BlockStatement; |
||||
|
||||
Assert.AreEqual(3, b.Children.Count); |
||||
Assert.IsTrue(b.Children[0] is LocalVariableDeclaration); |
||||
Assert.IsTrue(b.Children[1] is ForNextStatement); |
||||
Assert.IsTrue(b.Children[2] is ReturnStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultilineFunctionWithReturnTypeLambda() |
||||
{ |
||||
LambdaExpression e = Parse("Function(x As Integer) As Integer\n" + |
||||
" Dim prod As Integer = 1\n" + |
||||
" For i As Integer = 1 To x\n" + |
||||
" prod = prod * i\n" + |
||||
" Next\n" + |
||||
" Return prod\n" + |
||||
"End Function"); |
||||
Assert.AreEqual(1, e.Parameters.Count); |
||||
Assert.IsTrue(e.StatementBody is BlockStatement); |
||||
Assert.IsNotNull(e.ReturnType); |
||||
Assert.AreEqual("System.Int32", e.ReturnType.Type); |
||||
Assert.IsTrue(e.ReturnType.IsKeyword); |
||||
|
||||
BlockStatement b = e.StatementBody as BlockStatement; |
||||
|
||||
Assert.AreEqual(3, b.Children.Count); |
||||
Assert.IsTrue(b.Children[0] is LocalVariableDeclaration); |
||||
Assert.IsTrue(b.Children[1] is ForNextStatement); |
||||
Assert.IsTrue(b.Children[2] is ReturnStatement); |
||||
} |
||||
} |
||||
} |
||||
@ -1,82 +0,0 @@
@@ -1,82 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class MemberReferenceExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("myTargetObject.myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsTrue(fre.TargetObject is SimpleNameExpression); |
||||
Assert.AreEqual("myTargetObject", ((SimpleNameExpression)fre.TargetObject).Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetFieldReferenceExpressionWithoutTargetTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>(".myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsTrue(fre.TargetObject.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("SomeClass(of string).myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsInstanceOf(typeof(SimpleNameExpression), fre.TargetObject); |
||||
TypeReference tr = ((SimpleNameExpression)fre.TargetObject).TypeArguments[0]; |
||||
Assert.AreEqual("System.String", tr.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetFullNamespaceGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("System.Subnamespace.SomeClass(of string).myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsInstanceOf(typeof(MemberReferenceExpression), fre.TargetObject); |
||||
|
||||
MemberReferenceExpression inner = (MemberReferenceExpression)fre.TargetObject; |
||||
Assert.AreEqual("SomeClass", inner.MemberName); |
||||
Assert.AreEqual(1, inner.TypeArguments.Count); |
||||
Assert.AreEqual("System.String", inner.TypeArguments[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGlobalFullNamespaceGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("Global.System.Subnamespace.SomeClass(of string).myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsInstanceOf(typeof(MemberReferenceExpression), fre.TargetObject); |
||||
MemberReferenceExpression inner = (MemberReferenceExpression)fre.TargetObject; |
||||
|
||||
Assert.AreEqual("SomeClass", inner.MemberName); |
||||
Assert.AreEqual(1, inner.TypeArguments.Count); |
||||
Assert.AreEqual("System.String", inner.TypeArguments[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNestedGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("MyType(of string).InnerClass(of integer).myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsInstanceOf(typeof(MemberReferenceExpression), fre.TargetObject); |
||||
|
||||
MemberReferenceExpression inner = (MemberReferenceExpression)fre.TargetObject; |
||||
Assert.AreEqual("InnerClass", inner.MemberName); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,114 +0,0 @@
@@ -1,114 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ObjectCreateExpressionTests |
||||
{ |
||||
void CheckSimpleObjectCreateExpression(ObjectCreateExpression oce) |
||||
{ |
||||
Assert.AreEqual("MyObject", oce.CreateType.Type); |
||||
Assert.AreEqual(3, oce.Parameters.Count); |
||||
Assert.IsTrue(oce.ObjectInitializer.IsNull); |
||||
|
||||
for (int i = 0; i < oce.Parameters.Count; ++i) { |
||||
Assert.IsTrue(oce.Parameters[i] is PrimitiveExpression); |
||||
} |
||||
} |
||||
|
||||
Expression CheckPropertyInitializationExpression(Expression e, string name) |
||||
{ |
||||
Assert.IsInstanceOf(typeof(MemberInitializerExpression), e); |
||||
Assert.AreEqual(name, ((MemberInitializerExpression)e).Name); |
||||
return ((MemberInitializerExpression)e).Expression; |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetAnonymousType() |
||||
{ |
||||
ObjectCreateExpression oce = ParseUtil.ParseExpression<ObjectCreateExpression>( |
||||
"New With {.Id = 1, .Name= \"Bill Gates\" }"); |
||||
|
||||
Assert.IsTrue(oce.CreateType.IsNull); |
||||
Assert.AreEqual(0, oce.Parameters.Count); |
||||
Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count); |
||||
|
||||
Assert.IsInstanceOf(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "Id")); |
||||
Assert.IsInstanceOf(typeof(MemberInitializerExpression), oce.ObjectInitializer.CreateExpressions[1]); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetAnonymousTypeWithoutProperty() |
||||
{ |
||||
ObjectCreateExpression oce = ParseUtil.ParseExpression<ObjectCreateExpression>("New With { c }"); |
||||
|
||||
Assert.IsTrue(oce.CreateType.IsNull); |
||||
Assert.AreEqual(0, oce.Parameters.Count); |
||||
Assert.AreEqual(1, oce.ObjectInitializer.CreateExpressions.Count); |
||||
|
||||
Assert.IsInstanceOf(typeof(SimpleNameExpression), oce.ObjectInitializer.CreateExpressions[0]); |
||||
Assert.AreEqual("c", (oce.ObjectInitializer.CreateExpressions[0] as SimpleNameExpression).Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleObjectCreateExpressionTest() |
||||
{ |
||||
CheckSimpleObjectCreateExpression(ParseUtil.ParseExpression<ObjectCreateExpression>("New MyObject(1, 2, 3)")); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInvalidTypeArgumentListObjectCreateExpressionTest() |
||||
{ |
||||
// this test was written because this bug caused the AbstractDomVisitor to crash
|
||||
|
||||
InvocationExpression expr = ParseUtil.ParseExpression<InvocationExpression>("WriteLine(New SomeGenericType(Of Integer, )())", true); |
||||
Assert.IsTrue(expr.TargetObject is SimpleNameExpression); |
||||
Assert.AreEqual("WriteLine", ((SimpleNameExpression)expr.TargetObject).Identifier); |
||||
Assert.AreEqual(1, expr.Arguments.Count); // here a second null parameter was added incorrectly
|
||||
|
||||
Assert.IsTrue(expr.Arguments[0] is ObjectCreateExpression); |
||||
TypeReference typeRef = ((ObjectCreateExpression)expr.Arguments[0]).CreateType; |
||||
Assert.AreEqual("SomeGenericType", typeRef.Type); |
||||
Assert.AreEqual(1, typeRef.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", typeRef.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMemberInitializationTest() |
||||
{ |
||||
ObjectCreateExpression oce = ParseUtil.ParseExpression<ObjectCreateExpression>("new Contact() With { .FirstName = \"Bill\", .LastName = \"Gates\" }"); |
||||
Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count); |
||||
|
||||
Assert.AreEqual("FirstName", ((MemberInitializerExpression)oce.ObjectInitializer.CreateExpressions[0]).Name); |
||||
Assert.AreEqual("LastName", ((MemberInitializerExpression)oce.ObjectInitializer.CreateExpressions[1]).Name); |
||||
|
||||
Assert.IsInstanceOf(typeof(PrimitiveExpression), ((MemberInitializerExpression)oce.ObjectInitializer.CreateExpressions[0]).Expression); |
||||
Assert.IsInstanceOf(typeof(PrimitiveExpression), ((MemberInitializerExpression)oce.ObjectInitializer.CreateExpressions[1]).Expression); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNullableObjectCreateExpressionTest() |
||||
{ |
||||
ObjectCreateExpression oce = ParseUtil.ParseExpression<ObjectCreateExpression>("New Integer?"); |
||||
Assert.AreEqual("System.Nullable", oce.CreateType.Type); |
||||
Assert.AreEqual(1, oce.CreateType.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", oce.CreateType.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNullableObjectArrayCreateExpressionTest() |
||||
{ |
||||
ObjectCreateExpression oce = ParseUtil.ParseExpression<ObjectCreateExpression>("New Integer?()"); |
||||
Assert.AreEqual("System.Nullable", oce.CreateType.Type); |
||||
Assert.AreEqual(1, oce.CreateType.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", oce.CreateType.GenericTypes[0].Type); |
||||
} |
||||
} |
||||
} |
||||
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ParenthesizedExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetPrimitiveParenthesizedExpression() |
||||
{ |
||||
ParenthesizedExpression p = ParseUtil.ParseExpression<ParenthesizedExpression>("((1))"); |
||||
Assert.IsTrue(p.Expression is ParenthesizedExpression); |
||||
p = p.Expression as ParenthesizedExpression;; |
||||
Assert.IsTrue(p.Expression is PrimitiveExpression); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class PrimitiveExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void PrimitiveExpression1Test() |
||||
{ |
||||
InvocationExpression ie = ParseUtil.ParseExpression<InvocationExpression>("546.ToString()"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,635 +0,0 @@
@@ -1,635 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class QueryExpressionTests |
||||
{ |
||||
void RunTest(string expression, int expectedCount, Action<QueryExpression> constraint, params Type[] expectedTypes) |
||||
{ |
||||
var expr = ParseUtil.ParseExpression<QueryExpression>(expression); |
||||
|
||||
Assert.AreEqual(expectedCount, expr.Clauses.Count); |
||||
|
||||
for (int i = 0; i < expectedTypes.Length; i++) { |
||||
Assert.IsTrue(expectedTypes[i] == expr.Clauses[i].GetType()); |
||||
} |
||||
|
||||
constraint(expr); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleQueryTest() |
||||
{ |
||||
RunTest("From o In db.Orders Select o.OrderID", 2, |
||||
expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var selectClause = expr.Clauses[1] as QueryExpressionSelectVBClause; |
||||
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("o", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is MemberReferenceExpression); |
||||
var inExpr = var1.Expression as MemberReferenceExpression; |
||||
Assert.IsTrue(inExpr.MemberName == "Orders" && inExpr.TargetObject is IdentifierExpression && (inExpr.TargetObject as IdentifierExpression).Identifier == "db"); |
||||
|
||||
Assert.AreEqual(1, selectClause.Variables.Count); |
||||
Assert.IsTrue(selectClause.Variables[0].Expression is MemberReferenceExpression); |
||||
var member = selectClause.Variables[0].Expression as MemberReferenceExpression; |
||||
|
||||
Assert.IsTrue(member.MemberName == "OrderID" && member.TargetObject is IdentifierExpression && (member.TargetObject as IdentifierExpression).Identifier == "o"); |
||||
}, |
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionSelectVBClause) |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void SkipTakeQueryTest() |
||||
{ |
||||
RunTest("From o In db.Orders Select o.OrderID Skip 10 Take 5", 4, |
||||
expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var selectClause = expr.Clauses[1] as QueryExpressionSelectVBClause; |
||||
var skipClause = expr.Clauses[2] as QueryExpressionPartitionVBClause; |
||||
var takeClause = expr.Clauses[3] as QueryExpressionPartitionVBClause; |
||||
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("o", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is MemberReferenceExpression); |
||||
var inExpr = var1.Expression as MemberReferenceExpression; |
||||
Assert.IsTrue(inExpr.MemberName == "Orders" && inExpr.TargetObject is IdentifierExpression && (inExpr.TargetObject as IdentifierExpression).Identifier == "db"); |
||||
|
||||
Assert.AreEqual(1, selectClause.Variables.Count); |
||||
Assert.IsTrue(selectClause.Variables[0].Expression is MemberReferenceExpression); |
||||
var member = selectClause.Variables[0].Expression as MemberReferenceExpression; |
||||
|
||||
Assert.IsTrue(member.MemberName == "OrderID" && member.TargetObject is IdentifierExpression && (member.TargetObject as IdentifierExpression).Identifier == "o"); |
||||
|
||||
Assert.AreEqual(QueryExpressionPartitionType.Skip, skipClause.PartitionType); |
||||
Assert.IsTrue(skipClause.Expression is PrimitiveExpression && |
||||
(skipClause.Expression as PrimitiveExpression).StringValue == "10"); |
||||
|
||||
Assert.AreEqual(QueryExpressionPartitionType.Take, takeClause.PartitionType); |
||||
Assert.IsTrue(takeClause.Expression is PrimitiveExpression && |
||||
(takeClause.Expression as PrimitiveExpression).StringValue == "5"); |
||||
}, |
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionSelectVBClause), |
||||
typeof(QueryExpressionPartitionVBClause), typeof(QueryExpressionPartitionVBClause) |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void SkipWhileTakeWhileQueryTest() |
||||
{ |
||||
RunTest("From o In db.Orders Select o.OrderID Skip While o.OrderId > 2 Take While o.OrderId < 5", 4, |
||||
expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var selectClause = expr.Clauses[1] as QueryExpressionSelectVBClause; |
||||
var skipClause = expr.Clauses[2] as QueryExpressionPartitionVBClause; |
||||
var takeClause = expr.Clauses[3] as QueryExpressionPartitionVBClause; |
||||
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("o", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is MemberReferenceExpression); |
||||
var inExpr = var1.Expression as MemberReferenceExpression; |
||||
Assert.IsTrue(inExpr.MemberName == "Orders" && inExpr.TargetObject is IdentifierExpression && (inExpr.TargetObject as IdentifierExpression).Identifier == "db"); |
||||
|
||||
Assert.AreEqual(1, selectClause.Variables.Count); |
||||
Assert.IsTrue(selectClause.Variables[0].Expression is MemberReferenceExpression); |
||||
var member = selectClause.Variables[0].Expression as MemberReferenceExpression; |
||||
|
||||
Assert.IsTrue(member.MemberName == "OrderID" && member.TargetObject is IdentifierExpression && (member.TargetObject as IdentifierExpression).Identifier == "o"); |
||||
|
||||
Assert.AreEqual(QueryExpressionPartitionType.SkipWhile, skipClause.PartitionType); |
||||
Assert.IsTrue(skipClause.Expression is BinaryOperatorExpression); |
||||
|
||||
Assert.AreEqual(QueryExpressionPartitionType.TakeWhile, takeClause.PartitionType); |
||||
Assert.IsTrue(takeClause.Expression is BinaryOperatorExpression); |
||||
}, |
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionSelectVBClause), |
||||
typeof(QueryExpressionPartitionVBClause), typeof(QueryExpressionPartitionVBClause) |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultipleValuesSelectTest() |
||||
{ |
||||
RunTest(@"From i In list Select i, x2 = i^2", |
||||
2, expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var selectClause = expr.Clauses[1] as QueryExpressionSelectVBClause; |
||||
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("i", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((var1.Expression as IdentifierExpression).Identifier == "list"); |
||||
|
||||
Assert.AreEqual(2, selectClause.Variables.Count); |
||||
|
||||
var selectExpr1 = selectClause.Variables[0]; |
||||
var selectExpr2 = selectClause.Variables[1]; |
||||
|
||||
Assert.IsEmpty(selectExpr1.Identifier); |
||||
Assert.IsTrue(selectExpr1.Expression is IdentifierExpression && |
||||
(selectExpr1.Expression as IdentifierExpression).Identifier == "i"); |
||||
|
||||
Assert.AreEqual("x2", selectExpr2.Identifier); |
||||
Assert.IsTrue(selectExpr2.Type.IsNull); |
||||
Assert.IsTrue(selectExpr2.Expression is BinaryOperatorExpression); |
||||
|
||||
var binOp = selectExpr2.Expression as BinaryOperatorExpression; |
||||
|
||||
Assert.AreEqual(BinaryOperatorType.Power, binOp.Op); |
||||
Assert.IsTrue(binOp.Left is IdentifierExpression && (binOp.Left as IdentifierExpression).Identifier == "i"); |
||||
Assert.IsTrue(binOp.Right is PrimitiveExpression && (binOp.Right as PrimitiveExpression).StringValue == "2"); |
||||
}, |
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionSelectVBClause) |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void GroupTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var groupClause = expr.Clauses[1] as QueryExpressionGroupVBClause; |
||||
var selectClause = expr.Clauses[2] as QueryExpressionSelectVBClause; |
||||
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var fromVar1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("p", fromVar1.Identifier); |
||||
Assert.IsTrue(fromVar1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((fromVar1.Expression as IdentifierExpression).Identifier == "products"); |
||||
|
||||
Assert.AreEqual(1, groupClause.GroupVariables.Count); |
||||
Assert.AreEqual(1, groupClause.ByVariables.Count); |
||||
Assert.AreEqual(1, groupClause.IntoVariables.Count); |
||||
|
||||
var gv = groupClause.GroupVariables.First(); |
||||
var bv = groupClause.ByVariables.First(); |
||||
var iv = groupClause.IntoVariables.First(); |
||||
|
||||
Assert.IsTrue(gv.Expression is IdentifierExpression && (gv.Expression as IdentifierExpression).Identifier == "p"); |
||||
Assert.IsTrue(bv.Expression is MemberReferenceExpression && |
||||
(bv.Expression as MemberReferenceExpression).MemberName == "Category"); |
||||
Assert.IsTrue((bv.Expression as MemberReferenceExpression).TargetObject is IdentifierExpression && |
||||
((bv.Expression as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == "p"); |
||||
Assert.IsTrue(iv.Expression is IdentifierExpression && |
||||
(iv.Expression as IdentifierExpression).Identifier == "Group"); |
||||
|
||||
Assert.AreEqual(2, selectClause.Variables.Count); |
||||
|
||||
var var1 = selectClause.Variables.First(); |
||||
var var2 = selectClause.Variables.Skip(1).First(); |
||||
|
||||
Assert.IsTrue(var1.Expression is IdentifierExpression && |
||||
(var1.Expression as IdentifierExpression).Identifier == "Category"); |
||||
Assert.IsTrue(var2.Expression is InvocationExpression && |
||||
(var2.Expression as InvocationExpression).TargetObject is MemberReferenceExpression && |
||||
((var2.Expression as InvocationExpression).TargetObject as MemberReferenceExpression).MemberName == "Average" && |
||||
((var2.Expression as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject is IdentifierExpression && |
||||
(((var2.Expression as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == "Group"); |
||||
}; |
||||
|
||||
RunTest(@"From p In products _
|
||||
Group p By p.Category Into Group _ |
||||
Select Category, AveragePrice = Group.Average(Function(p) p.UnitPrice)", 3, constraint,
|
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionGroupVBClause), typeof(QueryExpressionSelectVBClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void LetTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var groupClause = expr.Clauses[1] as QueryExpressionGroupVBClause; |
||||
var letClause = expr.Clauses[2] as QueryExpressionLetClause; |
||||
var selectClause = expr.Clauses[3] as QueryExpressionSelectVBClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var fromVar1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("p", fromVar1.Identifier); |
||||
Assert.IsTrue(fromVar1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((fromVar1.Expression as IdentifierExpression).Identifier == "products"); |
||||
|
||||
// Group By Into
|
||||
Assert.AreEqual(1, groupClause.GroupVariables.Count); |
||||
Assert.AreEqual(1, groupClause.ByVariables.Count); |
||||
Assert.AreEqual(1, groupClause.IntoVariables.Count); |
||||
|
||||
var gv = groupClause.GroupVariables.First(); |
||||
var bv = groupClause.ByVariables.First(); |
||||
var iv = groupClause.IntoVariables.First(); |
||||
|
||||
Assert.IsTrue(gv.Expression is IdentifierExpression && (gv.Expression as IdentifierExpression).Identifier == "p"); |
||||
CheckMemberReferenceExpression(bv.Expression, "Category", "p"); |
||||
Assert.IsTrue(iv.Expression is IdentifierExpression && |
||||
(iv.Expression as IdentifierExpression).Identifier == "Group"); |
||||
|
||||
// Let
|
||||
Assert.AreEqual(1, letClause.Variables.Count); |
||||
|
||||
var letVariable = letClause.Variables.First(); |
||||
|
||||
Assert.AreEqual("minPrice", letVariable.Identifier); |
||||
Assert.IsTrue(letVariable.Expression is InvocationExpression); |
||||
CheckMemberReferenceExpression((letVariable.Expression as InvocationExpression).TargetObject, "Min", "Group"); |
||||
|
||||
// Select
|
||||
Assert.AreEqual(2, selectClause.Variables.Count); |
||||
|
||||
var var1 = selectClause.Variables.First(); |
||||
var var2 = selectClause.Variables.Skip(1).First(); |
||||
|
||||
Assert.IsTrue(var1.Expression is IdentifierExpression && |
||||
(var1.Expression as IdentifierExpression).Identifier == "Category"); |
||||
Assert.IsTrue(var2.Expression is InvocationExpression); |
||||
CheckMemberReferenceExpression((var2.Expression as InvocationExpression).TargetObject, "Where", "Group"); |
||||
}; |
||||
|
||||
RunTest(@"From p In products _
|
||||
Group p By p.Category Into Group _ |
||||
Let minPrice = Group.Min(Function(p) p.UnitPrice) _ |
||||
Select Category, CheapestProducts = Group.Where(Function(p) p.UnitPrice = minPrice)", 4, constraint,
|
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionGroupVBClause), typeof(QueryExpressionLetClause), typeof(QueryExpressionSelectVBClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CrossJoinTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var joinClause = expr.Clauses[1] as QueryExpressionJoinVBClause; |
||||
var selectClause = expr.Clauses[2] as QueryExpressionSelectVBClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var fromVar1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("c", fromVar1.Identifier); |
||||
Assert.IsTrue(fromVar1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((fromVar1.Expression as IdentifierExpression).Identifier == "categories"); |
||||
|
||||
// Join In On Equals
|
||||
var inClause = joinClause.JoinVariable as CollectionRangeVariable; |
||||
|
||||
Assert.AreEqual("p", inClause.Identifier); |
||||
Assert.IsTrue(inClause.Expression is IdentifierExpression && |
||||
(inClause.Expression as IdentifierExpression).Identifier == "products"); |
||||
|
||||
Assert.IsTrue(joinClause.SubJoin.IsNull); |
||||
|
||||
Assert.AreEqual(1, joinClause.Conditions.Count); |
||||
|
||||
var condition1 = joinClause.Conditions.First(); |
||||
|
||||
Assert.IsTrue(condition1.LeftSide is IdentifierExpression && (condition1.LeftSide as IdentifierExpression).Identifier == "c"); |
||||
|
||||
CheckMemberReferenceExpression(condition1.RightSide, "Category", "p"); |
||||
|
||||
// Select
|
||||
Assert.AreEqual(2, selectClause.Variables.Count); |
||||
|
||||
var var1 = selectClause.Variables.First(); |
||||
var var2 = selectClause.Variables.Skip(1).First(); |
||||
|
||||
Assert.AreEqual("Category", var1.Identifier); |
||||
Assert.IsEmpty(var2.Identifier); |
||||
|
||||
Assert.IsTrue(var1.Expression is IdentifierExpression && |
||||
(var1.Expression as IdentifierExpression).Identifier == "c"); |
||||
CheckMemberReferenceExpression(var2.Expression, "ProductName", "p"); |
||||
}; |
||||
|
||||
RunTest(@"From c In categories _
|
||||
Join p In products On c Equals p.Category _ |
||||
Select Category = c, p.ProductName", 3, constraint,
|
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionJoinVBClause), typeof(QueryExpressionSelectVBClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void OrderByTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var orderClause = expr.Clauses[1] as QueryExpressionOrderClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("i", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((var1.Expression as IdentifierExpression).Identifier == "list"); |
||||
|
||||
// Order By
|
||||
Assert.AreEqual(1, orderClause.Orderings.Count); |
||||
|
||||
var ordering1 = orderClause.Orderings.First(); |
||||
|
||||
Assert.IsTrue(ordering1.Criteria is IdentifierExpression && |
||||
(ordering1.Criteria as IdentifierExpression).Identifier == "i"); |
||||
Assert.AreEqual(QueryExpressionOrderingDirection.None, ordering1.Direction); |
||||
}; |
||||
|
||||
RunTest(@"From i In list Order By i", 2, constraint, typeof(QueryExpressionFromClause), typeof(QueryExpressionOrderClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void OrderByTest2() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var orderClause = expr.Clauses[1] as QueryExpressionOrderClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("i", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((var1.Expression as IdentifierExpression).Identifier == "list"); |
||||
|
||||
// Order By
|
||||
Assert.AreEqual(1, orderClause.Orderings.Count); |
||||
|
||||
var ordering1 = orderClause.Orderings.First(); |
||||
|
||||
Assert.IsTrue(ordering1.Criteria is IdentifierExpression && |
||||
(ordering1.Criteria as IdentifierExpression).Identifier == "i"); |
||||
Assert.AreEqual(QueryExpressionOrderingDirection.Ascending, ordering1.Direction); |
||||
}; |
||||
|
||||
RunTest(@"From i In list Order By i Ascending", 2, constraint, typeof(QueryExpressionFromClause), typeof(QueryExpressionOrderClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void OrderByTest3() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var orderClause = expr.Clauses[1] as QueryExpressionOrderClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("i", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((var1.Expression as IdentifierExpression).Identifier == "list"); |
||||
|
||||
// Order By
|
||||
Assert.AreEqual(1, orderClause.Orderings.Count); |
||||
|
||||
var ordering1 = orderClause.Orderings.First(); |
||||
|
||||
Assert.IsTrue(ordering1.Criteria is IdentifierExpression && |
||||
(ordering1.Criteria as IdentifierExpression).Identifier == "i"); |
||||
Assert.AreEqual(QueryExpressionOrderingDirection.Descending, ordering1.Direction); |
||||
}; |
||||
|
||||
RunTest(@"From i In list Order By i Descending", 2, constraint, typeof(QueryExpressionFromClause), typeof(QueryExpressionOrderClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void OrderByThenByTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var orderClause = expr.Clauses[1] as QueryExpressionOrderClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("d", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((var1.Expression as IdentifierExpression).Identifier == "digits"); |
||||
|
||||
// Order By
|
||||
Assert.AreEqual(2, orderClause.Orderings.Count); |
||||
|
||||
var ordering1 = orderClause.Orderings.First(); |
||||
var ordering2 = orderClause.Orderings.Skip(1).First(); |
||||
|
||||
CheckMemberReferenceExpression(ordering1.Criteria, "Length", "d"); |
||||
|
||||
Assert.IsTrue(ordering2.Criteria is IdentifierExpression && |
||||
(ordering2.Criteria as IdentifierExpression).Identifier == "d"); |
||||
|
||||
Assert.AreEqual(QueryExpressionOrderingDirection.None, ordering1.Direction); |
||||
Assert.AreEqual(QueryExpressionOrderingDirection.None, ordering2.Direction); |
||||
|
||||
}; |
||||
|
||||
RunTest(@"From d In digits _
|
||||
Order By d.Length, d", 2, constraint,
|
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionOrderClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void DistinctTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(1, fromClause.Sources.Count); |
||||
|
||||
var var1 = fromClause.Sources.First(); |
||||
|
||||
Assert.AreEqual("d", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((var1.Expression as IdentifierExpression).Identifier == "digits"); |
||||
}; |
||||
|
||||
RunTest(@"From d In digits Distinct", 2, constraint, |
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionDistinctClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void AggregateTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var clause = expr.Clauses[0] as QueryExpressionAggregateClause; |
||||
|
||||
Assert.AreEqual("p", clause.Source.Identifier); |
||||
CheckMemberReferenceExpression(clause.Source.Expression, "GetProcesses", "Process"); |
||||
|
||||
Assert.AreEqual(1, clause.IntoVariables.Count); |
||||
|
||||
var into1 = clause.IntoVariables.First(); |
||||
|
||||
Assert.AreEqual("virtualMemory", into1.Identifier); |
||||
|
||||
Assert.IsTrue(into1.Expression is InvocationExpression && |
||||
(into1.Expression as InvocationExpression).TargetObject is IdentifierExpression && |
||||
((into1.Expression as InvocationExpression).TargetObject as IdentifierExpression).Identifier == "Sum"); |
||||
Assert.AreEqual(1, (into1.Expression as InvocationExpression).Arguments.Count); |
||||
CheckMemberReferenceExpression((into1.Expression as InvocationExpression).Arguments.First(), "VirtualMemorySize64", "p"); |
||||
}; |
||||
|
||||
RunTest(@"Aggregate p In Process.GetProcesses _
|
||||
Into virtualMemory = Sum(p.VirtualMemorySize64)", 1, constraint, typeof(QueryExpressionAggregateClause));
|
||||
} |
||||
|
||||
[Test] |
||||
public void GroupJoinTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause1 = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var groupJoinClause = expr.Clauses[1] as QueryExpressionGroupJoinVBClause; |
||||
var fromClause2 = expr.Clauses[2] as QueryExpressionFromClause; |
||||
var selectClause = expr.Clauses[3] as QueryExpressionSelectVBClause; |
||||
|
||||
// From 1
|
||||
Assert.AreEqual(1, fromClause1.Sources.Count); |
||||
|
||||
var var1 = fromClause1.Sources.First(); |
||||
|
||||
Assert.AreEqual("s", var1.Identifier); |
||||
Assert.IsTrue(var1.Expression is IdentifierExpression && |
||||
(var1.Expression as IdentifierExpression).Identifier == "fileList"); |
||||
|
||||
// From 2
|
||||
Assert.AreEqual(1, fromClause2.Sources.Count); |
||||
|
||||
var var2 = fromClause2.Sources.First(); |
||||
|
||||
Assert.AreEqual("p", var2.Identifier); |
||||
Assert.IsTrue(var2.Expression is IdentifierExpression && |
||||
(var2.Expression as IdentifierExpression).Identifier == "Group"); |
||||
|
||||
// Select
|
||||
Assert.AreEqual(1, selectClause.Variables.Count); |
||||
|
||||
var var3 = selectClause.Variables.First(); |
||||
|
||||
Assert.IsEmpty(var3.Identifier); |
||||
Assert.IsTrue(var3.Expression is IdentifierExpression && |
||||
(var3.Expression as IdentifierExpression).Identifier == "s"); |
||||
|
||||
// Group Join
|
||||
var joinClause = groupJoinClause.JoinClause; |
||||
|
||||
// Join In On Equals
|
||||
var inClause = joinClause.JoinVariable as CollectionRangeVariable; |
||||
|
||||
Assert.AreEqual("p", inClause.Identifier); |
||||
Assert.IsTrue(inClause.Expression is IdentifierExpression && |
||||
(inClause.Expression as IdentifierExpression).Identifier == "IMAGES"); |
||||
|
||||
Assert.IsTrue(joinClause.SubJoin.IsNull); |
||||
|
||||
Assert.AreEqual(1, joinClause.Conditions.Count); |
||||
|
||||
var condition1 = joinClause.Conditions.First(); |
||||
|
||||
Assert.IsTrue(condition1.LeftSide is InvocationExpression); |
||||
Assert.IsTrue((condition1.LeftSide as InvocationExpression).TargetObject is MemberReferenceExpression); |
||||
Assert.IsTrue(((condition1.LeftSide as InvocationExpression).TargetObject as MemberReferenceExpression).MemberName == "ToUpper"); |
||||
Assert.IsTrue(((condition1.LeftSide as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject is MemberReferenceExpression); |
||||
Assert.IsTrue((((condition1.LeftSide as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject as MemberReferenceExpression).MemberName == "Extension"); |
||||
Assert.IsTrue((((condition1.LeftSide as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject as MemberReferenceExpression).TargetObject is IdentifierExpression); |
||||
Assert.IsTrue(((((condition1.LeftSide as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == "s"); |
||||
|
||||
Assert.IsTrue(condition1.RightSide is InvocationExpression); |
||||
Assert.IsTrue((condition1.RightSide as InvocationExpression).TargetObject is MemberReferenceExpression); |
||||
Assert.IsTrue(((condition1.RightSide as InvocationExpression).TargetObject as MemberReferenceExpression).MemberName == "ToUpper"); |
||||
Assert.IsTrue(((condition1.RightSide as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject is IdentifierExpression); |
||||
Assert.IsTrue((((condition1.RightSide as InvocationExpression).TargetObject as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == "p"); |
||||
}; |
||||
|
||||
RunTest(@"From s In fileList _
|
||||
Group Join p In IMAGES On s.Extension.ToUpper() Equals p.ToUpper() Into Group _ |
||||
From p In Group _ |
||||
Select s", 4, constraint,
|
||||
typeof(QueryExpressionFromClause), typeof(QueryExpressionGroupJoinVBClause), typeof(QueryExpressionFromClause), typeof(QueryExpressionSelectVBClause)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectManyTest() |
||||
{ |
||||
Action<QueryExpression> constraint = expr => { |
||||
var fromClause = expr.Clauses[0] as QueryExpressionFromClause; |
||||
var whereClause = expr.Clauses[1] as QueryExpressionWhereClause; |
||||
var selectClause = expr.Clauses[2] as QueryExpressionSelectVBClause; |
||||
|
||||
// From
|
||||
Assert.AreEqual(2, fromClause.Sources.Count); |
||||
|
||||
var fromVar1 = fromClause.Sources.First(); |
||||
var fromVar2 = fromClause.Sources.Skip(1).First(); |
||||
|
||||
Assert.AreEqual("c", fromVar1.Identifier); |
||||
Assert.IsTrue(fromVar1.Expression is IdentifierExpression); |
||||
Assert.IsTrue((fromVar1.Expression as IdentifierExpression).Identifier == "customers"); |
||||
|
||||
Assert.AreEqual("o", fromVar2.Identifier); |
||||
CheckMemberReferenceExpression(fromVar2.Expression, "Orders", "c"); |
||||
|
||||
// Where
|
||||
Assert.IsTrue(whereClause.Condition is BinaryOperatorExpression); |
||||
Assert.IsTrue((whereClause.Condition as BinaryOperatorExpression).Op == BinaryOperatorType.LessThan); |
||||
CheckMemberReferenceExpression((whereClause.Condition as BinaryOperatorExpression).Left, "Total", "o"); |
||||
Assert.IsTrue((whereClause.Condition as BinaryOperatorExpression).Right is PrimitiveExpression); |
||||
Assert.IsTrue((double)((whereClause.Condition as BinaryOperatorExpression).Right as PrimitiveExpression).Value == 500.0); |
||||
|
||||
// Select
|
||||
foreach (var v in selectClause.Variables) { |
||||
Assert.IsEmpty(v.Identifier); |
||||
} |
||||
|
||||
var var1 = selectClause.Variables.First(); |
||||
var var2 = selectClause.Variables.Skip(1).First(); |
||||
var var3 = selectClause.Variables.Skip(2).First(); |
||||
|
||||
CheckMemberReferenceExpression(var1.Expression, "CustomerID", "c"); |
||||
CheckMemberReferenceExpression(var2.Expression, "OrderID", "o"); |
||||
CheckMemberReferenceExpression(var3.Expression, "Total", "o"); |
||||
}; |
||||
|
||||
RunTest(@"From c In customers, o In c.Orders _
|
||||
Where o.Total < 500.0 _ |
||||
Select c.CustomerID, o.OrderID, o.Total", 3, constraint, typeof(QueryExpressionFromClause), typeof(QueryExpressionWhereClause), typeof(QueryExpressionSelectVBClause));
|
||||
} |
||||
|
||||
void CheckMemberReferenceExpression(Expression expr, string memberName, string targetObjectIdentifier) |
||||
{ |
||||
Assert.IsTrue(expr is MemberReferenceExpression); |
||||
Assert.IsTrue((expr as MemberReferenceExpression).MemberName == memberName && |
||||
(expr as MemberReferenceExpression).TargetObject is IdentifierExpression && |
||||
((expr as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == targetObjectIdentifier); |
||||
} |
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ThisReferenceExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetThisReferenceExpressionTest1() |
||||
{ |
||||
ThisReferenceExpression ie = ParseUtil.ParseExpression<ThisReferenceExpression>("Me"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class TypeOfExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBSimpleTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyNamespace.N1.MyType)"); |
||||
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void VBGlobalTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(Global.System.Console)"); |
||||
Assert.AreEqual("System.Console", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBPrimitiveTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(integer)"); |
||||
Assert.AreEqual("System.Int32", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBVoidTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(void)"); |
||||
Assert.AreEqual("void", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBArrayTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyType())"); |
||||
Assert.AreEqual("MyType", toe.TypeReference.Type); |
||||
Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBGenericTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyNamespace.N1.MyType(Of string))"); |
||||
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); |
||||
Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBUnboundTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyType(Of ,))"); |
||||
Assert.AreEqual("MyType", toe.TypeReference.Type); |
||||
Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull); |
||||
Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNestedGenericTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtil.ParseExpression<TypeOfExpression>("GetType(MyType(Of string).InnerClass(of integer).InnerInnerClass)"); |
||||
InnerClassTypeReference ic = (InnerClassTypeReference)toe.TypeReference; |
||||
Assert.AreEqual("InnerInnerClass", ic.Type); |
||||
Assert.AreEqual(0, ic.GenericTypes.Count); |
||||
ic = (InnerClassTypeReference)ic.BaseType; |
||||
Assert.AreEqual("InnerClass", ic.Type); |
||||
Assert.AreEqual(1, ic.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type); |
||||
Assert.AreEqual("MyType", ic.BaseType.Type); |
||||
Assert.AreEqual(1, ic.BaseType.GenericTypes.Count); |
||||
Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,34 +0,0 @@
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class TypeOfIsExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleTypeOfIsExpression() |
||||
{ |
||||
TypeOfIsExpression ce = ParseUtil.ParseExpression<TypeOfIsExpression>("TypeOf o Is MyObject"); |
||||
Assert.AreEqual("MyObject", ce.TypeReference.Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericTypeOfIsExpression() |
||||
{ |
||||
TypeOfIsExpression ce = ParseUtil.ParseExpression<TypeOfIsExpression>("TypeOf o Is List(of T)"); |
||||
Assert.AreEqual("List", ce.TypeReference.Type); |
||||
Assert.AreEqual("T", ce.TypeReference.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is SimpleNameExpression); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class TypeReferenceExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBIntReferenceExpression() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("inTeGer.MaxValue"); |
||||
Assert.AreEqual("MaxValue", fre.MemberName); |
||||
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBStandaloneIntReferenceExpression() |
||||
{ |
||||
TypeReferenceExpression tre = ParseUtil.ParseExpression<TypeReferenceExpression>("inTeGer"); |
||||
Assert.AreEqual("System.Int32", tre.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBObjectReferenceExpression() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtil.ParseExpression<MemberReferenceExpression>("Object.ReferenceEquals"); |
||||
Assert.AreEqual("ReferenceEquals", fre.MemberName); |
||||
Assert.AreEqual("System.Object", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBStandaloneObjectReferenceExpression() |
||||
{ |
||||
TypeReferenceExpression tre = ParseUtil.ParseExpression<TypeReferenceExpression>("obJect"); |
||||
Assert.AreEqual("System.Object", tre.TypeReference.Type); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class UnaryOperatorExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
void VBNetTestUnaryOperatorExpressionTest(string program, UnaryOperatorType op) |
||||
{ |
||||
UnaryOperatorExpression uoe = ParseUtil.ParseExpression<UnaryOperatorExpression>(program); |
||||
Assert.AreEqual(op, uoe.Op); |
||||
|
||||
Assert.IsTrue(uoe.Expression is SimpleNameExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNotTest() |
||||
{ |
||||
VBNetTestUnaryOperatorExpressionTest("Not a", UnaryOperatorType.Not); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInEqualsNotTest() |
||||
{ |
||||
BinaryOperatorExpression e = ParseUtil.ParseExpression<BinaryOperatorExpression>("b <> Not a"); |
||||
Assert.AreEqual(BinaryOperatorType.InEquality, e.Op); |
||||
UnaryOperatorExpression ue = (UnaryOperatorExpression)e.Right; |
||||
Assert.AreEqual(UnaryOperatorType.Not, ue.Op); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNotEqualTest() |
||||
{ |
||||
UnaryOperatorExpression e = ParseUtil.ParseExpression<UnaryOperatorExpression>("Not a = b"); |
||||
Assert.AreEqual(UnaryOperatorType.Not, e.Op); |
||||
BinaryOperatorExpression boe = (BinaryOperatorExpression)e.Expression; |
||||
Assert.AreEqual(BinaryOperatorType.Equality, boe.Op); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetPlusTest() |
||||
{ |
||||
VBNetTestUnaryOperatorExpressionTest("+a", UnaryOperatorType.Plus); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMinusTest() |
||||
{ |
||||
VBNetTestUnaryOperatorExpressionTest("-a", UnaryOperatorType.Minus); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,255 +0,0 @@
@@ -1,255 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class XmlExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleCommentTest() |
||||
{ |
||||
XmlContentExpression content = ParseUtil.ParseExpression<XmlContentExpression>("<!-- test -->"); |
||||
Assert.AreEqual(XmlContentType.Comment, content.Type); |
||||
Assert.AreEqual(" test ", content.Content); |
||||
Assert.AreEqual(new Location(1,1), content.StartLocation); |
||||
Assert.AreEqual(new Location(14,1), content.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimplePreprocessingInstructionTest() |
||||
{ |
||||
XmlContentExpression content = ParseUtil.ParseExpression<XmlContentExpression>("<?xml version='1.0'?>"); |
||||
Assert.AreEqual(XmlContentType.ProcessingInstruction, content.Type); |
||||
Assert.AreEqual("xml version='1.0'", content.Content); |
||||
Assert.AreEqual(new Location(1,1), content.StartLocation); |
||||
Assert.AreEqual(new Location(22,1), content.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleCDataTest() |
||||
{ |
||||
XmlContentExpression content = ParseUtil.ParseExpression<XmlContentExpression>("<![CDATA[<simple> <cdata>]]>"); |
||||
Assert.AreEqual(XmlContentType.CData, content.Type); |
||||
Assert.AreEqual("<simple> <cdata>", content.Content); |
||||
Assert.AreEqual(new Location(1,1), content.StartLocation); |
||||
Assert.AreEqual(new Location(29,1), content.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleEmptyElementTest() |
||||
{ |
||||
XmlElementExpression element = ParseUtil.ParseExpression<XmlElementExpression>("<Test />"); |
||||
Assert.IsFalse(element.NameIsExpression); |
||||
Assert.AreEqual("Test", element.XmlName); |
||||
Assert.IsEmpty(element.Attributes); |
||||
Assert.IsEmpty(element.Children); |
||||
Assert.AreEqual(new Location(1,1), element.StartLocation); |
||||
Assert.AreEqual(new Location(9,1), element.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleEmptyElementWithAttributeTest() |
||||
{ |
||||
XmlElementExpression element = ParseUtil.ParseExpression<XmlElementExpression>("<Test id='0' />"); |
||||
Assert.IsFalse(element.NameIsExpression); |
||||
Assert.AreEqual("Test", element.XmlName); |
||||
Assert.IsNotEmpty(element.Attributes); |
||||
Assert.AreEqual(1, element.Attributes.Count); |
||||
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression); |
||||
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression; |
||||
Assert.AreEqual("id", attribute.Name); |
||||
Assert.IsTrue(attribute.IsLiteralValue); |
||||
Assert.IsTrue(attribute.ExpressionValue.IsNull); |
||||
Assert.AreEqual("0", attribute.LiteralValue); |
||||
Assert.AreEqual(new Location(7,1), attribute.StartLocation); |
||||
Assert.AreEqual(new Location(13,1), attribute.EndLocation); |
||||
Assert.IsEmpty(element.Children); |
||||
Assert.AreEqual(new Location(1,1), element.StartLocation); |
||||
Assert.AreEqual(new Location(16,1), element.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleEmptyElementWithAttributesTest() |
||||
{ |
||||
XmlElementExpression element = ParseUtil.ParseExpression<XmlElementExpression>("<Test id='0' name=<%= name %> <%= contentData %> />"); Assert.IsFalse(element.NameIsExpression); |
||||
Assert.AreEqual("Test", element.XmlName); |
||||
Assert.IsNotEmpty(element.Attributes); |
||||
Assert.AreEqual(3, element.Attributes.Count); |
||||
|
||||
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression); |
||||
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression; |
||||
Assert.AreEqual("id", attribute.Name); |
||||
Assert.IsTrue(attribute.IsLiteralValue); |
||||
Assert.IsTrue(attribute.ExpressionValue.IsNull); |
||||
Assert.AreEqual("0", attribute.LiteralValue); |
||||
Assert.AreEqual(new Location(7,1), attribute.StartLocation); |
||||
Assert.AreEqual(new Location(13,1), attribute.EndLocation); |
||||
|
||||
Assert.IsTrue(element.Attributes[1] is XmlAttributeExpression); |
||||
XmlAttributeExpression attribute2 = element.Attributes[1] as XmlAttributeExpression; |
||||
Assert.AreEqual("name", attribute2.Name); |
||||
Assert.IsFalse(attribute2.IsLiteralValue); |
||||
Assert.IsFalse(attribute2.ExpressionValue.IsNull); |
||||
|
||||
Assert.IsTrue(attribute2.ExpressionValue is IdentifierExpression); |
||||
IdentifierExpression identifier = attribute2.ExpressionValue as IdentifierExpression; |
||||
Assert.AreEqual("name", identifier.Identifier); |
||||
Assert.AreEqual(new Location(23,1), identifier.StartLocation); |
||||
Assert.AreEqual(new Location(27,1), identifier.EndLocation); |
||||
|
||||
Assert.AreEqual(new Location(14,1), attribute2.StartLocation); |
||||
Assert.AreEqual(new Location(30,1), attribute2.EndLocation); |
||||
|
||||
Assert.IsTrue(element.Attributes[2] is XmlEmbeddedExpression); |
||||
XmlEmbeddedExpression attribute3 = element.Attributes[2] as XmlEmbeddedExpression; |
||||
|
||||
Assert.IsTrue(attribute3.InlineVBExpression is IdentifierExpression); |
||||
IdentifierExpression identifier2 = attribute3.InlineVBExpression as IdentifierExpression; |
||||
|
||||
Assert.AreEqual("contentData", identifier2.Identifier); |
||||
Assert.AreEqual(new Location(35,1), identifier2.StartLocation); |
||||
Assert.AreEqual(new Location(46,1), identifier2.EndLocation); |
||||
|
||||
Assert.AreEqual(new Location(31,1), attribute3.StartLocation); |
||||
Assert.AreEqual(new Location(49,1), attribute3.EndLocation); |
||||
|
||||
Assert.IsEmpty(element.Children); |
||||
Assert.AreEqual(new Location(1,1), element.StartLocation); |
||||
Assert.AreEqual(new Location(52,1), element.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetElementWithAttributeTest() |
||||
{ |
||||
XmlElementExpression element = ParseUtil.ParseExpression<XmlElementExpression>("<Test id='0'>\n" + |
||||
" <Item />\n" + |
||||
" <Item />\n" + |
||||
"</Test>"); |
||||
Assert.IsFalse(element.NameIsExpression); |
||||
Assert.AreEqual("Test", element.XmlName); |
||||
|
||||
Assert.IsNotEmpty(element.Attributes); |
||||
Assert.AreEqual(1, element.Attributes.Count); |
||||
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression); |
||||
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression; |
||||
Assert.AreEqual("id", attribute.Name); |
||||
Assert.IsTrue(attribute.IsLiteralValue); |
||||
Assert.IsTrue(attribute.ExpressionValue.IsNull); |
||||
Assert.AreEqual("0", attribute.LiteralValue); |
||||
Assert.AreEqual(new Location(7,1), attribute.StartLocation); |
||||
Assert.AreEqual(new Location(13,1), attribute.EndLocation); |
||||
|
||||
Assert.IsNotEmpty(element.Children); |
||||
Assert.AreEqual(5, element.Children.Count); |
||||
|
||||
CheckContent(element.Children[0], "\n\t", XmlContentType.Text, new Location(14,1), new Location(2,2)); |
||||
CheckContent(element.Children[2], "\n\t", XmlContentType.Text, new Location(10,2), new Location(2,3)); |
||||
CheckContent(element.Children[4], "\n", XmlContentType.Text, new Location(10,3), new Location(1,4)); |
||||
|
||||
CheckElement(element.Children[1], "Item", new Location(2,2), new Location(10,2)); |
||||
CheckElement(element.Children[3], "Item", new Location(2,3), new Location(10,3)); |
||||
|
||||
Assert.AreEqual(new Location(1,1), element.StartLocation); |
||||
Assert.AreEqual(new Location(8,4), element.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetElementWithMixedContentTest() |
||||
{ |
||||
XmlElementExpression element = ParseUtil.ParseExpression<XmlElementExpression>("<Test id='0'>\n" + |
||||
" <!-- test -->\n" + |
||||
" <Item />\n" + |
||||
" <Item />\n" + |
||||
" <![CDATA[<cdata> section]]>\n" + |
||||
"</Test>"); |
||||
Assert.IsFalse(element.NameIsExpression); |
||||
Assert.AreEqual("Test", element.XmlName); |
||||
|
||||
Assert.IsNotEmpty(element.Attributes); |
||||
Assert.AreEqual(1, element.Attributes.Count); |
||||
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression); |
||||
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression; |
||||
Assert.AreEqual("id", attribute.Name); |
||||
Assert.IsTrue(attribute.IsLiteralValue); |
||||
Assert.IsTrue(attribute.ExpressionValue.IsNull); |
||||
Assert.AreEqual("0", attribute.LiteralValue); |
||||
Assert.AreEqual(new Location(7,1), attribute.StartLocation); |
||||
Assert.AreEqual(new Location(13,1), attribute.EndLocation); |
||||
|
||||
Assert.IsNotEmpty(element.Children); |
||||
Assert.AreEqual(9, element.Children.Count); |
||||
|
||||
CheckContent(element.Children[0], "\n\t", XmlContentType.Text, new Location(14,1), new Location(2,2)); |
||||
CheckContent(element.Children[2], "\n\t", XmlContentType.Text, new Location(15,2), new Location(2,3)); |
||||
CheckContent(element.Children[4], "\n\t", XmlContentType.Text, new Location(10,3), new Location(2,4)); |
||||
CheckContent(element.Children[6], "\n\t", XmlContentType.Text, new Location(10,4), new Location(2,5)); |
||||
CheckContent(element.Children[7], "<cdata> section", XmlContentType.CData, new Location(2,5), new Location(29,5)); |
||||
CheckContent(element.Children[8], "\n", XmlContentType.Text, new Location(29,5), new Location(1,6)); |
||||
|
||||
CheckContent(element.Children[1], " test ", XmlContentType.Comment, new Location(2,2), new Location(15,2)); |
||||
CheckElement(element.Children[3], "Item", new Location(2,3), new Location(10,3)); |
||||
CheckElement(element.Children[5], "Item", new Location(2,4), new Location(10,4)); |
||||
|
||||
Assert.AreEqual(new Location(1,1), element.StartLocation); |
||||
Assert.AreEqual(new Location(8,6), element.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetElementWithMixedContentTest2() |
||||
{ |
||||
XmlElementExpression element = ParseUtil.ParseExpression<XmlElementExpression>("<Test> aaaa </Test>"); |
||||
Assert.IsFalse(element.NameIsExpression); |
||||
Assert.AreEqual("Test", element.XmlName); |
||||
|
||||
Assert.IsNotEmpty(element.Children); |
||||
Assert.AreEqual(1, element.Children.Count); |
||||
|
||||
CheckContent(element.Children[0], " aaaa ", XmlContentType.Text, new Location(7,1), new Location(14,1)); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetProcessingInstructionAndCommentAtEndTest() |
||||
{ |
||||
XmlDocumentExpression document = ParseUtil.ParseExpression<XmlDocumentExpression>("<Test />\n" + |
||||
"<!-- test -->\n" + |
||||
"<?target some text?>"); |
||||
Assert.IsNotEmpty(document.Expressions); |
||||
Assert.AreEqual(3, document.Expressions.Count); |
||||
|
||||
CheckElement(document.Expressions[0], "Test", new Location(1,1), new Location(9,1)); |
||||
CheckContent(document.Expressions[1], " test ", XmlContentType.Comment, new Location(1,2), new Location(14,2)); |
||||
CheckContent(document.Expressions[2], "target some text", XmlContentType.ProcessingInstruction, new Location(1,3), new Location(21,3)); |
||||
} |
||||
#endregion
|
||||
|
||||
void CheckElement(AstNode node, string name, AstLocation start, AstLocation end) |
||||
{ |
||||
Assert.IsTrue(node is XmlElementExpression); |
||||
XmlElementExpression expr = node as XmlElementExpression; |
||||
Assert.IsEmpty(expr.Attributes); |
||||
Assert.IsEmpty(expr.Children); |
||||
Assert.IsFalse(expr.NameIsExpression); |
||||
Assert.AreEqual(name, expr.XmlName); |
||||
Assert.AreEqual(start, expr.StartLocation); |
||||
Assert.AreEqual(end, expr.EndLocation); |
||||
} |
||||
|
||||
void CheckContent(AstNode node, string content, XmlContentType type, AstLocation start, AstLocation end) |
||||
{ |
||||
Assert.IsTrue(node is XmlContentExpression); |
||||
XmlContentExpression expr = node as XmlContentExpression; |
||||
Assert.AreEqual(type, expr.Type); |
||||
Assert.AreEqual(content, expr.Content); |
||||
Assert.AreEqual(start, expr.StartLocation); |
||||
Assert.AreEqual(end, expr.EndLocation); |
||||
} |
||||
} |
||||
} |
||||
@ -1,101 +0,0 @@
@@ -1,101 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class XmlMemberAccessExpressionTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleElementReferenceTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>("xml.<ns:MyElement>"); |
||||
Assert.AreEqual("ns:MyElement", xmae.Identifier); |
||||
Assert.IsTrue(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Element, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject is IdentifierExpression); |
||||
Assert.AreEqual("xml", ((IdentifierExpression)xmae.TargetObject).Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleAttributeReferenceTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>("xml.@attribute"); |
||||
Assert.AreEqual("attribute", xmae.Identifier); |
||||
Assert.IsFalse(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Attribute, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject is IdentifierExpression); |
||||
Assert.AreEqual("xml", ((IdentifierExpression)xmae.TargetObject).Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetXmlNameAttributeReferenceTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>("xml.@<ns:attribute>"); |
||||
Assert.AreEqual("ns:attribute", xmae.Identifier); |
||||
Assert.IsTrue(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Attribute, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject is IdentifierExpression); |
||||
Assert.AreEqual("xml", ((IdentifierExpression)xmae.TargetObject).Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleDescendentsReferenceTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>("xml...<ns:Element>"); |
||||
Assert.AreEqual("ns:Element", xmae.Identifier); |
||||
Assert.IsTrue(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Descendents, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject is IdentifierExpression); |
||||
Assert.AreEqual("xml", ((IdentifierExpression)xmae.TargetObject).Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleElementReferenceWithDotTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>(".<ns:MyElement>"); |
||||
Assert.AreEqual("ns:MyElement", xmae.Identifier); |
||||
Assert.IsTrue(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Element, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleAttributeReferenceWithDotTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>(".@attribute"); |
||||
Assert.AreEqual("attribute", xmae.Identifier); |
||||
Assert.IsFalse(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Attribute, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetXmlNameAttributeReferenceWithDotTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>(".@<ns:attribute>"); |
||||
Assert.AreEqual("ns:attribute", xmae.Identifier); |
||||
Assert.IsTrue(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Attribute, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleDescendentsReferenceWithDotTest() |
||||
{ |
||||
XmlMemberAccessExpression xmae = ParseUtil.ParseExpression<XmlMemberAccessExpression>("...<ns:Element>"); |
||||
Assert.AreEqual("ns:Element", xmae.Identifier); |
||||
Assert.IsTrue(xmae.IsXmlIdentifier); |
||||
Assert.AreEqual(XmlAxisType.Descendents, xmae.AxisType); |
||||
Assert.IsTrue(xmae.TargetObject.IsNull); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,74 +0,0 @@
@@ -1,74 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class AttributeSectionTests |
||||
{ |
||||
// [Test]
|
||||
// public void AttributeOnStructure()
|
||||
// {
|
||||
// string program = @"
|
||||
//<StructLayout( LayoutKind.Explicit )> _
|
||||
//Public Structure MyUnion
|
||||
//
|
||||
// <FieldOffset( 0 )> Public i As Integer
|
||||
// < FieldOffset( 0 )> Public d As Double
|
||||
//
|
||||
//End Structure 'MyUnion
|
||||
//";
|
||||
// TypeDeclaration decl = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
// Assert.AreEqual("StructLayout", decl.Attributes[0].Attributes[0].Type);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void AttributeOnModule()
|
||||
// {
|
||||
// string program = @"
|
||||
//<HideModule> _
|
||||
//Public Module MyExtra
|
||||
//
|
||||
// Public i As Integer
|
||||
// Public d As Double
|
||||
//
|
||||
//End Module
|
||||
//";
|
||||
// TypeDeclaration decl = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
// Assert.AreEqual("HideModule", decl.Attributes[0].Attributes[0].Type);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void GlobalAttribute()
|
||||
// {
|
||||
// string program = @"<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
|
||||
//Public Class Form1
|
||||
//
|
||||
//End Class";
|
||||
// TypeDeclaration decl = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
// Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes[0].Attributes[0].Type);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void AssemblyAttribute()
|
||||
// {
|
||||
// string program = @"<assembly: System.Attribute()>";
|
||||
// AttributeSection decl = ParseUtil.ParseGlobal<AttributeSection>(program);
|
||||
// Assert.AreEqual(new Location(1, 1), decl.StartLocation);
|
||||
// Assert.AreEqual("assembly", decl.AttributeTarget);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void ModuleAttributeTargetEscaped()
|
||||
// {
|
||||
// // check that this doesn't crash the parser:
|
||||
// ParseUtil.ParseGlobal<AttributeSection>("<[Module]: SuppressMessageAttribute>", true);
|
||||
// }
|
||||
} |
||||
} |
||||
@ -1,43 +0,0 @@
@@ -1,43 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class NamespaceDeclarationTests |
||||
{ |
||||
// #region VB.NET
|
||||
// [Test]
|
||||
// public void VBNetSimpleNamespaceTest()
|
||||
// {
|
||||
// string program = "Namespace TestNamespace" + Environment.NewLine +
|
||||
// "End Namespace" +Environment.NewLine;
|
||||
// NamespaceDeclaration ns = ParseUtil.ParseGlobal<NamespaceDeclaration>(program);
|
||||
// Assert.AreEqual("TestNamespace", ns.Name);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetJuggedNamespaceTest()
|
||||
// {
|
||||
// string program = "Namespace N1 'TestNamespace\n" +
|
||||
// " Namespace N2 ' Declares a namespace named N2 within N1.\n" +
|
||||
// " End Namespace\n" +
|
||||
// "End Namespace\n";
|
||||
//
|
||||
// NamespaceDeclaration ns = ParseUtil.ParseGlobal<NamespaceDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("N1", ns.Name);
|
||||
//
|
||||
// Assert.IsTrue(ns.Children[0] is NamespaceDeclaration);
|
||||
//
|
||||
// ns = (NamespaceDeclaration)ns.Children[0];
|
||||
//
|
||||
// Assert.AreEqual("N2", ns.Name);
|
||||
// }
|
||||
// #endregion
|
||||
} |
||||
} |
||||
@ -1,113 +0,0 @@
@@ -1,113 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OptionStatementTests |
||||
{ |
||||
[Test] |
||||
public void InvalidOptionSyntax() |
||||
{ |
||||
string program = "Option\n"; |
||||
ParseUtil.ParseGlobal<OptionStatement>(program, true); |
||||
} |
||||
|
||||
[Test] |
||||
public void StrictOption() |
||||
{ |
||||
string program = "Option Strict On\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Strict, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitOption() |
||||
{ |
||||
string program = "Option Explicit Off\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Explicit, |
||||
OptionValue = OptionValue.Off |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompareBinaryOption() |
||||
{ |
||||
string program = "Option Compare Binary\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Compare, |
||||
OptionValue = OptionValue.Binary |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompareTextOption() |
||||
{ |
||||
string program = "Option Compare Text\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Compare, |
||||
OptionValue = OptionValue.Text |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void InferOnOption() |
||||
{ |
||||
string program = "Option Infer On\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Infer, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void InferOffOption() |
||||
{ |
||||
string program = "Option Infer Off\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Infer, |
||||
OptionValue = OptionValue.Off |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
|
||||
[Test] |
||||
public void InferOption() |
||||
{ |
||||
string program = "Option Infer\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Infer, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
} |
||||
} |
||||
@ -1,203 +0,0 @@
@@ -1,203 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class TypeDeclarationTests |
||||
{ |
||||
// #region VB.NET
|
||||
// [Test]
|
||||
// public void VBNetSimpleClassTypeDeclarationTest()
|
||||
// {
|
||||
// string program = "Class TestClass\n" +
|
||||
// "End Class\n";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestClass", td.Name);
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual(1, td.StartLocation.Line, "start line");
|
||||
// Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line");
|
||||
// Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col");
|
||||
// Assert.AreEqual(2, td.EndLocation.Line, "end line");
|
||||
// Assert.AreEqual(10, td.EndLocation.Column, "end col");
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetMissingBaseClassTest()
|
||||
// {
|
||||
// // SD2-1499: test that this invalid code doesn't crash
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>("public class test inherits", true);
|
||||
// Assert.AreEqual(0, td.BaseTypes.Count);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetEnumWithBaseClassDeclarationTest()
|
||||
// {
|
||||
// string program = "Enum TestEnum As Byte\n" +
|
||||
// "End Enum\n";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestEnum", td.Name);
|
||||
// Assert.AreEqual(ClassType.Enum, td.Type);
|
||||
// Assert.AreEqual("System.Byte", td.BaseTypes[0].Type);
|
||||
// Assert.AreEqual(0, td.Children.Count);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetEnumOnSingleLine()
|
||||
// {
|
||||
// string program = "Enum TestEnum : A : B = 1 : C : End Enum";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestEnum", td.Name);
|
||||
// Assert.AreEqual(ClassType.Enum, td.Type);
|
||||
// Assert.AreEqual(3, td.Children.Count);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetEnumOnSingleLine2()
|
||||
// {
|
||||
// string program = "Enum TestEnum : A : : B = 1 :: C : End Enum";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestEnum", td.Name);
|
||||
// Assert.AreEqual(ClassType.Enum, td.Type);
|
||||
// Assert.AreEqual(3, td.Children.Count);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetEnumWithSystemBaseClassDeclarationTest()
|
||||
// {
|
||||
// string program = "Enum TestEnum As System.UInt16\n" +
|
||||
// "End Enum\n";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestEnum", td.Name);
|
||||
// Assert.AreEqual(ClassType.Enum, td.Type);
|
||||
// Assert.AreEqual("System.UInt16", td.BaseTypes[0].Type);
|
||||
// Assert.AreEqual(0, td.Children.Count);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetSimpleClassTypeDeclarationWithoutLastNewLineTest()
|
||||
// {
|
||||
// string program = "Class TestClass\n" +
|
||||
// "End Class";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestClass", td.Name);
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual(1, td.StartLocation.Line, "start line");
|
||||
// Assert.AreEqual(2, td.EndLocation.Line, "end line");
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetSimpleClassTypeDeclarationWithColon()
|
||||
// {
|
||||
// string program = "Class TestClass\n" +
|
||||
// " : \n" +
|
||||
// "End Class";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestClass", td.Name);
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetSimplePartialClassTypeDeclarationTest()
|
||||
// {
|
||||
// string program = "Partial Class TestClass\n" +
|
||||
// "End Class\n";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestClass", td.Name);
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual(Modifiers.Partial, td.Modifier);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetPartialPublicClass()
|
||||
// {
|
||||
// string program = "Partial Public Class TestClass\nEnd Class\n";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program);
|
||||
//
|
||||
// Assert.AreEqual("TestClass", td.Name);
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual(Modifiers.Partial | Modifiers.Public, td.Modifier);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetGenericClassTypeDeclarationTest()
|
||||
// {
|
||||
// string declr = @"
|
||||
//Public Class Test(Of T)
|
||||
//
|
||||
//End Class
|
||||
//";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(declr);
|
||||
//
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual("Test", td.Name);
|
||||
// Assert.AreEqual(Modifiers.Public, td.Modifier);
|
||||
// Assert.AreEqual(0, td.BaseTypes.Count);
|
||||
// Assert.AreEqual(1, td.Templates.Count);
|
||||
// Assert.AreEqual("T", td.Templates[0].Name);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetGenericClassWithConstraint()
|
||||
// {
|
||||
// string declr = @"
|
||||
//Public Class Test(Of T As IMyInterface)
|
||||
//
|
||||
//End Class
|
||||
//";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(declr);
|
||||
//
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual("Test", td.Name);
|
||||
//
|
||||
// Assert.AreEqual(1, td.Templates.Count);
|
||||
// Assert.AreEqual("T", td.Templates[0].Name);
|
||||
// Assert.AreEqual("IMyInterface", td.Templates[0].Bases[0].Type);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetComplexGenericClassTypeDeclarationTest()
|
||||
// {
|
||||
// string declr = @"
|
||||
//Public Class Generic(Of T As MyNamespace.IMyInterface, S As {G(Of T()), IAnotherInterface})
|
||||
// Implements System.IComparable
|
||||
//
|
||||
//End Class
|
||||
//";
|
||||
// TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(declr);
|
||||
//
|
||||
// Assert.AreEqual(ClassType.Class, td.Type);
|
||||
// Assert.AreEqual("Generic", td.Name);
|
||||
// Assert.AreEqual(Modifiers.Public, td.Modifier);
|
||||
// Assert.AreEqual(1, td.BaseTypes.Count);
|
||||
// Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type);
|
||||
//
|
||||
// Assert.AreEqual(2, td.Templates.Count);
|
||||
// Assert.AreEqual("T", td.Templates[0].Name);
|
||||
// Assert.AreEqual("MyNamespace.IMyInterface", td.Templates[0].Bases[0].Type);
|
||||
//
|
||||
// Assert.AreEqual("S", td.Templates[1].Name);
|
||||
// Assert.AreEqual(2, td.Templates[1].Bases.Count);
|
||||
// Assert.AreEqual("G", td.Templates[1].Bases[0].Type);
|
||||
// Assert.AreEqual(1, td.Templates[1].Bases[0].GenericTypes.Count);
|
||||
// Assert.IsTrue(td.Templates[1].Bases[0].GenericTypes[0].IsArrayType);
|
||||
// Assert.AreEqual("T", td.Templates[1].Bases[0].GenericTypes[0].Type);
|
||||
// Assert.AreEqual(new int[] {0}, td.Templates[1].Bases[0].GenericTypes[0].RankSpecifier);
|
||||
// Assert.AreEqual("IAnotherInterface", td.Templates[1].Bases[1].Type);
|
||||
// }
|
||||
// #endregion
|
||||
} |
||||
} |
||||
@ -1,108 +0,0 @@
@@ -1,108 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
public class ParseUtil |
||||
{ |
||||
public static T ParseGlobal<T>(string code, bool expectErrors = false) where T : AstNode |
||||
{ |
||||
VBParser parser = new VBParser(); |
||||
CompilationUnit cu = parser.Parse(new StringReader(code)); |
||||
|
||||
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); |
||||
|
||||
AstNode node = cu.Children.Single(); |
||||
Type type = typeof(T); |
||||
Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, node)); |
||||
return (T)node; |
||||
} |
||||
|
||||
public static void AssertGlobal(string code, AstNode expectedNode) |
||||
{ |
||||
var node = ParseGlobal<AstNode>(code); |
||||
if (!expectedNode.IsMatch(node)) { |
||||
Assert.Fail("Expected '{0}' but was '{1}'", ToVB(expectedNode), ToVB(node)); |
||||
} |
||||
} |
||||
|
||||
// public static T ParseStatement<T>(string stmt, bool expectErrors = false) where T : AstNode
|
||||
// {
|
||||
// VBParser parser = new VBParser();
|
||||
// var statements = parser.ParseStatements(new StringReader(stmt));
|
||||
//
|
||||
// Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
|
||||
//
|
||||
// AstNode statement = statements.Single();
|
||||
// Type type = typeof(T);
|
||||
// Assert.IsTrue(type.IsAssignableFrom(statement.GetType()), String.Format("Parsed statement was {0} instead of {1} ({2})", statement.GetType(), type, statement));
|
||||
// return (T)statement;
|
||||
// }
|
||||
//
|
||||
// public static void AssertStatement(string code, VB.Ast.Statement expectedStmt)
|
||||
// {
|
||||
// var stmt = ParseStatement<VB.Ast.Statement>(code);
|
||||
// if (!expectedStmt.IsMatch(stmt)) {
|
||||
// Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedStmt), ToCSharp(stmt));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static T ParseExpression<T>(string expr, bool expectErrors = false) where T : AstNode
|
||||
// {
|
||||
// VBParser parser = new VBParser();
|
||||
// AstNode parsedExpression = parser.ParseExpression(new StringReader(expr));
|
||||
//
|
||||
// Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
|
||||
// if (expectErrors && parsedExpression == null)
|
||||
// return default (T);
|
||||
// Type type = typeof(T);
|
||||
// Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression));
|
||||
// return (T)parsedExpression;
|
||||
// }
|
||||
//
|
||||
// public static void AssertExpression(string code, VB.Ast.Expression expectedExpr)
|
||||
// {
|
||||
// var expr = ParseExpression<CSharp.Expression>(code);
|
||||
// if (!expectedExpr.IsMatch(expr)) {
|
||||
// Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedExpr), ToCSharp(expr));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static T ParseTypeMember<T>(string expr, bool expectErrors = false) where T : AttributedNode
|
||||
// {
|
||||
// VBParser parser = new VBParser();
|
||||
// var members = parser.ParseTypeMembers(new StringReader(expr));
|
||||
//
|
||||
// Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
|
||||
//
|
||||
// AttributedNode m = members.Single();
|
||||
// Type type = typeof(T);
|
||||
// Assert.IsTrue(type.IsAssignableFrom(m.GetType()), String.Format("Parsed member was {0} instead of {1} ({2})", m.GetType(), type, m));
|
||||
// return (T)m;
|
||||
// }
|
||||
//
|
||||
// public static void AssertTypeMember(string code, VB.Ast.AttributedNode expectedMember)
|
||||
// {
|
||||
// var member = ParseTypeMember<VB.Ast.AttributedNode>(code);
|
||||
// if (!expectedMember.IsMatch(member)) {
|
||||
// Assert.Fail("Expected '{0}' but was '{1}'", ToVB(expectedMember), ToVB(member));
|
||||
// }
|
||||
// }
|
||||
|
||||
static string ToVB(AstNode node) |
||||
{ |
||||
StringWriter w = new StringWriter(); |
||||
node.AcceptVisitor(new OutputVisitor(w, new VBFormattingOptions()), null); |
||||
return w.ToString(); |
||||
} |
||||
} |
||||
} |
||||
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using System; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class SnippetParserTests |
||||
{ |
||||
// [Test]
|
||||
// public void InvalidExpressionSyntax()
|
||||
// {
|
||||
// // SD2-1584: ensure we don't crash on this invalid VB code
|
||||
// SnippetParser parser = new SnippetParser();
|
||||
// INode node = parser.Parse("i == 5");
|
||||
// Assert.IsTrue(parser.Errors.Count > 0);
|
||||
// }
|
||||
} |
||||
} |
||||
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class AddHandlerStatementTests |
||||
{ |
||||
[Test] |
||||
public void AddHandlerTest() |
||||
{ |
||||
AddHandlerStatement addHandlerStatement = ParseUtil.ParseStatement<AddHandlerStatement>("AddHandler Obj.Ev_Event, AddressOf EventHandler"); |
||||
// TODO : extend tests
|
||||
} |
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class BlockStatementTests |
||||
{ |
||||
// TODO create BlockStatementTests
|
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ContinueStatementTests |
||||
{ |
||||
// TODO : add ContinueStatementTests
|
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class DoLoopStatementTests |
||||
{ |
||||
// TODO write some DoLoopStatement tests
|
||||
} |
||||
} |
||||
@ -1,29 +0,0 @@
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class EndStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetEndStatementTest() |
||||
{ |
||||
EndStatement endStatement = ParseUtil.ParseStatement<EndStatement>("End"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetEndStatementInIfThenTest2() |
||||
{ |
||||
IfElseStatement endStatement = ParseUtil.ParseStatement<IfElseStatement>("IF a THEN End"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class EraseStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetEraseStatementTest() |
||||
{ |
||||
EraseStatement eraseStatement = ParseUtil.ParseStatement<EraseStatement>("Erase a, b, c"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ErrorStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetErrorStatementTest() |
||||
{ |
||||
ErrorStatement errorStatement = ParseUtil.ParseStatement<ErrorStatement>("Error a"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ExpressionStatementTests |
||||
{ |
||||
// TODO : Create ExpressionStatementTests
|
||||
} |
||||
} |
||||
@ -1,29 +0,0 @@
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ForNextStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetForNextStatementTest() |
||||
{ |
||||
ForNextStatement forNextStatement = ParseUtil.ParseStatement<ForNextStatement>("For i=0 To 10 Step 2 : Next i"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetForNextStatementWithComplexExpressionTest() |
||||
{ |
||||
ForNextStatement forNextStatement = ParseUtil.ParseStatement<ForNextStatement>("For SomeMethod().Property = 0 To 10 : Next SomeMethod().Property"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ForeachStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetForeachStatementTest() |
||||
{ |
||||
ForeachStatement foreachStmt = ParseUtil.ParseStatement<ForeachStatement>("For Each i As Integer In myColl : Next"); |
||||
// TODO : Extend test.
|
||||
} |
||||
#endregion
|
||||
|
||||
} |
||||
} |
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class GotoStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetGotoStatementTest() |
||||
{ |
||||
GotoStatement gotoStmt = ParseUtil.ParseStatement<GotoStatement>("GoTo myLabel"); |
||||
Assert.AreEqual("myLabel", gotoStmt.Label); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,142 +0,0 @@
@@ -1,142 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class IfElseStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleIfStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN END"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement.Count == 1, "true count != 1:" + ifElseStatement.TrueStatement.Count); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement.Count == 0, "false count != 0:" + ifElseStatement.FalseStatement.Count); |
||||
|
||||
Assert.IsTrue(ifElseStatement.TrueStatement[0] is EndStatement, "Statement was: " + ifElseStatement.TrueStatement[0]); |
||||
} |
||||
[Test] |
||||
public void VBNetSimpleIfStatementTest2() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN\n END\n END IF"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement.Count == 1, "true count != 1:" + ifElseStatement.TrueStatement.Count); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement.Count == 0, "false count != 0:" + ifElseStatement.FalseStatement.Count); |
||||
|
||||
Assert.IsTrue(ifElseStatement.TrueStatement[0] is BlockStatement, "Statement was: " + ifElseStatement.TrueStatement[0]); |
||||
} |
||||
|
||||
// test for SD2-1201
|
||||
[Test] |
||||
public void VBNetIfStatementLocationTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN\n" + |
||||
"DoIt()\n" + |
||||
"ElseIf False Then\n" + |
||||
"DoIt()\n" + |
||||
"End If"); |
||||
Assert.AreEqual(3, (ifElseStatement.StartLocation).Line); |
||||
Assert.AreEqual(7, (ifElseStatement.EndLocation).Line); |
||||
Assert.AreEqual(5, (ifElseStatement.ElseIfSections[0].StartLocation).Line); |
||||
Assert.AreEqual(6, (ifElseStatement.ElseIfSections[0].EndLocation).Line); |
||||
Assert.IsNotNull(ifElseStatement.ElseIfSections[0].Parent); |
||||
|
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetElseIfStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN\n" + |
||||
"END\n" + |
||||
"ElseIf False Then\n" + |
||||
"Stop\n" + |
||||
"End If"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement.Count == 1, "true count != 1:" + ifElseStatement.TrueStatement.Count); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement.Count == 0, "false count != 0:" + ifElseStatement.FalseStatement.Count); |
||||
Assert.IsFalse((bool)(ifElseStatement.ElseIfSections[0].Condition as PrimitiveExpression).Value); |
||||
|
||||
Assert.IsTrue(ifElseStatement.TrueStatement[0] is BlockStatement, "Statement was: " + ifElseStatement.TrueStatement[0]); |
||||
Assert.IsTrue(ifElseStatement.ElseIfSections[0].EmbeddedStatement.Children[0] is StopStatement, "Statement was: " + ifElseStatement.ElseIfSections[0].EmbeddedStatement.Children[0]); |
||||
} |
||||
[Test] |
||||
public void VBNetElse_IfStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN\n" + |
||||
"END\n" + |
||||
"Else If False Then\n" + |
||||
"Stop\n" + |
||||
"End If"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement.Count == 1, "true count != 1:" + ifElseStatement.TrueStatement.Count); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement.Count == 0, "false count != 0:" + ifElseStatement.FalseStatement.Count); |
||||
Assert.IsFalse((bool)(ifElseStatement.ElseIfSections[0].Condition as PrimitiveExpression).Value); |
||||
|
||||
Assert.IsTrue(ifElseStatement.TrueStatement[0] is BlockStatement, "Statement was: " + ifElseStatement.TrueStatement[0]); |
||||
Assert.IsTrue(ifElseStatement.ElseIfSections[0].EmbeddedStatement.Children[0] is StopStatement, "Statement was: " + ifElseStatement.ElseIfSections[0].EmbeddedStatement.Children[0]); |
||||
} |
||||
[Test] |
||||
public void VBNetMultiStatementIfStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN Stop : b"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.AreEqual(2, ifElseStatement.TrueStatement.Count, "true count"); |
||||
Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); |
||||
|
||||
Assert.IsTrue(ifElseStatement.TrueStatement[0] is StopStatement); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement[1] is ExpressionStatement); |
||||
} |
||||
[Test] |
||||
public void VBNetMultiStatementIfStatementWithEndStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN Stop : End : b"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.AreEqual(3, ifElseStatement.TrueStatement.Count, "true count"); |
||||
Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); |
||||
|
||||
Assert.IsTrue(ifElseStatement.TrueStatement[0] is StopStatement); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement[1] is EndStatement); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement[2] is ExpressionStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetIfWithEmptyElseTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN a Else"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.AreEqual(1, ifElseStatement.TrueStatement.Count, "true count"); |
||||
Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetIfWithMultipleColons() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN a : : b"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.AreEqual(2, ifElseStatement.TrueStatement.Count, "true count"); |
||||
Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetIfWithSingleLineElse() |
||||
{ |
||||
// This isn't legal according to the VB spec, but the MS VB compiler seems to allow it.
|
||||
IfElseStatement ifElseStatement = ParseUtil.ParseStatement<IfElseStatement>("If True THEN\n" + |
||||
" x()\n" + |
||||
"Else y()\n" + |
||||
"End If"); |
||||
Assert.IsFalse(ifElseStatement.Condition.IsNull); |
||||
Assert.AreEqual(1, ifElseStatement.TrueStatement.Count, "true count"); |
||||
Assert.AreEqual(1, ifElseStatement.FalseStatement.Count, "false count"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class LabelStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetLabelStatementTest() |
||||
{ |
||||
MethodDeclaration method = ParseUtil.ParseTypeMember<MethodDeclaration>("Sub Test \n myLabel: Console.WriteLine() \n End Sub"); |
||||
Assert.AreEqual(2, method.Body.Children.Count); |
||||
LabelStatement labelStmt = (LabelStatement)method.Body.Children[0]; |
||||
Assert.AreEqual("myLabel", labelStmt.Label); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,204 +0,0 @@
@@ -1,204 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class LocalVariableDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetLocalVariableDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As Integer = 5"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables[0].Initializer).Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLocalVariableNamedOverrideDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim override As Integer = 5"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("override", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables[0].Initializer).Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLocalArrayDeclarationWithInitializationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a(10) As Integer"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(new int[] { 0 } , type.RankSpecifier); |
||||
ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer; |
||||
Assert.AreEqual(new int[] { 0 } , ace.CreateType.RankSpecifier); |
||||
Assert.AreEqual(1, ace.Arguments.Count); |
||||
Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLocalArrayDeclarationWithInitializationAndLowerBoundTest() |
||||
{ |
||||
// VB.NET allows only "0" as lower bound
|
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a(0 To 10) As Integer"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(new int[] { 0 } , type.RankSpecifier); |
||||
ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer; |
||||
Assert.AreEqual(new int[] { 0 } , ace.CreateType.RankSpecifier); |
||||
Assert.AreEqual(1, ace.Arguments.Count); |
||||
Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLocalArrayDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a() As Integer"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(new int[] { 0 } , type.RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetLocalJaggedArrayDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a(10)() As Integer"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(new int[] { 0, 0 } , type.RankSpecifier); |
||||
ArrayCreateExpression ace = (ArrayCreateExpression)lvd.Variables[0].Initializer; |
||||
Assert.AreEqual(new int[] {0, 0}, ace.CreateType.RankSpecifier); |
||||
Assert.AreEqual(1, ace.Arguments.Count); |
||||
Assert.AreEqual(10, ((PrimitiveExpression)ace.Arguments[0]).Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetComplexGenericLocalVariableDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim where As Generic(Of Printable, G(Of Printable()))"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("where", lvd.Variables[0].Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("Generic", type.Type); |
||||
Assert.AreEqual(2, type.GenericTypes.Count); |
||||
Assert.AreEqual("Printable", type.GenericTypes[0].Type); |
||||
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); |
||||
Assert.AreEqual("G", type.GenericTypes[1].Type); |
||||
Assert.AreEqual(1, type.GenericTypes[1].GenericTypes.Count); |
||||
Assert.AreEqual("Printable", type.GenericTypes[1].GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericWithArrayLocalVariableDeclarationTest1() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As G(Of Integer)()"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("G", type.Type); |
||||
Assert.AreEqual(1, type.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); |
||||
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); |
||||
Assert.IsFalse(type.GenericTypes[0].IsArrayType); |
||||
Assert.AreEqual(new int[] { 0 }, type.RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericWithArrayLocalVariableDeclarationTest2() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As G(Of Integer())"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("G", type.Type); |
||||
Assert.AreEqual(1, type.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); |
||||
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count); |
||||
Assert.IsFalse(type.IsArrayType); |
||||
Assert.AreEqual(1, type.GenericTypes[0].RankSpecifier.Length); |
||||
Assert.AreEqual(0, type.GenericTypes[0].RankSpecifier[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericLocalVariableDeclarationTest2() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As G(Of G(Of Integer))"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("G", type.Type); |
||||
Assert.AreEqual(1, type.GenericTypes.Count); |
||||
Assert.AreEqual("G", type.GenericTypes[0].Type); |
||||
Assert.AreEqual(1, type.GenericTypes[0].GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericLocalVariableDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As G(Of Integer)"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("G", type.Type); |
||||
Assert.AreEqual(1, type.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericLocalVariableInitializationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a As New G(Of Integer)"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("G", type.Type); |
||||
Assert.AreEqual(1, type.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); |
||||
// TODO: Check initializer
|
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetNestedGenericLocalVariableDeclarationTest() |
||||
{ |
||||
LocalVariableDeclaration lvd = ParseUtil.ParseStatement<LocalVariableDeclaration>("Dim a as MyType(of string).InnerClass(of integer).InnerInnerClass"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
InnerClassTypeReference ic = (InnerClassTypeReference)lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("InnerInnerClass", ic.Type); |
||||
Assert.AreEqual(0, ic.GenericTypes.Count); |
||||
ic = (InnerClassTypeReference)ic.BaseType; |
||||
Assert.AreEqual("InnerClass", ic.Type); |
||||
Assert.AreEqual(1, ic.GenericTypes.Count); |
||||
Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type); |
||||
Assert.AreEqual("MyType", ic.BaseType.Type); |
||||
Assert.AreEqual(1, ic.BaseType.GenericTypes.Count); |
||||
Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetDimInSingleLineIf() |
||||
{ |
||||
IfElseStatement ifes = ParseUtil.ParseStatement<IfElseStatement>("If a Then Dim b As String"); |
||||
LocalVariableDeclaration lvd = (LocalVariableDeclaration)ifes.TrueStatement[0]; |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.String", type.Type); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class LockStatementTests |
||||
{ |
||||
// TODO : write some tests on SyncLock
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OnErrorStatementTest |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetOnErrorStatementTest() |
||||
{ |
||||
OnErrorStatement onErrorStatement = ParseUtil.ParseStatement<OnErrorStatement>("On Error Goto err"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class RaiseEventStatementTest |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetRaiseEventStatementTest() |
||||
{ |
||||
RaiseEventStatement raiseEventStatement = ParseUtil.ParseStatement<RaiseEventStatement>("RaiseEvent MyEvent(a, 5, (6))"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ReDimStatementTests |
||||
{ |
||||
[Test] |
||||
public void VBNetReDimStatementTest() |
||||
{ |
||||
ReDimStatement reDimStatement = ParseUtil.ParseStatement<ReDimStatement>("ReDim Preserve MyArray(15)"); |
||||
Assert.AreEqual(1, reDimStatement.ReDimClauses.Count); |
||||
Assert.AreSame(reDimStatement, reDimStatement.ReDimClauses[0].Parent); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetReDimStatementTest2() |
||||
{ |
||||
ReDimStatement reDimStatement = ParseUtil.ParseStatement<ReDimStatement>("ReDim calCheckData(channelNum, lambdaNum).ShiftFromLastFullCalPixels(CalCheckPeak.HighWavelength)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetBigReDimStatementTest() |
||||
{ |
||||
string program = @"
|
||||
Class X |
||||
Sub x |
||||
ReDim sU(m - 1, n - 1) |
||||
ReDim sW(n - 1) |
||||
ReDim sV(n - 1, n - 1) |
||||
ReDim rv1(n - 1) |
||||
ReDim sMt(iNrCols - 1, 0) |
||||
ReDim Preserve sMt(iNrCols - 1, iRowNr) |
||||
ReDim sM(iRowNr - 1, iNrCols - 1) |
||||
If (IsNothing(ColLengths)) Then ReDim ColLengths(0) |
||||
If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1) |
||||
ReDim sTransform(2, iTransformType - 1) |
||||
ReDim Preserve _Items(_Count) |
||||
ReDim Preserve _Items(nCapacity) |
||||
ReDim Preserve _Items(0 To _Count) |
||||
ReDim Preserve _Items(0 To nCapacity) |
||||
ReDim sU(m - 1, n - 1) |
||||
ReDim sW(n - 1) |
||||
ReDim sV(n - 1, n - 1) |
||||
ReDim rv1(n - 1) |
||||
ReDim sMt(iNrCols - 1, 0) |
||||
ReDim Preserve sMt(iNrCols - 1, iRowNr) |
||||
ReDim sM(iRowNr - 1, iNrCols - 1) |
||||
If (IsNothing(ColLengths)) Then ReDim ColLengths(0) |
||||
If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1) |
||||
ReDim sTransform(2, iTransformType - 1) |
||||
ReDim Preserve Samples(Samples.GetUpperBound(0) + 1) |
||||
ReDim Samples(0) |
||||
ReDim BaseCssContent(BaseCssContentRows - 1) |
||||
ReDim mabtRxBuf(Bytes2Read - 1) |
||||
ReDim Preserve primarykey(primarykey.Length) |
||||
ReDim Preserve IntArray(10, 10, 15) |
||||
ReDim X(10, 10) |
||||
ReDim Preserve IntArray(0 To 10, 10, 0 To 20) |
||||
ReDim Preserve IntArray(10, 10, 15) |
||||
ReDim X(0 To 10, 0 To 10) |
||||
ReDim GetMe().IntArray(0 To 10, 10, 0 To 20) |
||||
ReDim GetMe(ExplicitParameter := 3).IntArray(0 To 10, 10, 0 To 20) |
||||
ReDim SomeType(Of Integer).IntArray(0 To 10, 10, 0 To 20) |
||||
End Sub |
||||
End Class";
|
||||
TypeDeclaration typeDeclaration = ParseUtil.ParseGlobal<TypeDeclaration>(program); |
||||
} |
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class RemoveHandlerStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetRemoveHandlerTest() |
||||
{ |
||||
RemoveHandlerStatement removeHandlerStatement = ParseUtil.ParseStatement<RemoveHandlerStatement>("RemoveHandler MyHandler, AddressOf MyMethod"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ResumeStatementTests |
||||
{ |
||||
[Test] |
||||
public void ResumeStatementTest() |
||||
{ |
||||
ResumeStatement resumeStatement = ParseUtil.ParseStatement<ResumeStatement>("Resume"); |
||||
} |
||||
|
||||
// TODO : write some more
|
||||
} |
||||
} |
||||
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ReturnStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetEmptyReturnStatementTest() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtil.ParseStatement<ReturnStatement>("Return"); |
||||
Assert.IsTrue(returnStatement.Expression.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetReturnStatementTest() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtil.ParseStatement<ReturnStatement>("Return 5"); |
||||
Assert.IsFalse(returnStatement.Expression.IsNull); |
||||
Assert.IsTrue(returnStatement.Expression is PrimitiveExpression); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class StopStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetStopStatementTest() |
||||
{ |
||||
StopStatement stopStatement = ParseUtil.ParseStatement<StopStatement>("Stop"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,34 +0,0 @@
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class SwitchStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBSwitchStatementTest() |
||||
{ |
||||
SwitchStatement switchStmt = ParseUtil.ParseStatement<SwitchStatement>("Select Case a\n Case 4, 5\n Case 6\n Case Else\n End Select"); |
||||
Assert.AreEqual("a", ((SimpleNameExpression)switchStmt.SwitchExpression).Identifier); |
||||
// TODO: Extend test
|
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidVBSwitchStatementTest() |
||||
{ |
||||
SwitchStatement switchStmt = ParseUtil.ParseStatement<SwitchStatement>("Select Case a\n Case \n End Select", true); |
||||
Assert.AreEqual("a", ((SimpleNameExpression)switchStmt.SwitchExpression).Identifier); |
||||
SwitchSection sec = switchStmt.SwitchSections[0]; |
||||
Assert.AreEqual(0, sec.SwitchLabels.Count); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ThrowStatementTests |
||||
{ |
||||
// TODO : ThrowStatementTests
|
||||
} |
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class TryCatchStatementTests |
||||
{ |
||||
// TODO : TryCatchStatementTests
|
||||
} |
||||
} |
||||
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class UsingStatementTests |
||||
{ |
||||
[Test] |
||||
public void UsingStatement() |
||||
{ |
||||
string usingText = @"
|
||||
Using nf As New System.Drawing.Font(""Arial"", 12.0F, FontStyle.Bold) |
||||
c.Font = nf |
||||
c.Text = ""This is 12-point Arial bold"" |
||||
End Using";
|
||||
UsingStatement usingStmt = ParseUtil.ParseStatement<UsingStatement>(usingText); |
||||
// TODO : Extend test.
|
||||
} |
||||
[Test] |
||||
public void UsingStatement2() |
||||
{ |
||||
string usingText = @"
|
||||
Using nf As Font = New Font() |
||||
Bla(nf) |
||||
End Using";
|
||||
UsingStatement usingStmt = ParseUtil.ParseStatement<UsingStatement>(usingText); |
||||
// TODO : Extend test.
|
||||
} |
||||
[Test] |
||||
public void UsingStatement3() |
||||
{ |
||||
string usingText = @"
|
||||
Using nf As New Font(), nf2 As New List(Of Font)(), nf3 = Nothing |
||||
Bla(nf) |
||||
End Using";
|
||||
UsingStatement usingStmt = ParseUtil.ParseStatement<UsingStatement>(usingText); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class WithStatementTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetWithStatementTest() |
||||
{ |
||||
WithStatement withStatement = ParseUtil.ParseStatement<WithStatement>("With MyObj : End With"); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,34 +0,0 @@
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class ConstructorDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetConstructorDeclarationTest1() |
||||
{ |
||||
string program = @"Sub New()
|
||||
End Sub";
|
||||
ConstructorDeclaration cd = ParseUtil.ParseTypeMember<ConstructorDeclaration>(program); |
||||
Assert.IsTrue(cd.ConstructorInitializer.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetConstructorDeclarationTest2() |
||||
{ |
||||
ConstructorDeclaration cd = ParseUtil.ParseTypeMember<ConstructorDeclaration>("Sub New(x As Integer, Optional y As String) \nEnd Sub"); |
||||
Assert.AreEqual(2, cd.Parameters.Count); |
||||
Assert.AreEqual("System.Int32", cd.Parameters[0].TypeReference.Type); |
||||
Assert.AreEqual("System.String", cd.Parameters[1].TypeReference.Type); |
||||
Assert.AreEqual(ParameterModifiers.Optional, cd.Parameters[1].ParamModifier & ParameterModifiers.Optional); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class CustomEventTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetCustomEventsStatementTest() |
||||
{ |
||||
string code = @" Public Custom Event TestEvent As EventHandler
|
||||
AddHandler(ByVal value As EventHandler) |
||||
Handlers = CType([Delegate].Combine(Handlers, value), _ |
||||
EventHandler) |
||||
End AddHandler |
||||
|
||||
RemoveHandler(ByVal value as EventHandler) |
||||
Handlers = CType([Delegate].Remove(Handlers, value), _ |
||||
EventHandler) |
||||
End RemoveHandler |
||||
|
||||
RaiseEvent(ByVal sender As Object, ByVal e As EventArgs) |
||||
Dim TempHandlers As EventHandler = Handlers |
||||
|
||||
If TempHandlers IsNot Nothing Then |
||||
TempHandlers(sender, e) |
||||
End If |
||||
End RaiseEvent |
||||
End Event";
|
||||
EventDeclaration customEventDecl = ParseUtil.ParseTypeMember<EventDeclaration>(code); |
||||
Assert.IsNotNull(customEventDecl); |
||||
Assert.AreEqual("TestEvent", customEventDecl.Name); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,28 +0,0 @@
@@ -1,28 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class DeclareDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetDeclareDeclarationTest() |
||||
{ |
||||
string program = "Declare Ansi Function GetUserName Lib \"advapi32.dll\" Alias \"GetUserNameA\" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer\n"; |
||||
DeclareDeclaration dd = ParseUtil.ParseTypeMember<DeclareDeclaration>(program); |
||||
Assert.AreEqual("System.Int32", dd.TypeReference.Type); |
||||
Assert.AreEqual("GetUserName", dd.Name); |
||||
Assert.AreEqual("advapi32.dll", dd.Library); |
||||
Assert.AreEqual("GetUserNameA", dd.Alias); |
||||
Assert.AreEqual(CharsetModifier.Ansi, dd.Charset); |
||||
} |
||||
#endregion
|
||||
|
||||
} |
||||
} |
||||
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class EventDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleEventDeclarationTest() |
||||
{ |
||||
EventDeclaration ed = ParseUtil.ParseTypeMember<EventDeclaration>("event MyEvent(x as Integer)"); |
||||
Assert.AreEqual(1, ed.Parameters.Count); |
||||
Assert.AreEqual("MyEvent", ed.Name); |
||||
Assert.IsFalse(ed.HasAddRegion); |
||||
Assert.IsFalse(ed.HasRemoveRegion); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,74 +0,0 @@
@@ -1,74 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class FieldDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleFieldDeclarationTest() |
||||
{ |
||||
FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("myField As Integer(,,,)"); |
||||
Assert.AreEqual(1, fd.Fields.Count); |
||||
|
||||
Assert.AreEqual("System.Int32", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type); |
||||
Assert.AreEqual("System.Int32", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type); |
||||
Assert.AreEqual("myField", ((VariableDeclaration)fd.Fields[0]).Name); |
||||
Assert.AreEqual(new int[] { 3 } , ((VariableDeclaration)fd.Fields[0]).TypeReference.RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMultiFieldDeclarationTest() |
||||
{ |
||||
FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("a, b As String"); |
||||
Assert.AreEqual(2, fd.Fields.Count); |
||||
|
||||
Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type); |
||||
Assert.IsFalse(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType); |
||||
Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type); |
||||
Assert.IsFalse(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMultiFieldsOnSingleLineTest() |
||||
{ |
||||
string program = "Class TestClass : Dim a : Dim b : End Class"; |
||||
TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program); |
||||
|
||||
Assert.AreEqual(2, td.Children.Count); |
||||
Assert.IsTrue(td.Children[0] is FieldDeclaration); |
||||
Assert.IsTrue(td.Children[1] is FieldDeclaration); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMultiFieldDeclarationTest2() |
||||
{ |
||||
FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("Dim a, b() As String"); |
||||
Assert.AreEqual(2, fd.Fields.Count); |
||||
|
||||
Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type); |
||||
Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type); |
||||
Assert.IsFalse(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType); |
||||
Assert.IsTrue(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMultiFieldDeclarationTest3() |
||||
{ |
||||
FieldDeclaration fd = ParseUtil.ParseTypeMember<FieldDeclaration>("Dim a(), b As String"); |
||||
Assert.AreEqual(2, fd.Fields.Count); |
||||
|
||||
Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type); |
||||
Assert.AreEqual("System.String", ((VariableDeclaration)fd.Fields[1]).TypeReference.Type); |
||||
Assert.IsTrue(((VariableDeclaration)fd.Fields[0]).TypeReference.IsArrayType); |
||||
Assert.IsFalse(((VariableDeclaration)fd.Fields[1]).TypeReference.IsArrayType); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,199 +0,0 @@
@@ -1,199 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class MethodDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
|
||||
[Test] |
||||
public void VBNetDefiningPartialMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>(@"Partial Sub MyMethod()
|
||||
End Sub");
|
||||
Assert.AreEqual(0, md.Parameters.Count); |
||||
Assert.AreEqual("MyMethod", md.Name); |
||||
Assert.IsFalse(md.IsExtensionMethod); |
||||
Assert.AreEqual(Modifiers.Partial, md.Modifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMethodWithModifiersRegionTest() |
||||
{ |
||||
const string program = @"public shared sub MyMethod()
|
||||
OtherMethod() |
||||
end sub";
|
||||
|
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual(Modifiers.Public | Modifiers.Static, md.Modifier); |
||||
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y"); |
||||
Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y"); |
||||
Assert.AreEqual(2, md.StartLocation.Column, "StartLocation.X"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetFunctionMethodDeclarationTest() |
||||
{ |
||||
const string program = @"public function MyFunction() as Integer
|
||||
return 1 |
||||
end function";
|
||||
|
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual(Modifiers.Public, md.Modifier); |
||||
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y"); |
||||
Assert.AreEqual(2, md.StartLocation.Column, "StartLocation.X"); |
||||
Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSubroutineMethodDeclarationTest() |
||||
{ |
||||
const string program = @"public Sub MyMethod()
|
||||
OtherMethod() |
||||
end Sub";
|
||||
|
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual(Modifiers.Public, md.Modifier); |
||||
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y"); |
||||
Assert.AreEqual(2, md.StartLocation.Column, "StartLocation.X"); |
||||
Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericFunctionMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>("function MyMethod(Of T)(a As T) As Double\nEnd Function"); |
||||
Assert.AreEqual("System.Double", md.TypeReference.Type); |
||||
Assert.AreEqual(1, md.Parameters.Count); |
||||
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type); |
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); |
||||
|
||||
Assert.AreEqual(1, md.Templates.Count); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>("Function MyMethod(Of T)(a As T) As T\nEnd Function "); |
||||
Assert.AreEqual("T", md.TypeReference.Type); |
||||
Assert.AreEqual(1, md.Parameters.Count); |
||||
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type); |
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); |
||||
|
||||
Assert.AreEqual(1, md.Templates.Count); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericMethodDeclarationWithConstraintTest() |
||||
{ |
||||
string program = "Function MyMethod(Of T As { ISomeInterface })(a As T) As T\n End Function"; |
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual("T", md.TypeReference.Type); |
||||
Assert.AreEqual(1, md.Parameters.Count); |
||||
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type); |
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); |
||||
|
||||
Assert.AreEqual(1, md.Templates.Count); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
Assert.AreEqual(1, md.Templates[0].Bases.Count); |
||||
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetExtensionMethodDeclaration() |
||||
{ |
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>( |
||||
@"<Extension> _
|
||||
Sub Print(s As String) |
||||
Console.WriteLine(s) |
||||
End Sub");
|
||||
|
||||
Assert.AreEqual("Print", md.Name); |
||||
|
||||
// IsExtensionMethod is only valid for c#.
|
||||
// Assert.IsTrue(md.IsExtensionMethod);
|
||||
|
||||
Assert.AreEqual("s", md.Parameters[0].ParameterName); |
||||
Assert.AreEqual("System.String", md.Parameters[0].TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericMethodInInterface() |
||||
{ |
||||
const string program = @"Interface MyInterface
|
||||
Function MyMethod(Of T As {ISomeInterface})(a As T) As T |
||||
End Interface";
|
||||
TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program); |
||||
MethodDeclaration md = (MethodDeclaration)td.Children[0]; |
||||
Assert.AreEqual("T", md.TypeReference.Type); |
||||
Assert.AreEqual(1, md.Parameters.Count); |
||||
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type); |
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); |
||||
|
||||
Assert.AreEqual(1, md.Templates.Count); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
Assert.AreEqual(1, md.Templates[0].Bases.Count); |
||||
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetGenericVoidMethodInInterface() |
||||
{ |
||||
const string program = @"interface MyInterface
|
||||
Sub MyMethod(Of T As {ISomeInterface})(a as T) |
||||
End Interface |
||||
";
|
||||
TypeDeclaration td = ParseUtil.ParseGlobal<TypeDeclaration>(program); |
||||
MethodDeclaration md = (MethodDeclaration)td.Children[0]; |
||||
Assert.AreEqual("System.Void", md.TypeReference.Type); |
||||
Assert.AreEqual(1, md.Parameters.Count); |
||||
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type); |
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName); |
||||
|
||||
Assert.AreEqual(1, md.Templates.Count); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
Assert.AreEqual(1, md.Templates[0].Bases.Count); |
||||
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMethodWithHandlesClause() |
||||
{ |
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>( |
||||
@"Public Sub MyMethod(sender As Object, e As EventArgs) Handles x.y
|
||||
End Sub");
|
||||
Assert.AreEqual(new string[] { "x.y" }, md.HandlesClause.ToArray()); |
||||
|
||||
md = ParseUtil.ParseTypeMember<MethodDeclaration>( |
||||
@"Public Sub MyMethod() Handles Me.FormClosing
|
||||
End Sub");
|
||||
Assert.AreEqual(new string[] { "Me.FormClosing" }, md.HandlesClause.ToArray()); |
||||
|
||||
md = ParseUtil.ParseTypeMember<MethodDeclaration>( |
||||
@"Public Sub MyMethod() Handles MyBase.Event, Button1.Click
|
||||
End Sub");
|
||||
Assert.AreEqual(new string[] { "MyBase.Event", "Button1.Click" }, md.HandlesClause.ToArray()); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetMethodWithTypeCharactersTest() |
||||
{ |
||||
const string program = @"Public Function Func!(ByVal Param&)
|
||||
Func! = CSingle(Param&) |
||||
End Function";
|
||||
|
||||
MethodDeclaration md = ParseUtil.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual(Modifiers.Public, md.Modifier); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OperatorDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
|
||||
[Test] |
||||
public void VBNetImplictOperatorDeclarationTest() |
||||
{ |
||||
string programm = @"Public Shared Operator + (ByVal v As Complex) As Complex
|
||||
Return v |
||||
End Operator";
|
||||
|
||||
OperatorDeclaration od = ParseUtil.ParseTypeMember<OperatorDeclaration>(programm); |
||||
Assert.IsFalse(od.IsConversionOperator); |
||||
Assert.AreEqual(1, od.Parameters.Count); |
||||
Assert.AreEqual(ConversionType.None, od.ConversionType); |
||||
Assert.AreEqual("Complex", od.TypeReference.Type); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,107 +0,0 @@
@@ -1,107 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class PropertyDeclarationTests |
||||
{ |
||||
#region VB.NET
|
||||
[Test] |
||||
public void VBNetSimpleGetSetPropertyDeclarationTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer \n Get \n End Get \n Set \n End Set\nEnd Property"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleGetPropertyDeclarationTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty \nGet\nEnd Get\nEnd Property"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsFalse(pd.HasSetRegion); |
||||
Assert.IsTrue((pd.Modifier & Modifiers.ReadOnly) == Modifiers.ReadOnly); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleSetPropertyDeclarationTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty \n Set\nEnd Set\nEnd Property "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
Assert.IsTrue((pd.Modifier & Modifiers.WriteOnly) == Modifiers.WriteOnly); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetAutoPropertyTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
Assert.AreEqual(pd.Initializer, Expression.Null); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetReadOnlyAutoPropertyTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("ReadOnly Property MyProperty"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsFalse(pd.HasSetRegion); |
||||
Assert.AreEqual(pd.Initializer, Expression.Null); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetWriteOnlyAutoPropertyTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("WriteOnly Property MyProperty"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
Assert.AreEqual(pd.Initializer, Expression.Null); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleInitializerAutoPropertyTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty = 5"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleInitializerAutoPropertyWithTypeTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As Integer = 5"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.AreEqual("System.Int32", pd.TypeReference.Type); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
Assert.AreEqual(pd.Initializer.ToString(), new PrimitiveExpression(5).ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetSimpleObjectInitializerAutoPropertyTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtil.ParseTypeMember<PropertyDeclaration>("Property MyProperty As New List"); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.AreEqual("List", pd.TypeReference.Type); |
||||
Assert.IsTrue(pd.HasGetRegion); |
||||
Assert.IsTrue(pd.HasSetRegion); |
||||
Assert.AreEqual(pd.Initializer.ToString(), new ObjectCreateExpression(new TypeReference("List"), null).ToString()); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,559 +0,0 @@
@@ -1,559 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public abstract class AstNode : AbstractAnnotatable, PatternMatching.INode |
||||
{ |
||||
#region Null
|
||||
public static readonly AstNode Null = new NullAstNode (); |
||||
|
||||
sealed class NullAstNode : AstNode |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator AstNode(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : AstNode, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
AstNode parent; |
||||
AstNode prevSibling; |
||||
AstNode nextSibling; |
||||
AstNode firstChild; |
||||
AstNode lastChild; |
||||
Role role = RootRole; |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public virtual TextLocation StartLocation { |
||||
get { |
||||
var child = firstChild; |
||||
if (child == null) |
||||
return TextLocation.Empty; |
||||
return child.StartLocation; |
||||
} |
||||
} |
||||
|
||||
public virtual TextLocation EndLocation { |
||||
get { |
||||
var child = lastChild; |
||||
if (child == null) |
||||
return TextLocation.Empty; |
||||
return child.EndLocation; |
||||
} |
||||
} |
||||
|
||||
public AstNode Parent { |
||||
get { return parent; } |
||||
} |
||||
|
||||
public Role Role { |
||||
get { return role; } |
||||
} |
||||
|
||||
public AstNode NextSibling { |
||||
get { return nextSibling; } |
||||
} |
||||
|
||||
public AstNode PrevSibling { |
||||
get { return prevSibling; } |
||||
} |
||||
|
||||
public AstNode FirstChild { |
||||
get { return firstChild; } |
||||
} |
||||
|
||||
public AstNode LastChild { |
||||
get { return lastChild; } |
||||
} |
||||
|
||||
public IEnumerable<AstNode> Children { |
||||
get { |
||||
AstNode next; |
||||
for (AstNode cur = firstChild; cur != null; cur = next) { |
||||
Debug.Assert(cur.parent == this); |
||||
// Remember next before yielding cur.
|
||||
// This allows removing/replacing nodes while iterating through the list.
|
||||
next = cur.nextSibling; |
||||
yield return cur; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the ancestors of this node (excluding this node itself)
|
||||
/// </summary>
|
||||
public IEnumerable<AstNode> Ancestors { |
||||
get { |
||||
for (AstNode cur = parent; cur != null; cur = cur.parent) { |
||||
yield return cur; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all descendants of this node (excluding this node itself).
|
||||
/// </summary>
|
||||
public IEnumerable<AstNode> Descendants { |
||||
get { |
||||
return Utils.TreeTraversal.PreOrder(this.Children, n => n.Children); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all descendants of this node (including this node itself).
|
||||
/// </summary>
|
||||
public IEnumerable<AstNode> DescendantsAndSelf { |
||||
get { |
||||
return Utils.TreeTraversal.PreOrder(this, n => n.Children); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the first child with the specified role.
|
||||
/// Returns the role's null object if the child is not found.
|
||||
/// </summary>
|
||||
public T GetChildByRole<T>(Role<T> role) where T : AstNode |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
for (var cur = firstChild; cur != null; cur = cur.nextSibling) { |
||||
if (cur.role == role) |
||||
return (T)cur; |
||||
} |
||||
return role.NullObject; |
||||
} |
||||
|
||||
public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode |
||||
{ |
||||
return new AstNodeCollection<T>(this, role); |
||||
} |
||||
|
||||
protected void SetChildByRole<T>(Role<T> role, T newChild) where T : AstNode |
||||
{ |
||||
AstNode oldChild = GetChildByRole(role); |
||||
if (oldChild.IsNull) |
||||
AddChild(newChild, role); |
||||
else |
||||
oldChild.ReplaceWith(newChild); |
||||
} |
||||
|
||||
public void AddChild<T>(T child, Role<T> role) where T : AstNode |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
if (child == null || child.IsNull) |
||||
return; |
||||
if (this.IsNull) |
||||
throw new InvalidOperationException("Cannot add children to null nodes"); |
||||
if (child.parent != null) |
||||
throw new ArgumentException ("Node is already used in another tree.", "child"); |
||||
AddChildUnsafe(child, role); |
||||
} |
||||
|
||||
internal void AddChildUntyped(AstNode child, Role role) |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
if (child == null || child.IsNull) |
||||
return; |
||||
if (this.IsNull) |
||||
throw new InvalidOperationException("Cannot add children to null nodes"); |
||||
if (child.parent != null) |
||||
throw new ArgumentException ("Node is already used in another tree.", "child"); |
||||
AddChildUnsafe(child, role); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a child without performing any safety checks.
|
||||
/// </summary>
|
||||
void AddChildUnsafe(AstNode child, Role role) |
||||
{ |
||||
child.parent = this; |
||||
child.role = role; |
||||
if (firstChild == null) { |
||||
lastChild = firstChild = child; |
||||
} else { |
||||
lastChild.nextSibling = child; |
||||
child.prevSibling = lastChild; |
||||
lastChild = child; |
||||
} |
||||
} |
||||
|
||||
public void InsertChildBefore<T>(AstNode nextSibling, T child, Role<T> role) where T : AstNode |
||||
{ |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
if (nextSibling == null || nextSibling.IsNull) { |
||||
AddChild(child, role); |
||||
return; |
||||
} |
||||
|
||||
if (child == null || child.IsNull) |
||||
return; |
||||
if (child.parent != null) |
||||
throw new ArgumentException ("Node is already used in another tree.", "child"); |
||||
if (nextSibling.parent != this) |
||||
throw new ArgumentException ("NextSibling is not a child of this node.", "nextSibling"); |
||||
// No need to test for "Cannot add children to null nodes",
|
||||
// as there isn't any valid nextSibling in null nodes.
|
||||
InsertChildBeforeUnsafe(nextSibling, child, role); |
||||
} |
||||
|
||||
|
||||
void InsertChildBeforeUnsafe(AstNode nextSibling, AstNode child, Role role) |
||||
{ |
||||
child.parent = this; |
||||
child.role = role; |
||||
child.nextSibling = nextSibling; |
||||
child.prevSibling = nextSibling.prevSibling; |
||||
|
||||
if (nextSibling.prevSibling != null) { |
||||
Debug.Assert(nextSibling.prevSibling.nextSibling == nextSibling); |
||||
nextSibling.prevSibling.nextSibling = child; |
||||
} else { |
||||
Debug.Assert(firstChild == nextSibling); |
||||
firstChild = child; |
||||
} |
||||
nextSibling.prevSibling = child; |
||||
} |
||||
|
||||
public void InsertChildAfter<T>(AstNode prevSibling, T child, Role<T> role) where T : AstNode |
||||
{ |
||||
InsertChildBefore((prevSibling == null || prevSibling.IsNull) ? firstChild : prevSibling.nextSibling, child, role); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes this node from its parent.
|
||||
/// </summary>
|
||||
public void Remove() |
||||
{ |
||||
if (parent != null) { |
||||
if (prevSibling != null) { |
||||
Debug.Assert(prevSibling.nextSibling == this); |
||||
prevSibling.nextSibling = nextSibling; |
||||
} else { |
||||
Debug.Assert(parent.firstChild == this); |
||||
parent.firstChild = nextSibling; |
||||
} |
||||
if (nextSibling != null) { |
||||
Debug.Assert(nextSibling.prevSibling == this); |
||||
nextSibling.prevSibling = prevSibling; |
||||
} else { |
||||
Debug.Assert(parent.lastChild == this); |
||||
parent.lastChild = prevSibling; |
||||
} |
||||
parent = null; |
||||
role = Roles.Root; |
||||
prevSibling = null; |
||||
nextSibling = null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Replaces this node with the new node.
|
||||
/// </summary>
|
||||
public void ReplaceWith(AstNode newNode) |
||||
{ |
||||
if (newNode == null || newNode.IsNull) { |
||||
Remove(); |
||||
return; |
||||
} |
||||
if (newNode == this) |
||||
return; // nothing to do...
|
||||
if (parent == null) { |
||||
throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); |
||||
} |
||||
// Because this method doesn't statically check the new node's type with the role,
|
||||
// we perform a runtime test:
|
||||
if (!role.IsValid(newNode)) { |
||||
throw new ArgumentException (string.Format("The new node '{0}' is not valid in the role {1}", newNode.GetType().Name, role.ToString()), "newNode"); |
||||
} |
||||
if (newNode.parent != null) { |
||||
// newNode is used within this tree?
|
||||
if (newNode.Ancestors.Contains(this)) { |
||||
// e.g. "parenthesizedExpr.ReplaceWith(parenthesizedExpr.Expression);"
|
||||
// enable automatic removal
|
||||
newNode.Remove(); |
||||
} else { |
||||
throw new ArgumentException ("Node is already used in another tree.", "newNode"); |
||||
} |
||||
} |
||||
|
||||
newNode.parent = parent; |
||||
newNode.role = role; |
||||
newNode.prevSibling = prevSibling; |
||||
newNode.nextSibling = nextSibling; |
||||
if (parent != null) { |
||||
if (prevSibling != null) { |
||||
Debug.Assert(prevSibling.nextSibling == this); |
||||
prevSibling.nextSibling = newNode; |
||||
} else { |
||||
Debug.Assert(parent.firstChild == this); |
||||
parent.firstChild = newNode; |
||||
} |
||||
if (nextSibling != null) { |
||||
Debug.Assert(nextSibling.prevSibling == this); |
||||
nextSibling.prevSibling = newNode; |
||||
} else { |
||||
Debug.Assert(parent.lastChild == this); |
||||
parent.lastChild = newNode; |
||||
} |
||||
parent = null; |
||||
prevSibling = null; |
||||
nextSibling = null; |
||||
role = Roles.Root; |
||||
} |
||||
} |
||||
|
||||
public AstNode ReplaceWith(Func<AstNode, AstNode> replaceFunction) |
||||
{ |
||||
if (replaceFunction == null) |
||||
throw new ArgumentNullException("replaceFunction"); |
||||
if (parent == null) { |
||||
throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); |
||||
} |
||||
AstNode oldParent = parent; |
||||
AstNode oldSuccessor = nextSibling; |
||||
Role oldRole = role; |
||||
Remove(); |
||||
AstNode replacement = replaceFunction(this); |
||||
if (oldSuccessor != null && oldSuccessor.parent != oldParent) |
||||
throw new InvalidOperationException("replace function changed nextSibling of node being replaced?"); |
||||
if (!(replacement == null || replacement.IsNull)) { |
||||
if (replacement.parent != null) |
||||
throw new InvalidOperationException("replace function must return the root of a tree"); |
||||
if (!oldRole.IsValid(replacement)) { |
||||
throw new InvalidOperationException (string.Format("The new node '{0}' is not valid in the role {1}", replacement.GetType().Name, oldRole.ToString())); |
||||
} |
||||
|
||||
if (oldSuccessor != null) |
||||
oldParent.InsertChildBeforeUnsafe(oldSuccessor, replacement, oldRole); |
||||
else |
||||
oldParent.AddChildUnsafe(replacement, oldRole); |
||||
} |
||||
return replacement; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Clones the whole subtree starting at this AST node.
|
||||
/// </summary>
|
||||
/// <remarks>Annotations are copied over to the new nodes; and any annotations implementating ICloneable will be cloned.</remarks>
|
||||
public AstNode Clone() |
||||
{ |
||||
AstNode copy = (AstNode)MemberwiseClone(); |
||||
// First, reset the shallow pointer copies
|
||||
copy.parent = null; |
||||
copy.role = Roles.Root; |
||||
copy.firstChild = null; |
||||
copy.lastChild = null; |
||||
copy.prevSibling = null; |
||||
copy.nextSibling = null; |
||||
|
||||
// Then perform a deep copy:
|
||||
for (AstNode cur = firstChild; cur != null; cur = cur.nextSibling) { |
||||
copy.AddChildUnsafe(cur.Clone(), cur.role); |
||||
} |
||||
|
||||
// Finally, clone the annotation, if necessary
|
||||
copy.CloneAnnotations(); |
||||
|
||||
return copy; |
||||
} |
||||
|
||||
public override void AddAnnotation (object annotation) |
||||
{ |
||||
if (this.IsNull) |
||||
throw new InvalidOperationException("Cannot add annotations to the null node"); |
||||
base.AddAnnotation (annotation); |
||||
} |
||||
|
||||
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data); |
||||
|
||||
#region Pattern Matching
|
||||
protected static bool MatchString(string name1, string name2) |
||||
{ |
||||
return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase); |
||||
} |
||||
|
||||
protected static bool MatchStringXml(string name1, string name2) |
||||
{ |
||||
return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.Ordinal); |
||||
} |
||||
|
||||
protected internal abstract bool DoMatch(AstNode other, PatternMatching.Match match); |
||||
|
||||
bool PatternMatching.INode.DoMatch(PatternMatching.INode other, PatternMatching.Match match) |
||||
{ |
||||
AstNode o = other as AstNode; |
||||
// try matching if other is null, or if other is an AstNode
|
||||
return (other == null || o != null) && DoMatch(o, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
AstNode o = pos as AstNode; |
||||
return (pos == null || o != null) && DoMatch (o, match); |
||||
} |
||||
|
||||
PatternMatching.INode PatternMatching.INode.NextSibling { |
||||
get { return nextSibling; } |
||||
} |
||||
|
||||
PatternMatching.INode PatternMatching.INode.FirstChild { |
||||
get { return firstChild; } |
||||
} |
||||
#endregion
|
||||
|
||||
public AstNode GetNextNode () |
||||
{ |
||||
if (NextSibling != null) |
||||
return NextSibling; |
||||
if (Parent != null) |
||||
return Parent.GetNextNode (); |
||||
return null; |
||||
} |
||||
|
||||
public AstNode GetPrevNode () |
||||
{ |
||||
if (PrevSibling != null) |
||||
return PrevSibling; |
||||
if (Parent != null) |
||||
return Parent.GetPrevNode (); |
||||
return null; |
||||
} |
||||
|
||||
// filters all non VB nodes (comments, white spaces or pre processor directives)
|
||||
public AstNode GetVBNodeBefore (AstNode node) |
||||
{ |
||||
var n = node.PrevSibling; |
||||
while (n != null) { |
||||
if (n.Role != Roles.Comment) |
||||
return n; |
||||
n = n.GetPrevNode (); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
|
||||
static readonly Role<AstNode> RootRole = new Role<AstNode>("Root"); |
||||
|
||||
public static class Roles |
||||
{ |
||||
/// <summary>
|
||||
/// Root of an abstract syntax tree.
|
||||
/// </summary>
|
||||
public static readonly Role<AstNode> Root = RootRole; |
||||
|
||||
// some pre defined constants for common roles
|
||||
public static readonly Role<Identifier> Identifier = new Role<Identifier>("Identifier", Ast.Identifier.Null); |
||||
public static readonly Role<XmlIdentifier> XmlIdentifier = new Role<XmlIdentifier>("XmlIdentifier", Ast.XmlIdentifier.Null); |
||||
public static readonly Role<XmlLiteralString> XmlLiteralString = new Role<XmlLiteralString>("XmlLiteralString", Ast.XmlLiteralString.Null); |
||||
|
||||
public static readonly Role<BlockStatement> Body = new Role<BlockStatement>("Body", Ast.BlockStatement.Null); |
||||
public static readonly Role<ParameterDeclaration> Parameter = new Role<ParameterDeclaration>("Parameter"); |
||||
public static readonly Role<Expression> Argument = new Role<Expression>("Argument", Ast.Expression.Null); |
||||
public static readonly Role<AstType> Type = new Role<AstType>("Type", AstType.Null); |
||||
public static readonly Role<Expression> Expression = new Role<Expression>("Expression", Ast.Expression.Null); |
||||
public static readonly Role<Expression> TargetExpression = new Role<Expression>("Target", Ast.Expression.Null); |
||||
public readonly static Role<Expression> Condition = new Role<Expression>("Condition", Ast.Expression.Null); |
||||
//
|
||||
public static readonly Role<TypeParameterDeclaration> TypeParameter = new Role<TypeParameterDeclaration>("TypeParameter"); |
||||
public static readonly Role<AstType> TypeArgument = new Role<AstType>("TypeArgument", AstType.Null); |
||||
// public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer>("Variable");
|
||||
// public static readonly Role<Statement> EmbeddedStatement = new Role<Statement>("EmbeddedStatement", CSharp.Statement.Null);
|
||||
//
|
||||
public static readonly Role<VBTokenNode> Keyword = new Role<VBTokenNode>("Keyword", VBTokenNode.Null); |
||||
// public static readonly Role<VBTokenNode> InKeyword = new Role<VBTokenNode>("InKeyword", VBTokenNode.Null);
|
||||
|
||||
// some pre defined constants for most used punctuation
|
||||
public static readonly Role<VBTokenNode> LPar = new Role<VBTokenNode>("LPar", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RPar = new Role<VBTokenNode>("RPar", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> LBracket = new Role<VBTokenNode>("LBracket", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RBracket = new Role<VBTokenNode>("RBracket", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> LBrace = new Role<VBTokenNode>("LBrace", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RBrace = new Role<VBTokenNode>("RBrace", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> LChevron = new Role<VBTokenNode>("LChevron", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> RChevron = new Role<VBTokenNode>("RChevron", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Comma = new Role<VBTokenNode>("Comma", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> QuestionMark = new Role<VBTokenNode>("QuestionMark", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Dot = new Role<VBTokenNode>("Dot", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Semicolon = new Role<VBTokenNode>("Semicolon", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Assign = new Role<VBTokenNode>("Assign", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> Colon = new Role<VBTokenNode>("Colon", VBTokenNode.Null); |
||||
public static readonly Role<VBTokenNode> StatementTerminator = new Role<VBTokenNode>("StatementTerminator", VBTokenNode.Null); |
||||
|
||||
// XML
|
||||
/// <summary>
|
||||
/// Text: <
|
||||
/// </summary>
|
||||
public static readonly Role<VBTokenNode> XmlOpenTag = new Role<VBTokenNode>("XmlOpenTag", VBTokenNode.Null); |
||||
/// <summary>
|
||||
/// Text: >
|
||||
/// </summary>
|
||||
public static readonly Role<VBTokenNode> XmlCloseTag = new Role<VBTokenNode>("XmlOpenTag", VBTokenNode.Null); |
||||
|
||||
public static readonly Role<Comment> Comment = new Role<Comment>("Comment"); |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -1,199 +0,0 @@
@@ -1,199 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the children of an AstNode that have a specific role.
|
||||
/// </summary>
|
||||
public class AstNodeCollection<T> : ICollection<T> where T : AstNode |
||||
{ |
||||
readonly AstNode node; |
||||
readonly Role<T> role; |
||||
|
||||
public AstNodeCollection(AstNode node, Role<T> role) |
||||
{ |
||||
if (node == null) |
||||
throw new ArgumentNullException("node"); |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
this.node = node; |
||||
this.role = role; |
||||
} |
||||
|
||||
public int Count { |
||||
get { |
||||
int count = 0; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = cur.NextSibling) { |
||||
if (cur.Role == role) |
||||
count++; |
||||
} |
||||
return count; |
||||
} |
||||
} |
||||
|
||||
public void Add(T element) |
||||
{ |
||||
node.AddChild(element, role); |
||||
} |
||||
|
||||
public void AddRange(IEnumerable<T> nodes) |
||||
{ |
||||
// Evaluate 'nodes' first, since it might change when we add the new children
|
||||
// Example: collection.AddRange(collection);
|
||||
if (nodes != null) { |
||||
foreach (T node in nodes.ToList()) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void AddRange(T[] nodes) |
||||
{ |
||||
// Fast overload for arrays - we don't need to create a copy
|
||||
if (nodes != null) { |
||||
foreach (T node in nodes) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void ReplaceWith(IEnumerable<T> nodes) |
||||
{ |
||||
// Evaluate 'nodes' first, since it might change when we call Clear()
|
||||
// Example: collection.ReplaceWith(collection);
|
||||
if (nodes != null) |
||||
nodes = nodes.ToList(); |
||||
Clear(); |
||||
foreach (T node in nodes) |
||||
Add(node); |
||||
} |
||||
|
||||
public void MoveTo(ICollection<T> targetCollection) |
||||
{ |
||||
foreach (T node in this) { |
||||
node.Remove(); |
||||
targetCollection.Add(node); |
||||
} |
||||
} |
||||
|
||||
public bool Contains(T element) |
||||
{ |
||||
return element != null && element.Parent == node && element.Role == role; |
||||
} |
||||
|
||||
public bool Remove(T element) |
||||
{ |
||||
if (Contains(element)) { |
||||
element.Remove(); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public void CopyTo(T[] array, int arrayIndex) |
||||
{ |
||||
foreach (T item in this) |
||||
array[arrayIndex++] = item; |
||||
} |
||||
|
||||
public void Clear() |
||||
{ |
||||
foreach (T item in this) |
||||
item.Remove(); |
||||
} |
||||
|
||||
bool ICollection<T>.IsReadOnly { |
||||
get { return false; } |
||||
} |
||||
|
||||
public IEnumerator<T> GetEnumerator() |
||||
{ |
||||
AstNode next; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = next) { |
||||
Debug.Assert(cur.Parent == node); |
||||
// Remember next before yielding cur.
|
||||
// This allows removing/replacing nodes while iterating through the list.
|
||||
next = cur.NextSibling; |
||||
if (cur.Role == role) |
||||
yield return (T)cur; |
||||
} |
||||
} |
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return GetEnumerator(); |
||||
} |
||||
|
||||
#region Equals and GetHashCode implementation
|
||||
public override int GetHashCode() |
||||
{ |
||||
return node.GetHashCode() ^ role.GetHashCode(); |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
AstNodeCollection<T> other = obj as AstNodeCollection<T>; |
||||
if (other == null) |
||||
return false; |
||||
return this.node == other.node && this.role == other.role; |
||||
} |
||||
#endregion
|
||||
|
||||
internal bool DoMatch(AstNodeCollection<T> other, Match match) |
||||
{ |
||||
// TODO : does not compile (ask Daniel)!
|
||||
// Stack<AstNode> patternStack = new Stack<AstNode>();
|
||||
// Stack<Pattern.PossibleMatch> stack = new Stack<Pattern.PossibleMatch>();
|
||||
// patternStack.Push(this.node.FirstChild);
|
||||
// stack.Push(new Pattern.PossibleMatch(other.node.FirstChild, match.CheckPoint()));
|
||||
// while (stack.Count > 0) {
|
||||
// AstNode cur1 = patternStack.Pop();
|
||||
// AstNode cur2 = stack.Peek().NextOther;
|
||||
// match.RestoreCheckPoint(stack.Pop().Checkpoint);
|
||||
// bool success = true;
|
||||
// while (cur1 != null && success) {
|
||||
// while (cur1 != null && cur1.Role != role)
|
||||
// cur1 = cur1.NextSibling;
|
||||
// while (cur2 != null && cur2.Role != role)
|
||||
// cur2 = cur2.NextSibling;
|
||||
// if (cur1 == null)
|
||||
// break;
|
||||
//
|
||||
// Debug.Assert(stack.Count == patternStack.Count);
|
||||
// success = cur1.DoMatchCollection(role, cur2, match, stack);
|
||||
// Debug.Assert(stack.Count >= patternStack.Count);
|
||||
// while (stack.Count > patternStack.Count)
|
||||
// patternStack.Push(cur1.NextSibling);
|
||||
//
|
||||
// cur1 = cur1.NextSibling;
|
||||
// if (cur2 != null)
|
||||
// cur2 = cur2.NextSibling;
|
||||
// }
|
||||
// while (cur2 != null && cur2.Role != role)
|
||||
// cur2 = cur2.NextSibling;
|
||||
// if (success && cur2 == null)
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void InsertAfter(T existingItem, T newItem) |
||||
{ |
||||
node.InsertChildAfter(existingItem, newItem, role); |
||||
} |
||||
|
||||
public void InsertBefore(T existingItem, T newItem) |
||||
{ |
||||
node.InsertChildBefore(existingItem, newItem, role); |
||||
} |
||||
} |
||||
} |
||||
@ -1,67 +0,0 @@
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public class Comment : AstNode |
||||
{ |
||||
public bool IsDocumentationComment { get; set; } |
||||
|
||||
public bool StartsLine { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public string Content { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
TextLocation endLocation; |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return endLocation; |
||||
} |
||||
} |
||||
|
||||
public Comment (string content, bool isDocumentation = false) |
||||
{ |
||||
this.IsDocumentationComment = isDocumentation; |
||||
this.Content = content; |
||||
} |
||||
|
||||
public Comment (bool isDocumentation, TextLocation startLocation, TextLocation endLocation) |
||||
{ |
||||
this.IsDocumentationComment = isDocumentation; |
||||
this.startLocation = startLocation; |
||||
this.endLocation = endLocation; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitComment(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
Comment o = other as Comment; |
||||
return o != null && this.IsDocumentationComment == o.IsDocumentationComment && MatchString(this.Content, o.Content); |
||||
} |
||||
} |
||||
} |
||||
@ -1,154 +0,0 @@
@@ -1,154 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
[Flags] |
||||
public enum Modifiers |
||||
{ |
||||
None = 0x0000, |
||||
|
||||
// Accessibility
|
||||
Private = 0x0001, |
||||
Friend = 0x0002, |
||||
Protected = 0x0004, |
||||
Public = 0x0008, |
||||
|
||||
// Scope
|
||||
MustInherit = 0x0010, // Types
|
||||
MustOverride = 0x0020, // Members
|
||||
Overridable = 0x0040, |
||||
NotInheritable = 0x0080, // Types
|
||||
NotOverridable = 0x0100, // Members
|
||||
Const = 0x0200, |
||||
Shared = 0x0400, |
||||
Static = 0x0800, |
||||
Overrides = 0x1000, |
||||
ReadOnly = 0x2000, |
||||
Shadows = 0x4000, |
||||
Partial = 0x8000, |
||||
|
||||
// Special
|
||||
Overloads = 0x10000, // VB specific
|
||||
WithEvents = 0x20000, // VB specific
|
||||
Default = 0x40000, // VB specific
|
||||
|
||||
Dim = 0x80000, // VB.NET SPECIFIC, for fields/local variables only
|
||||
|
||||
/// <summary>Only for VB properties.</summary>
|
||||
WriteOnly = 0x100000, // VB specific
|
||||
|
||||
ByVal = 0x200000, |
||||
ByRef = 0x400000, |
||||
ParamArray = 0x800000, |
||||
Optional = 0x1000000, |
||||
|
||||
Narrowing = 0x2000000, |
||||
Widening = 0x4000000, |
||||
|
||||
Iterator = 0x8000000, |
||||
Async = 0x10000000, |
||||
|
||||
/// <summary>
|
||||
/// Special value used to match any modifiers during pattern matching.
|
||||
/// </summary>
|
||||
Any = unchecked((int)0x80000000) |
||||
} |
||||
|
||||
public enum ParentType |
||||
{ |
||||
ClassOrStruct, |
||||
InterfaceOrEnum, |
||||
Namespace, |
||||
Unknown |
||||
} |
||||
|
||||
public enum FieldDirection |
||||
{ |
||||
None, |
||||
In, |
||||
Out, |
||||
Ref |
||||
} |
||||
|
||||
public enum AssignmentOperatorType |
||||
{ |
||||
None, |
||||
Assign, |
||||
|
||||
Add, |
||||
Subtract, |
||||
Multiply, |
||||
Divide, |
||||
|
||||
Power, // (VB only)
|
||||
DivideInteger, // (VB only)
|
||||
ConcatString, // (VB only)
|
||||
|
||||
ShiftLeft, |
||||
ShiftRight, |
||||
} |
||||
|
||||
public enum ContinueType |
||||
{ |
||||
None, |
||||
Do, |
||||
For, |
||||
While |
||||
} |
||||
|
||||
public enum ConditionType |
||||
{ |
||||
None, |
||||
LoopUntil, |
||||
LoopWhile, |
||||
DoUntil, |
||||
DoWhile |
||||
} |
||||
|
||||
public enum ConversionType |
||||
{ |
||||
None, |
||||
Implicit, |
||||
Explicit |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Specifies the ordering direction of a QueryExpressionOrdering node.
|
||||
/// </summary>
|
||||
public enum QueryOrderingDirection |
||||
{ |
||||
None, |
||||
Ascending, |
||||
Descending |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Specifies the partition type for a VB.NET
|
||||
/// query expression.
|
||||
/// </summary>
|
||||
public enum PartitionKind |
||||
{ |
||||
Take, |
||||
TakeWhile, |
||||
Skip, |
||||
SkipWhile |
||||
} |
||||
|
||||
public enum XmlAxisType |
||||
{ |
||||
Element, // .
|
||||
Attribute, // .@
|
||||
Descendents // ...
|
||||
} |
||||
|
||||
public enum XmlContentType |
||||
{ |
||||
Comment, |
||||
Text, |
||||
CData, |
||||
ProcessingInstruction |
||||
} |
||||
} |
||||
@ -1,41 +0,0 @@
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class AnonymousObjectCreationExpression : Expression |
||||
{ |
||||
public AstNodeCollection<Expression> Initializer { |
||||
get { return GetChildrenByRole(Roles.Expression); } |
||||
} |
||||
|
||||
public AnonymousObjectCreationExpression () |
||||
{ |
||||
} |
||||
|
||||
public AnonymousObjectCreationExpression (IEnumerable<Expression> initializer) |
||||
{ |
||||
foreach (var ini in initializer) { |
||||
AddChild (ini, Roles.Expression); |
||||
} |
||||
} |
||||
|
||||
public AnonymousObjectCreationExpression (params Expression[] initializer) : this ((IEnumerable<Expression>)initializer) |
||||
{ |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAnonymousObjectCreationExpression(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as AnonymousObjectCreationExpression; |
||||
return o != null && this.Initializer.DoMatch(o.Initializer, match); |
||||
} |
||||
} |
||||
} |
||||
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// New Type[Dimensions]
|
||||
/// </summary>
|
||||
public class ArrayCreateExpression : Expression |
||||
{ |
||||
public readonly static Role<ArraySpecifier> AdditionalArraySpecifierRole = new Role<ArraySpecifier>("AdditionalArraySpecifier"); |
||||
public readonly static Role<ArrayInitializerExpression> InitializerRole = new Role<ArrayInitializerExpression>("Initializer", ArrayInitializerExpression.Null); |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole (Roles.Argument); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets additional array ranks (those without size info).
|
||||
/// Empty for "New Integer(5,1)"; will contain a single element for "New Integer(5)()".
|
||||
/// </summary>
|
||||
public AstNodeCollection<ArraySpecifier> AdditionalArraySpecifiers { |
||||
get { return GetChildrenByRole(AdditionalArraySpecifierRole); } |
||||
} |
||||
|
||||
public ArrayInitializerExpression Initializer { |
||||
get { return GetChildByRole (InitializerRole); } |
||||
set { SetChildByRole (InitializerRole, value); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitArrayCreateExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ArrayCreateExpression o = other as ArrayCreateExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match); |
||||
} |
||||
} |
||||
} |
||||
@ -1,53 +0,0 @@
@@ -1,53 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// { Elements }
|
||||
/// </summary>
|
||||
public class ArrayInitializerExpression : Expression |
||||
{ |
||||
#region Null
|
||||
public new static readonly ArrayInitializerExpression Null = new NullArrayInitializerExpression (); |
||||
|
||||
sealed class NullArrayInitializerExpression : ArrayInitializerExpression |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public readonly static Role<ArrayInitializerExpression> InitializerRole = new Role<ArrayInitializerExpression>("Initializer", ArrayInitializerExpression.Null); |
||||
|
||||
public AstNodeCollection<Expression> Elements { |
||||
get { return GetChildrenByRole(Roles.Expression); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitArrayInitializerExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ArrayInitializerExpression o = other as ArrayInitializerExpression; |
||||
return o != null && this.Elements.DoMatch(o.Elements, match); |
||||
} |
||||
} |
||||
} |
||||
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class AssignmentExpression : Expression |
||||
{ |
||||
public readonly static Role<Expression> LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; |
||||
public readonly static Role<VBTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole; |
||||
public readonly static Role<Expression> RightExpressionRole = BinaryOperatorExpression.RightExpressionRole; |
||||
|
||||
public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right) |
||||
{ |
||||
AddChild(left, LeftExpressionRole); |
||||
AddChild(right, RightExpressionRole); |
||||
Operator = type; |
||||
} |
||||
|
||||
public Expression Left { |
||||
get { return GetChildByRole(LeftExpressionRole); } |
||||
set { SetChildByRole(LeftExpressionRole, value); } |
||||
} |
||||
|
||||
public AssignmentOperatorType Operator { get; set; } |
||||
|
||||
public Expression Right { |
||||
get { return GetChildByRole(RightExpressionRole); } |
||||
set { SetChildByRole(RightExpressionRole, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAssignmentExpression(this, data); |
||||
} |
||||
} |
||||
} |
||||
@ -1,110 +0,0 @@
@@ -1,110 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class BinaryOperatorExpression : Expression |
||||
{ |
||||
public readonly static Role<Expression> LeftExpressionRole = new Role<Expression>("Left"); |
||||
public readonly static Role<VBTokenNode> OperatorRole = new Role<VBTokenNode>("Operator"); |
||||
public readonly static Role<Expression> RightExpressionRole = new Role<Expression>("Right"); |
||||
|
||||
public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right) |
||||
{ |
||||
AddChild(left, LeftExpressionRole); |
||||
AddChild(right, RightExpressionRole); |
||||
Operator = type; |
||||
} |
||||
|
||||
public Expression Left { |
||||
get { return GetChildByRole(LeftExpressionRole); } |
||||
set { SetChildByRole(LeftExpressionRole, value); } |
||||
} |
||||
|
||||
public BinaryOperatorType Operator { get; set; } |
||||
|
||||
public Expression Right { |
||||
get { return GetChildByRole(RightExpressionRole); } |
||||
set { SetChildByRole(RightExpressionRole, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitBinaryOperatorExpression(this, data); |
||||
} |
||||
} |
||||
|
||||
public enum BinaryOperatorType |
||||
{ |
||||
None, |
||||
|
||||
/// <summary>'&' in C#, 'And' in VB.</summary>
|
||||
BitwiseAnd, |
||||
/// <summary>'|' in C#, 'Or' in VB.</summary>
|
||||
BitwiseOr, |
||||
/// <summary>'&&' in C#, 'AndAlso' in VB.</summary>
|
||||
LogicalAnd, |
||||
/// <summary>'||' in C#, 'OrElse' in VB.</summary>
|
||||
LogicalOr, |
||||
/// <summary>'^' in C#, 'Xor' in VB.</summary>
|
||||
ExclusiveOr, |
||||
|
||||
/// <summary>></summary>
|
||||
GreaterThan, |
||||
/// <summary>>=</summary>
|
||||
GreaterThanOrEqual, |
||||
/// <summary>'==' in C#, '=' in VB.</summary>
|
||||
Equality, |
||||
/// <summary>'!=' in C#, '<>' in VB.</summary>
|
||||
InEquality, |
||||
/// <summary><</summary>
|
||||
LessThan, |
||||
/// <summary><=</summary>
|
||||
LessThanOrEqual, |
||||
|
||||
/// <summary>+</summary>
|
||||
Add, |
||||
/// <summary>-</summary>
|
||||
Subtract, |
||||
/// <summary>*</summary>
|
||||
Multiply, |
||||
/// <summary>/</summary>
|
||||
Divide, |
||||
/// <summary>'%' in C#, 'Mod' in VB.</summary>
|
||||
Modulus, |
||||
/// <summary>VB-only: \</summary>
|
||||
DivideInteger, |
||||
/// <summary>VB-only: ^</summary>
|
||||
Power, |
||||
/// <summary>VB-only: &</summary>
|
||||
Concat, |
||||
|
||||
/// <summary>C#: <<</summary>
|
||||
ShiftLeft, |
||||
/// <summary>C#: >></summary>
|
||||
ShiftRight, |
||||
/// <summary>VB-only: Is</summary>
|
||||
ReferenceEquality, |
||||
/// <summary>VB-only: IsNot</summary>
|
||||
ReferenceInequality, |
||||
|
||||
/// <summary>VB-only: Like</summary>
|
||||
Like, |
||||
/// <summary>
|
||||
/// C#: ??
|
||||
/// VB: IF(x, y)
|
||||
/// </summary>
|
||||
NullCoalescing, |
||||
|
||||
/// <summary>VB-only: !</summary>
|
||||
DictionaryAccess |
||||
} |
||||
} |
||||
@ -1,95 +0,0 @@
@@ -1,95 +0,0 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// CastType(Expression, AstType)
|
||||
/// </summary>
|
||||
public class CastExpression : Expression |
||||
{ |
||||
public CastType CastType { get; set; } |
||||
|
||||
public VBTokenNode CastTypeToken { |
||||
get { return GetChildByRole (Roles.Keyword); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CastExpression () |
||||
{ |
||||
} |
||||
|
||||
public CastExpression (CastType castType, AstType castToType, Expression expression) |
||||
{ |
||||
CastType = castType; |
||||
AddChild (castToType, Roles.Type); |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public CastExpression (CastType castType, Expression expression) |
||||
{ |
||||
CastType = castType; |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCastExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CastExpression o = other as CastExpression; |
||||
return o != null && this.CastType == o.CastType && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
|
||||
public enum CastType |
||||
{ |
||||
DirectCast, |
||||
TryCast, |
||||
CType, |
||||
CBool, |
||||
CByte, |
||||
CChar, |
||||
CDate, |
||||
CDec, |
||||
CDbl, |
||||
CInt, |
||||
CLng, |
||||
CObj, |
||||
CSByte, |
||||
CShort, |
||||
CSng, |
||||
CStr, |
||||
CUInt, |
||||
CULng, |
||||
CUShort |
||||
} |
||||
} |
||||
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Identifier As Type In Expression
|
||||
/// </summary>
|
||||
public class CollectionRangeVariableDeclaration : AstNode |
||||
{ |
||||
public static readonly Role<CollectionRangeVariableDeclaration> CollectionRangeVariableDeclarationRole = new Role<CollectionRangeVariableDeclaration>("CollectionRangeVariableDeclaration"); |
||||
|
||||
public VariableIdentifier Identifier { |
||||
get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); } |
||||
set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCollectionRangeVariableDeclaration(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CollectionRangeVariableDeclaration o = other as CollectionRangeVariableDeclaration; |
||||
return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
||||
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class ConditionalExpression : Expression |
||||
{ |
||||
public readonly static Role<Expression> ConditionExpressionRole = new Role<Expression>("ConditionExpressionRole", Expression.Null); |
||||
public readonly static Role<Expression> TrueExpressionRole = new Role<Expression>("TrueExpressionRole", Expression.Null); |
||||
public readonly static Role<Expression> FalseExpressionRole = new Role<Expression>("FalseExpressionRole", Expression.Null); |
||||
|
||||
public VBTokenNode IfToken { |
||||
get { return GetChildByRole (Roles.Keyword); } |
||||
} |
||||
|
||||
public Expression ConditionExpression { |
||||
get { return GetChildByRole (ConditionExpressionRole); } |
||||
set { SetChildByRole (ConditionExpressionRole, value); } |
||||
} |
||||
|
||||
public Expression TrueExpression { |
||||
get { return GetChildByRole (TrueExpressionRole); } |
||||
set { SetChildByRole (TrueExpressionRole, value); } |
||||
} |
||||
|
||||
public Expression FalseExpression { |
||||
get { return GetChildByRole (FalseExpressionRole); } |
||||
set { SetChildByRole (FalseExpressionRole, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitConditionalExpression(this, data); |
||||
} |
||||
} |
||||
} |
||||
@ -1,59 +0,0 @@
@@ -1,59 +0,0 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class EmptyExpression : Expression |
||||
{ |
||||
TextLocation location; |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return location; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return location; |
||||
} |
||||
} |
||||
|
||||
public EmptyExpression() |
||||
{ |
||||
} |
||||
|
||||
public EmptyExpression(TextLocation location) |
||||
{ |
||||
this.location = location; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitEmptyExpression(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as EmptyExpression; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
||||
@ -1,107 +0,0 @@
@@ -1,107 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public abstract class Expression : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly Expression Null = new NullExpression (); |
||||
|
||||
sealed class NullExpression : Expression |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region Builder methods
|
||||
/// <summary>
|
||||
/// Builds an member reference expression using this expression as target.
|
||||
/// </summary>
|
||||
public MemberAccessExpression Member(string memberName) |
||||
{ |
||||
return new MemberAccessExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments) |
||||
{ |
||||
return Invoke(methodName, null, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(string methodName, params Expression[] arguments) |
||||
{ |
||||
return Invoke(methodName, null, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberAccessExpression mre = new MemberAccessExpression(); |
||||
mre.Target = this; |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = this; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = this; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { CastType = CastType.CType, Type = type, Expression = this }; |
||||
} |
||||
|
||||
public CastExpression CastTo(Type type) |
||||
{ |
||||
return new CastExpression { CastType = CastType.CType, Type = AstType.Create(type), Expression = this }; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -1,49 +0,0 @@
@@ -1,49 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// [ Key ] .Identifier = Expression
|
||||
/// </summary>
|
||||
public class FieldInitializerExpression : Expression |
||||
{ |
||||
public bool IsKey { get; set; } |
||||
|
||||
public VBTokenNode KeyToken { |
||||
get { return GetChildByRole (Roles.Keyword); } |
||||
} |
||||
|
||||
public VBTokenNode DotToken { |
||||
get { return GetChildByRole (Roles.Dot); } |
||||
} |
||||
|
||||
public Identifier Identifier { |
||||
get { return GetChildByRole(Roles.Identifier); } |
||||
set { SetChildByRole(Roles.Identifier, value); } |
||||
} |
||||
|
||||
public VBTokenNode AssignToken { |
||||
get { return GetChildByRole (Roles.Assign); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitFieldInitializerExpression(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
FieldInitializerExpression o = other as FieldInitializerExpression; |
||||
return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
||||
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class GetTypeExpression : Expression |
||||
{ |
||||
public GetTypeExpression() |
||||
{ |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var expr = other as GetTypeExpression; |
||||
return expr != null && |
||||
Type.DoMatch(expr.Type, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitGetTypeExpression(this, data); |
||||
} |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue