Browse Source
Added Boo resolver unit tests. Added workaround for IME crash in WOW64 mode. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1339 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
12 changed files with 436 additions and 65 deletions
@ -0,0 +1,74 @@ |
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<PropertyGroup> |
||||||
|
<OutputType>Library</OutputType> |
||||||
|
<RootNamespace>Grunwald.BooBinding.Tests</RootNamespace> |
||||||
|
<AssemblyName>BooBinding.Tests</AssemblyName> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<ProjectGuid>{6FA16499-896F-4C02-BB43-1AF5C6C7C713}</ProjectGuid> |
||||||
|
<OutputPath>..\..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||||
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||||
|
<NoStdLib>False</NoStdLib> |
||||||
|
<RegisterForComInterop>False</RegisterForComInterop> |
||||||
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||||
|
<BaseAddress>4194304</BaseAddress> |
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget> |
||||||
|
<FileAlignment>4096</FileAlignment> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||||
|
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> |
||||||
|
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath> |
||||||
|
<Optimize>False</Optimize> |
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>Full</DebugType> |
||||||
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||||
|
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> |
||||||
|
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath> |
||||||
|
<Optimize>True</Optimize> |
||||||
|
<DefineConstants>TRACE</DefineConstants> |
||||||
|
<DebugSymbols>False</DebugSymbols> |
||||||
|
<DebugType>None</DebugType> |
||||||
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="System" /> |
||||||
|
<Reference Include="System.Data" /> |
||||||
|
<Reference Include="System.Xml" /> |
||||||
|
<Reference Include="nunit.framework" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="ResolverTests.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> |
||||||
|
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> |
||||||
|
<Name>ICSharpCode.SharpDevelop</Name> |
||||||
|
</ProjectReference> |
||||||
|
<ProjectReference Include="..\..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj"> |
||||||
|
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project> |
||||||
|
<Name>ICSharpCode.Core</Name> |
||||||
|
</ProjectReference> |
||||||
|
<ProjectReference Include="..\Project\BooBinding.csproj"> |
||||||
|
<Project>{4AC2D5F1-F671-480C-A075-6BF62B3721B2}</Project> |
||||||
|
<Name>BooBinding</Name> |
||||||
|
</ProjectReference> |
||||||
|
<Content Include="..\..\..\..\..\..\bin\log4net.dll"> |
||||||
|
<Link>log4net.dll</Link> |
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||||
|
</Content> |
||||||
|
<Content Include="..\..\..\..\..\..\bin\ICSharpCode.Core.dll"> |
||||||
|
<Link>ICSharpCode.Core.dll</Link> |
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||||
|
</Content> |
||||||
|
<Content Include="..\..\..\..\..\..\bin\ICSharpCode.SharpDevelop.dll"> |
||||||
|
<Link>ICSharpCode.SharpDevelop.dll</Link> |
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||||
|
</Content> |
||||||
|
</ItemGroup> |
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||||
|
</Project> |
||||||
@ -0,0 +1,142 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 23.04.2006 |
||||||
|
* Time: 11:33 |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using Grunwald.BooBinding.CodeCompletion; |
||||||
|
|
||||||
|
namespace Grunwald.BooBinding.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResolverTests |
||||||
|
{ |
||||||
|
T Resolve<T>(string code) where T : ResolveResult |
||||||
|
{ |
||||||
|
return Resolve<T>(code, "/*1*/"); |
||||||
|
} |
||||||
|
|
||||||
|
T Resolve<T>(string code, string marker) where T : ResolveResult |
||||||
|
{ |
||||||
|
ResolveResult rr = Resolve(prog, new ExpressionResult(code), marker); |
||||||
|
Assert.IsNotNull(rr, "Resolve must not return null"); |
||||||
|
Assert.IsInstanceOfType(typeof(T), rr, "Resolve must return instance of type " + typeof(T).Name); |
||||||
|
return (T)rr; |
||||||
|
} |
||||||
|
|
||||||
|
ResolveResult Resolve(string prog, ExpressionResult er, string marker) |
||||||
|
{ |
||||||
|
const string fileName = "tempFile.boo"; |
||||||
|
DefaultProjectContent pc = new DefaultProjectContent(); |
||||||
|
ParserService.ForceProjectContent(pc); |
||||||
|
pc.ReferencedContents.Add(ProjectContentRegistry.Mscorlib); |
||||||
|
pc.ReferencedContents.Add(ProjectContentRegistry.WinForms); |
||||||
|
ICompilationUnit cu = new BooParser().Parse(pc, fileName, prog); |
||||||
|
ParserService.UpdateParseInformation(cu, fileName, false, false); |
||||||
|
cu.Classes.ForEach(pc.AddClassToNamespaceList); |
||||||
|
|
||||||
|
int index = prog.IndexOf(marker); |
||||||
|
int line = 1; |
||||||
|
int column = 0; |
||||||
|
for (int i = 0; i < index; i++) { |
||||||
|
column++; |
||||||
|
if (prog[i]=='\n') { |
||||||
|
line++; |
||||||
|
column = 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
BooResolver r = new BooResolver(); |
||||||
|
return r.Resolve(er, line, column, fileName, prog); |
||||||
|
} |
||||||
|
|
||||||
|
const string prog = |
||||||
|
"import System\n" + |
||||||
|
"def MyMethod(arg as string):\n" + |
||||||
|
"\tlocalVar = arg\n" + |
||||||
|
"\t/*1*/\n" + |
||||||
|
"\tclosure = { e as string | arg.IndexOf(e) /*inClosure*/ }\n" + |
||||||
|
"\tindex = closure('.')\n" + |
||||||
|
"\t/*2*/\n" + |
||||||
|
"\tclosure2 = def(e as DateTime):\n" + |
||||||
|
"\t\treturn e.Year\n" + |
||||||
|
"\trecursiveClosure = def():\n" + |
||||||
|
"\t\treturn recursiveClosure()\n" + |
||||||
|
"\t/*3*/\n"; |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MethodParameter() |
||||||
|
{ |
||||||
|
LocalResolveResult rr = Resolve<LocalResolveResult>("arg"); |
||||||
|
Assert.IsTrue(rr.IsParameter); |
||||||
|
Assert.AreEqual("System.String", rr.ResolvedType.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void LocalVariable() |
||||||
|
{ |
||||||
|
LocalResolveResult rr = Resolve<LocalResolveResult>("localVar"); |
||||||
|
Assert.IsFalse(rr.IsParameter); |
||||||
|
Assert.AreEqual("System.String", rr.ResolvedType.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NullCoalescing() |
||||||
|
{ |
||||||
|
ResolveResult rr = Resolve<ResolveResult>("localVar or arg"); |
||||||
|
Assert.AreEqual("System.String", rr.ResolvedType.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void InnerClassEnum() |
||||||
|
{ |
||||||
|
TypeResolveResult trr = Resolve<TypeResolveResult>("Environment.SpecialFolder"); |
||||||
|
Assert.AreEqual("System.Environment.SpecialFolder", trr.ResolvedClass.FullyQualifiedName); |
||||||
|
|
||||||
|
MemberResolveResult mrr = Resolve<MemberResolveResult>("Environment.SpecialFolder.Desktop"); |
||||||
|
Assert.AreEqual("System.Environment.SpecialFolder.Desktop", mrr.ResolvedMember.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ClosureParameter() |
||||||
|
{ |
||||||
|
LocalResolveResult rr = Resolve<LocalResolveResult>("e", "/*inClosure*/"); |
||||||
|
Assert.AreEqual("System.String", rr.ResolvedType.FullyQualifiedName); |
||||||
|
|
||||||
|
Assert.IsNull(Resolve(prog, new ExpressionResult("e"), "/*1*/")); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ClosureCall() |
||||||
|
{ |
||||||
|
LocalResolveResult rr = Resolve<LocalResolveResult>("closure('.')", "/*2*/"); |
||||||
|
Assert.IsFalse(rr.IsParameter); |
||||||
|
Assert.AreEqual("closure", rr.Field.Name); |
||||||
|
Assert.AreEqual("System.Int32", rr.ResolvedType.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ClosureCall2() |
||||||
|
{ |
||||||
|
LocalResolveResult rr = Resolve<LocalResolveResult>("closure2(DateTime.Now)", "/*3*/"); |
||||||
|
Assert.IsFalse(rr.IsParameter); |
||||||
|
Assert.AreEqual("closure2", rr.Field.Name); |
||||||
|
Assert.AreEqual("System.Int32", rr.ResolvedType.FullyQualifiedName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RecursiveClosure() |
||||||
|
{ |
||||||
|
// Code-completion cannot work here, test if SharpDevelop is correctly
|
||||||
|
// preventing the StackOverflow.
|
||||||
|
LocalResolveResult rr = Resolve<LocalResolveResult>("recursiveClosure", "/*3*/"); |
||||||
|
Assert.IsFalse(rr.IsParameter); |
||||||
|
Assert.AreEqual("delegate():?", rr.ResolvedType.FullyQualifiedName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue