diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2012-03-14 19:06:20 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2012-03-14 19:06:20 +0400 |
commit | 6c5b43964b67f2fd895fa858624cd28395f4a464 (patch) | |
tree | 4f33aedb685aae063d725d7a2d5ce2ee8f21d4c4 /ICSharpCode.NRefactory.CSharp.AstVerifier | |
parent | cf134dbdc8fe4662d4265adcffd0f0d120571eac (diff) |
Added little command line tool to test the AST roundtrip.
Diffstat (limited to 'ICSharpCode.NRefactory.CSharp.AstVerifier')
3 files changed, 158 insertions, 0 deletions
diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs b/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs new file mode 100644 index 00000000..7bd701be --- /dev/null +++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("ICSharpCode.NRefactory.CSharp.AstVerifier")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("mike")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj b/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj new file mode 100644 index 00000000..bd6e1e82 --- /dev/null +++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>10.0.0</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{961DADFA-7CE6-429F-BC22-47630D6DB826}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>ICSharpCode.NRefactory.CSharp.AstVerifier</RootNamespace> + <AssemblyName>AstVerifier</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG;</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Externalconsole>true</Externalconsole> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>none</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Externalconsole>true</Externalconsole> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Main.cs" /> + <Compile Include="AssemblyInfo.cs" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj"> + <Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project> + <Name>ICSharpCode.NRefactory.CSharp</Name> + </ProjectReference> + <ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> + <Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> + <Name>ICSharpCode.NRefactory</Name> + </ProjectReference> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs b/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs new file mode 100644 index 00000000..b178babd --- /dev/null +++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs @@ -0,0 +1,82 @@ +using System; +using System.IO; + +namespace ICSharpCode.NRefactory.CSharp.AstVerifier +{ + class MainClass + { + static bool IsMatch (string src1, string src2, out int i, out int j) + { + i = 0; + j = 0; + while (i < src1.Length && j < src2.Length) { + char c1 = src1 [i]; + char c2 = src2 [j]; + if (char.IsWhiteSpace (c1)) { + i++; + continue; + } + if (char.IsWhiteSpace (c2)) { + j++; + continue; + } + if (c1 != c2) { + Console.WriteLine ( i + ":"+ c1 + "!= " +j +":" + c2); + return false; + } + i++; + j++; + } + while (i < src1.Length && char.IsWhiteSpace (src1[i])) { + i++; + } + while (j < src2.Length && char.IsWhiteSpace (src2[j])) { + j++; + } + + return i == src1.Length && j == src2.Length; + } + + public static void Main (string[] args) + { + if (args.Length == 0) { + Console.WriteLine ("Usage: AstVerifier [Directory]"); + return; + } + try { + if (!Directory.Exists (args[0])) { + Console.WriteLine ("Directory not found."); + return; + } + } catch (IOException) { + Console.WriteLine ("Exception while trying to access the directory."); + return; + } + int failed = 0, passed = 0; + Console.WriteLine ("search in " + args [0]); + foreach (var file in Directory.GetFileSystemEntries (args[0], "*", SearchOption.AllDirectories)) { + if (!file.EndsWith (".cs")) + continue; + string text = File.ReadAllText (file); + var unit = CompilationUnit.Parse (text, file); + if (unit == null) + continue; + string generated = unit.GetText (); + int i, j; + if (!IsMatch (text, generated, out i, out j)) { + if (i > 0 && j > 0) { + Console.WriteLine ("fail :" + file + "----original:"); + Console.WriteLine (text.Substring (0, i + 1)); + Console.WriteLine ("----generated:"); + Console.WriteLine (generated.Substring (0, j + 1)); + } + failed++; + } else { + passed++; + } + } + + Console.WriteLine ("{0} passed, {1} failed", passed, failed); + } + } +} |