mirror of https://github.com/icsharpcode/ILSpy.git
602 changed files with 271481 additions and 123 deletions
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0"?> |
||||
<configuration> |
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> |
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
*.sln -crlf |
||||
*.csproj -crlf |
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
/lib/*.dll |
||||
/ICSharpCode.NRefactory.Tests/PartCover/* |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
|
||||
bin/ |
||||
obj/ |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{9C19E629-C93E-4ACB-9A4B-13072B5AEF9D}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
||||
<OutputType>WinExe</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.Demo</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.Demo</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<DebugSymbols>True</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<Optimize>False</Optimize> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Drawing" /> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="VBEditDialog.cs" /> |
||||
<Compile Include="VBEditDialog.Designer.cs"> |
||||
<DependentUpon>VBEditDialog.cs</DependentUpon> |
||||
</Compile> |
||||
<Compile Include="VBDomView.cs" /> |
||||
<Compile Include="VBDomView.Designer.cs"> |
||||
<DependentUpon>VBDomView.cs</DependentUpon> |
||||
</Compile> |
||||
<Compile Include="MainForm.cs" /> |
||||
<Compile Include="MainForm.Designer.cs"> |
||||
<DependentUpon>MainForm.cs</DependentUpon> |
||||
</Compile> |
||||
<Compile Include="Program.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="VBDemo.cs" /> |
||||
<Compile Include="VBDemo.Designer.cs"> |
||||
<DependentUpon>VBDemo.cs</DependentUpon> |
||||
</Compile> |
||||
</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="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<EmbeddedResource Include="VBEditDialog.resx"> |
||||
<DependentUpon>VBEditDialog.cs</DependentUpon> |
||||
</EmbeddedResource> |
||||
<EmbeddedResource Include="VBDomView.resx"> |
||||
<DependentUpon>VBDomView.cs</DependentUpon> |
||||
</EmbeddedResource> |
||||
<EmbeddedResource Include="MainForm.resx"> |
||||
<DependentUpon>MainForm.cs</DependentUpon> |
||||
</EmbeddedResource> |
||||
<EmbeddedResource Include="VBDemo.resx"> |
||||
<DependentUpon>VBDemo.cs</DependentUpon> |
||||
</EmbeddedResource> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,221 @@
@@ -0,0 +1,221 @@
|
||||
// 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)
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
partial class MainForm |
||||
{ |
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null; |
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) { |
||||
if (components != null) { |
||||
components.Dispose(); |
||||
} |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent() |
||||
{ |
||||
this.tabPage2 = new System.Windows.Forms.TabPage(); |
||||
this.tabPage1 = new System.Windows.Forms.TabPage(); |
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); |
||||
this.csharpCodeTextBox = new System.Windows.Forms.TextBox(); |
||||
this.resolveButton = new System.Windows.Forms.Button(); |
||||
this.csharpTreeView = new System.Windows.Forms.TreeView(); |
||||
this.csharpGenerateCodeButton = new System.Windows.Forms.Button(); |
||||
this.csharpParseButton = new System.Windows.Forms.Button(); |
||||
this.tabControl1 = new System.Windows.Forms.TabControl(); |
||||
this.miniToolStrip = new System.Windows.Forms.ToolStrip(); |
||||
this.vbDemo1 = new ICSharpCode.NRefactory.Demo.VBDemo(); |
||||
this.tabPage2.SuspendLayout(); |
||||
this.tabPage1.SuspendLayout(); |
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); |
||||
this.splitContainer1.Panel1.SuspendLayout(); |
||||
this.splitContainer1.Panel2.SuspendLayout(); |
||||
this.splitContainer1.SuspendLayout(); |
||||
this.tabControl1.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// tabPage2
|
||||
//
|
||||
this.tabPage2.Controls.Add(this.vbDemo1); |
||||
this.tabPage2.Location = new System.Drawing.Point(4, 22); |
||||
this.tabPage2.Name = "tabPage2"; |
||||
this.tabPage2.Padding = new System.Windows.Forms.Padding(3); |
||||
this.tabPage2.Size = new System.Drawing.Size(507, 458); |
||||
this.tabPage2.TabIndex = 1; |
||||
this.tabPage2.Text = "VB"; |
||||
this.tabPage2.UseVisualStyleBackColor = true; |
||||
//
|
||||
// tabPage1
|
||||
//
|
||||
this.tabPage1.Controls.Add(this.splitContainer1); |
||||
this.tabPage1.Location = new System.Drawing.Point(4, 22); |
||||
this.tabPage1.Name = "tabPage1"; |
||||
this.tabPage1.Padding = new System.Windows.Forms.Padding(3); |
||||
this.tabPage1.Size = new System.Drawing.Size(507, 458); |
||||
this.tabPage1.TabIndex = 0; |
||||
this.tabPage1.Text = "C#"; |
||||
this.tabPage1.UseVisualStyleBackColor = true; |
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.splitContainer1.Location = new System.Drawing.Point(3, 3); |
||||
this.splitContainer1.Name = "splitContainer1"; |
||||
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; |
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.Controls.Add(this.csharpCodeTextBox); |
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.resolveButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.csharpTreeView); |
||||
this.splitContainer1.Panel2.Controls.Add(this.csharpGenerateCodeButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.csharpParseButton); |
||||
this.splitContainer1.Size = new System.Drawing.Size(501, 452); |
||||
this.splitContainer1.SplitterDistance = 201; |
||||
this.splitContainer1.TabIndex = 0; |
||||
//
|
||||
// csharpCodeTextBox
|
||||
//
|
||||
this.csharpCodeTextBox.AcceptsReturn = true; |
||||
this.csharpCodeTextBox.AcceptsTab = true; |
||||
this.csharpCodeTextBox.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.csharpCodeTextBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); |
||||
this.csharpCodeTextBox.HideSelection = false; |
||||
this.csharpCodeTextBox.Location = new System.Drawing.Point(0, 0); |
||||
this.csharpCodeTextBox.Multiline = true; |
||||
this.csharpCodeTextBox.Name = "csharpCodeTextBox"; |
||||
this.csharpCodeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; |
||||
this.csharpCodeTextBox.Size = new System.Drawing.Size(501, 201); |
||||
this.csharpCodeTextBox.TabIndex = 0; |
||||
this.csharpCodeTextBox.Text = "using System;\r\nclass Test\r\n{\r\n public void Main(string[] args)\r\n {\r\n " + |
||||
" Console.WriteLine(\"Hello, World\");\r\n }\r\n}"; |
||||
this.csharpCodeTextBox.WordWrap = false; |
||||
this.csharpCodeTextBox.TextChanged += new System.EventHandler(this.CsharpCodeTextBoxTextChanged); |
||||
this.csharpCodeTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CSharpCodeTextBoxKeyDown); |
||||
//
|
||||
// resolveButton
|
||||
//
|
||||
this.resolveButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.resolveButton.Location = new System.Drawing.Point(200, 3); |
||||
this.resolveButton.Name = "resolveButton"; |
||||
this.resolveButton.Size = new System.Drawing.Size(100, 23); |
||||
this.resolveButton.TabIndex = 3; |
||||
this.resolveButton.Text = "Resolve"; |
||||
this.resolveButton.UseVisualStyleBackColor = true; |
||||
this.resolveButton.Click += new System.EventHandler(this.ResolveButtonClick); |
||||
//
|
||||
// csharpTreeView
|
||||
//
|
||||
this.csharpTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
||||
| System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.csharpTreeView.HideSelection = false; |
||||
this.csharpTreeView.Location = new System.Drawing.Point(3, 32); |
||||
this.csharpTreeView.Name = "csharpTreeView"; |
||||
this.csharpTreeView.Size = new System.Drawing.Size(493, 212); |
||||
this.csharpTreeView.TabIndex = 2; |
||||
this.csharpTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.CSharpTreeViewAfterSelect); |
||||
//
|
||||
// csharpGenerateCodeButton
|
||||
//
|
||||
this.csharpGenerateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.csharpGenerateCodeButton.Location = new System.Drawing.Point(306, 2); |
||||
this.csharpGenerateCodeButton.Name = "csharpGenerateCodeButton"; |
||||
this.csharpGenerateCodeButton.Size = new System.Drawing.Size(100, 23); |
||||
this.csharpGenerateCodeButton.TabIndex = 1; |
||||
this.csharpGenerateCodeButton.Text = "Generate"; |
||||
this.csharpGenerateCodeButton.UseVisualStyleBackColor = true; |
||||
this.csharpGenerateCodeButton.Click += new System.EventHandler(this.CSharpGenerateCodeButtonClick); |
||||
//
|
||||
// csharpParseButton
|
||||
//
|
||||
this.csharpParseButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.csharpParseButton.Location = new System.Drawing.Point(94, 3); |
||||
this.csharpParseButton.Name = "csharpParseButton"; |
||||
this.csharpParseButton.Size = new System.Drawing.Size(100, 23); |
||||
this.csharpParseButton.TabIndex = 0; |
||||
this.csharpParseButton.Text = "Parse"; |
||||
this.csharpParseButton.UseVisualStyleBackColor = true; |
||||
this.csharpParseButton.Click += new System.EventHandler(this.CSharpParseButtonClick); |
||||
//
|
||||
// tabControl1
|
||||
//
|
||||
this.tabControl1.Controls.Add(this.tabPage1); |
||||
this.tabControl1.Controls.Add(this.tabPage2); |
||||
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.tabControl1.Location = new System.Drawing.Point(0, 0); |
||||
this.tabControl1.Name = "tabControl1"; |
||||
this.tabControl1.SelectedIndex = 0; |
||||
this.tabControl1.Size = new System.Drawing.Size(515, 484); |
||||
this.tabControl1.TabIndex = 0; |
||||
//
|
||||
// miniToolStrip
|
||||
//
|
||||
this.miniToolStrip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||
this.miniToolStrip.AutoSize = false; |
||||
this.miniToolStrip.CanOverflow = false; |
||||
this.miniToolStrip.Dock = System.Windows.Forms.DockStyle.None; |
||||
this.miniToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; |
||||
this.miniToolStrip.Location = new System.Drawing.Point(13, 3); |
||||
this.miniToolStrip.Name = "miniToolStrip"; |
||||
this.miniToolStrip.Size = new System.Drawing.Size(16, 25); |
||||
this.miniToolStrip.TabIndex = 3; |
||||
//
|
||||
// vbDemo1
|
||||
//
|
||||
this.vbDemo1.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.vbDemo1.Location = new System.Drawing.Point(3, 3); |
||||
this.vbDemo1.Name = "vbDemo1"; |
||||
this.vbDemo1.Size = new System.Drawing.Size(501, 452); |
||||
this.vbDemo1.TabIndex = 0; |
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||
this.ClientSize = new System.Drawing.Size(515, 484); |
||||
this.Controls.Add(this.tabControl1); |
||||
this.Name = "MainForm"; |
||||
this.Text = "NRefactory Demo"; |
||||
this.tabPage2.ResumeLayout(false); |
||||
this.tabPage1.ResumeLayout(false); |
||||
this.splitContainer1.Panel1.ResumeLayout(false); |
||||
this.splitContainer1.Panel1.PerformLayout(); |
||||
this.splitContainer1.Panel2.ResumeLayout(false); |
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); |
||||
this.splitContainer1.ResumeLayout(false); |
||||
this.tabControl1.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private ICSharpCode.NRefactory.Demo.VBDemo vbDemo1; |
||||
private System.Windows.Forms.Button resolveButton; |
||||
private System.Windows.Forms.ToolStrip miniToolStrip; |
||||
private System.Windows.Forms.TreeView csharpTreeView; |
||||
private System.Windows.Forms.Button csharpParseButton; |
||||
private System.Windows.Forms.Button csharpGenerateCodeButton; |
||||
private System.Windows.Forms.TextBox csharpCodeTextBox; |
||||
private System.Windows.Forms.SplitContainer splitContainer1; |
||||
private System.Windows.Forms.TabPage tabPage2; |
||||
private System.Windows.Forms.TabPage tabPage1; |
||||
private System.Windows.Forms.TabControl tabControl1; |
||||
} |
||||
} |
@ -0,0 +1,228 @@
@@ -0,0 +1,228 @@
|
||||
// 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; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
using System.Text; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
/// <summary>
|
||||
/// Description of MainForm.
|
||||
/// </summary>
|
||||
public partial class MainForm : Form |
||||
{ |
||||
public MainForm() |
||||
{ |
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent(); |
||||
|
||||
csharpCodeTextBox.SelectAll(); |
||||
CSharpParseButtonClick(null, null); |
||||
resolveButton.UseWaitCursor = true; |
||||
ThreadPool.QueueUserWorkItem( |
||||
delegate { |
||||
builtInLibs.Value.ToString(); |
||||
BeginInvoke(new Action(delegate { resolveButton.UseWaitCursor = false; })); |
||||
}); |
||||
} |
||||
|
||||
CompilationUnit compilationUnit; |
||||
|
||||
void CSharpParseButtonClick(object sender, EventArgs e) |
||||
{ |
||||
CSharpParser parser = new CSharpParser(); |
||||
compilationUnit = parser.Parse(new StringReader(csharpCodeTextBox.Text)); |
||||
csharpTreeView.Nodes.Clear(); |
||||
foreach (var element in compilationUnit.Children) { |
||||
csharpTreeView.Nodes.Add(MakeTreeNode(element)); |
||||
} |
||||
SelectCurrentNode(csharpTreeView.Nodes); |
||||
resolveButton.Enabled = true; |
||||
} |
||||
|
||||
TreeNode MakeTreeNode(AstNode node) |
||||
{ |
||||
TreeNode t = new TreeNode(GetNodeTitle(node)); |
||||
t.Tag = node; |
||||
foreach (AstNode child in node.Children) { |
||||
t.Nodes.Add(MakeTreeNode(child)); |
||||
} |
||||
return t; |
||||
} |
||||
|
||||
string GetNodeTitle(AstNode node) |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
b.Append(node.Role.ToString()); |
||||
b.Append(": "); |
||||
b.Append(node.GetType().Name); |
||||
bool hasProperties = false; |
||||
foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { |
||||
if (p.Name == "NodeType" || p.Name == "IsNull") |
||||
continue; |
||||
if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { |
||||
if (!hasProperties) { |
||||
hasProperties = true; |
||||
b.Append(" ("); |
||||
} else { |
||||
b.Append(", "); |
||||
} |
||||
b.Append(p.Name); |
||||
b.Append(" = "); |
||||
try { |
||||
object val = p.GetValue(node, null); |
||||
b.Append(val != null ? val.ToString() : "**null**"); |
||||
} catch (TargetInvocationException ex) { |
||||
b.Append("**" + ex.InnerException.GetType().Name + "**"); |
||||
} |
||||
} |
||||
} |
||||
if (hasProperties) |
||||
b.Append(")"); |
||||
return b.ToString(); |
||||
} |
||||
|
||||
bool SelectCurrentNode(TreeNodeCollection c) |
||||
{ |
||||
int selectionStart = csharpCodeTextBox.SelectionStart; |
||||
int selectionEnd = selectionStart + csharpCodeTextBox.SelectionLength; |
||||
foreach (TreeNode t in c) { |
||||
AstNode node = t.Tag as AstNode; |
||||
if (node != null |
||||
&& selectionStart >= GetOffset(csharpCodeTextBox, node.StartLocation) |
||||
&& selectionEnd <= GetOffset(csharpCodeTextBox, node.EndLocation)) |
||||
{ |
||||
if (selectionStart == selectionEnd |
||||
&& (selectionStart == GetOffset(csharpCodeTextBox, node.StartLocation) |
||||
|| selectionStart == GetOffset(csharpCodeTextBox, node.EndLocation))) |
||||
{ |
||||
// caret is on border of this node; don't expand
|
||||
csharpTreeView.SelectedNode = t; |
||||
} else { |
||||
t.Expand(); |
||||
if (!SelectCurrentNode(t.Nodes)) |
||||
csharpTreeView.SelectedNode = t; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void CSharpGenerateCodeButtonClick(object sender, EventArgs e) |
||||
{ |
||||
StringWriter w = new StringWriter(); |
||||
OutputVisitor output = new OutputVisitor(w, new CSharpFormattingPolicy()); |
||||
compilationUnit.AcceptVisitor(output, null); |
||||
csharpCodeTextBox.Text = w.ToString(); |
||||
} |
||||
|
||||
int GetOffset(TextBox textBox, AstLocation location) |
||||
{ |
||||
return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1; |
||||
} |
||||
|
||||
void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e) |
||||
{ |
||||
AstNode node = e.Node.Tag as AstNode; |
||||
if (node != null) { |
||||
int startOffset = GetOffset(csharpCodeTextBox, node.StartLocation); |
||||
int endOffset = GetOffset(csharpCodeTextBox, node.EndLocation); |
||||
csharpCodeTextBox.Select(startOffset, endOffset - startOffset); |
||||
} |
||||
} |
||||
|
||||
Lazy<IList<IProjectContent>> builtInLibs = new Lazy<IList<IProjectContent>>( |
||||
delegate { |
||||
Assembly[] assemblies = { |
||||
typeof(object).Assembly, // mscorlib
|
||||
typeof(Uri).Assembly, // System.dll
|
||||
typeof(System.Linq.Enumerable).Assembly, // System.Core.dll
|
||||
// typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll
|
||||
// typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll
|
||||
// typeof(Form).Assembly, // System.Windows.Forms.dll
|
||||
typeof(ICSharpCode.NRefactory.TypeSystem.IProjectContent).Assembly, |
||||
}; |
||||
IProjectContent[] projectContents = new IProjectContent[assemblies.Length]; |
||||
Stopwatch total = Stopwatch.StartNew(); |
||||
Parallel.For( |
||||
0, assemblies.Length, |
||||
delegate (int i) { |
||||
Stopwatch w = Stopwatch.StartNew(); |
||||
CecilLoader loader = new CecilLoader(); |
||||
projectContents[i] = loader.LoadAssemblyFile(assemblies[i].Location); |
||||
Debug.WriteLine(Path.GetFileName(assemblies[i].Location) + ": " + w.Elapsed); |
||||
}); |
||||
Debug.WriteLine("Total: " + total.Elapsed); |
||||
return projectContents; |
||||
}); |
||||
|
||||
void ResolveButtonClick(object sender, EventArgs e) |
||||
{ |
||||
SimpleProjectContent project = new SimpleProjectContent(); |
||||
TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(project, "dummy.cs"); |
||||
compilationUnit.AcceptVisitor(convertVisitor, null); |
||||
project.UpdateProjectContent(null, convertVisitor.ParsedFile.TopLevelTypeDefinitions, null, null); |
||||
|
||||
List<ITypeResolveContext> projects = new List<ITypeResolveContext>(); |
||||
projects.Add(project); |
||||
projects.AddRange(builtInLibs.Value); |
||||
|
||||
using (var context = new CompositeTypeResolveContext(projects).Synchronize()) { |
||||
CSharpResolver resolver = new CSharpResolver(context); |
||||
|
||||
IResolveVisitorNavigator navigator = null; |
||||
if (csharpTreeView.SelectedNode != null) { |
||||
navigator = new NodeListResolveVisitorNavigator(new[] { (AstNode)csharpTreeView.SelectedNode.Tag }); |
||||
} |
||||
ResolveVisitor visitor = new ResolveVisitor(resolver, convertVisitor.ParsedFile, navigator); |
||||
visitor.Scan(compilationUnit); |
||||
csharpTreeView.BeginUpdate(); |
||||
ShowResolveResultsInTree(csharpTreeView.Nodes, visitor); |
||||
csharpTreeView.EndUpdate(); |
||||
} |
||||
} |
||||
|
||||
void ShowResolveResultsInTree(TreeNodeCollection c, ResolveVisitor v) |
||||
{ |
||||
foreach (TreeNode t in c) { |
||||
AstNode node = t.Tag as AstNode; |
||||
if (node != null) { |
||||
ResolveResult rr = v.GetResolveResult(node); |
||||
if (rr != null) |
||||
t.Text = GetNodeTitle(node) + " " + rr.ToString(); |
||||
else |
||||
t.Text = GetNodeTitle(node); |
||||
} |
||||
ShowResolveResultsInTree(t.Nodes, v); |
||||
} |
||||
} |
||||
|
||||
void CSharpCodeTextBoxKeyDown(object sender, KeyEventArgs e) |
||||
{ |
||||
if (e.Control && e.KeyCode == Keys.A) { |
||||
e.Handled = true; |
||||
csharpCodeTextBox.SelectAll(); |
||||
} |
||||
} |
||||
|
||||
void CsharpCodeTextBoxTextChanged(object sender, EventArgs e) |
||||
{ |
||||
resolveButton.Enabled = false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,123 @@
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<metadata name="miniToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
||||
<value>17, 17</value> |
||||
</metadata> |
||||
</root> |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
// 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.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
/// <summary>
|
||||
/// Class with program entry point.
|
||||
/// </summary>
|
||||
internal sealed class Program |
||||
{ |
||||
/// <summary>
|
||||
/// Program entry point.
|
||||
/// </summary>
|
||||
[STAThread] |
||||
private static void Main(string[] args) |
||||
{ |
||||
Application.EnableVisualStyles(); |
||||
Application.SetCompatibleTextRenderingDefault(false); |
||||
Application.Run(new MainForm()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#region Using directives
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ICSharpCode.NRefactory.Demo")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("ICSharpCode.NRefactory.Demo")] |
||||
[assembly: AssemblyCopyright("Copyright 2010")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")] |
@ -0,0 +1,163 @@
@@ -0,0 +1,163 @@
|
||||
// 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)
|
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
partial class VBDemo |
||||
{ |
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null; |
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the control.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) { |
||||
if (components != null) { |
||||
components.Dispose(); |
||||
} |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent() |
||||
{ |
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); |
||||
this.codeView = new System.Windows.Forms.TextBox(); |
||||
this.editNodeButton = new System.Windows.Forms.Button(); |
||||
this.clearSpecialsButton = new System.Windows.Forms.Button(); |
||||
this.syntaxTree = new ICSharpCode.NRefactory.Demo.VBDomView(); |
||||
this.generateCodeButton = new System.Windows.Forms.Button(); |
||||
this.parseButton = new System.Windows.Forms.Button(); |
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); |
||||
this.splitContainer1.Panel1.SuspendLayout(); |
||||
this.splitContainer1.Panel2.SuspendLayout(); |
||||
this.splitContainer1.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.splitContainer1.Location = new System.Drawing.Point(0, 0); |
||||
this.splitContainer1.Name = "splitContainer1"; |
||||
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; |
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.Controls.Add(this.codeView); |
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.editNodeButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.clearSpecialsButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.syntaxTree); |
||||
this.splitContainer1.Panel2.Controls.Add(this.generateCodeButton); |
||||
this.splitContainer1.Panel2.Controls.Add(this.parseButton); |
||||
this.splitContainer1.Size = new System.Drawing.Size(462, 391); |
||||
this.splitContainer1.SplitterDistance = 173; |
||||
this.splitContainer1.TabIndex = 1; |
||||
//
|
||||
// codeView
|
||||
//
|
||||
this.codeView.AcceptsReturn = true; |
||||
this.codeView.AcceptsTab = true; |
||||
this.codeView.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.codeView.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); |
||||
this.codeView.HideSelection = false; |
||||
this.codeView.Location = new System.Drawing.Point(0, 0); |
||||
this.codeView.Multiline = true; |
||||
this.codeView.Name = "codeView"; |
||||
this.codeView.ScrollBars = System.Windows.Forms.ScrollBars.Both; |
||||
this.codeView.Size = new System.Drawing.Size(462, 173); |
||||
this.codeView.TabIndex = 0; |
||||
this.codeView.Text = "Imports System\r\nClass Test\r\n Public Sub Main(ByVal args As String())\r\n " + |
||||
" Console.WriteLine(\"Hello, World\")\r\n End Sub\r\nEnd Class"; |
||||
this.codeView.WordWrap = false; |
||||
//
|
||||
// editNodeButton
|
||||
//
|
||||
this.editNodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.editNodeButton.Location = new System.Drawing.Point(331, 2); |
||||
this.editNodeButton.Name = "editNodeButton"; |
||||
this.editNodeButton.Size = new System.Drawing.Size(100, 23); |
||||
this.editNodeButton.TabIndex = 4; |
||||
this.editNodeButton.Text = "Edit node"; |
||||
this.editNodeButton.UseVisualStyleBackColor = true; |
||||
this.editNodeButton.Click += new System.EventHandler(this.EditNodeButtonClick); |
||||
//
|
||||
// clearSpecialsButton
|
||||
//
|
||||
this.clearSpecialsButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.clearSpecialsButton.Location = new System.Drawing.Point(225, 2); |
||||
this.clearSpecialsButton.Name = "clearSpecialsButton"; |
||||
this.clearSpecialsButton.Size = new System.Drawing.Size(100, 23); |
||||
this.clearSpecialsButton.TabIndex = 3; |
||||
this.clearSpecialsButton.Text = "Clear 0 specials"; |
||||
this.clearSpecialsButton.UseVisualStyleBackColor = true; |
||||
this.clearSpecialsButton.Click += new System.EventHandler(this.ClearSpecialsButtonClick); |
||||
//
|
||||
// syntaxTree
|
||||
//
|
||||
this.syntaxTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
||||
| System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.syntaxTree.Location = new System.Drawing.Point(3, 32); |
||||
this.syntaxTree.Name = "syntaxTree"; |
||||
this.syntaxTree.Size = new System.Drawing.Size(459, 182); |
||||
this.syntaxTree.TabIndex = 2; |
||||
this.syntaxTree.Unit = null; |
||||
//
|
||||
// generateCodeButton
|
||||
//
|
||||
this.generateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.generateCodeButton.Location = new System.Drawing.Point(119, 2); |
||||
this.generateCodeButton.Name = "generateCodeButton"; |
||||
this.generateCodeButton.Size = new System.Drawing.Size(100, 23); |
||||
this.generateCodeButton.TabIndex = 1; |
||||
this.generateCodeButton.Text = "Generate"; |
||||
this.generateCodeButton.UseVisualStyleBackColor = true; |
||||
this.generateCodeButton.Click += new System.EventHandler(this.GenerateCodeButtonClick); |
||||
//
|
||||
// parseButton
|
||||
//
|
||||
this.parseButton.Anchor = System.Windows.Forms.AnchorStyles.Top; |
||||
this.parseButton.Location = new System.Drawing.Point(13, 2); |
||||
this.parseButton.Name = "parseButton"; |
||||
this.parseButton.Size = new System.Drawing.Size(100, 23); |
||||
this.parseButton.TabIndex = 0; |
||||
this.parseButton.Text = "Parse"; |
||||
this.parseButton.UseVisualStyleBackColor = true; |
||||
this.parseButton.Click += new System.EventHandler(this.ParseButtonClick); |
||||
//
|
||||
// VBDemo
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||
this.Controls.Add(this.splitContainer1); |
||||
this.Name = "VBDemo"; |
||||
this.Size = new System.Drawing.Size(462, 391); |
||||
this.splitContainer1.Panel1.ResumeLayout(false); |
||||
this.splitContainer1.Panel1.PerformLayout(); |
||||
this.splitContainer1.Panel2.ResumeLayout(false); |
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); |
||||
this.splitContainer1.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.Button clearSpecialsButton; |
||||
private System.Windows.Forms.Button editNodeButton; |
||||
private ICSharpCode.NRefactory.Demo.VBDomView syntaxTree; |
||||
private System.Windows.Forms.TextBox codeView; |
||||
private System.Windows.Forms.Button generateCodeButton; |
||||
private System.Windows.Forms.Button parseButton; |
||||
private System.Windows.Forms.SplitContainer splitContainer1; |
||||
} |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
// 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; |
||||
using System.ComponentModel; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.NRefactory.VB; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
/// <summary>
|
||||
/// Description of VBDemo.
|
||||
/// </summary>
|
||||
public partial class VBDemo : UserControl |
||||
{ |
||||
public VBDemo() |
||||
{ |
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent(); |
||||
ParseButtonClick(null, null); |
||||
} |
||||
|
||||
IList<ISpecial> savedSpecials; |
||||
|
||||
void ParseButtonClick(object sender, EventArgs e) |
||||
{ |
||||
using (VBParser parser = new VBParser(new VBLexer(new StringReader(codeView.Text)))) { |
||||
parser.Parse(); |
||||
// this allows retrieving comments, preprocessor directives, etc. (stuff that isn't part of the syntax)
|
||||
SetSpecials(parser.Lexer.SpecialTracker.RetrieveSpecials()); |
||||
// this retrieves the root node of the result DOM
|
||||
if (parser.Errors.Count > 0) { |
||||
MessageBox.Show(parser.Errors.ErrorOutput); |
||||
} |
||||
syntaxTree.Unit = parser.CompilationUnit; |
||||
} |
||||
} |
||||
|
||||
void GenerateCodeButtonClick(object sender, EventArgs e) |
||||
{ |
||||
if (syntaxTree.Unit != null) { |
||||
VBNetOutputVisitor visitor = new VBNetOutputVisitor(); |
||||
// re-insert the comments we saved from the parser into the output
|
||||
using (SpecialNodesInserter.Install(savedSpecials, visitor)) { |
||||
syntaxTree.Unit.AcceptVisitor(visitor, null); |
||||
} |
||||
codeView.Text = visitor.Text.Replace("\t", " "); |
||||
} |
||||
} |
||||
|
||||
void ClearSpecialsButtonClick(object sender, EventArgs e) |
||||
{ |
||||
SetSpecials(new ISpecial[0]); |
||||
} |
||||
|
||||
void EditNodeButtonClick(object sender, EventArgs e) |
||||
{ |
||||
syntaxTree.EditSelectedNode(); |
||||
} |
||||
|
||||
void SetSpecials(IList<ISpecial> specials) |
||||
{ |
||||
savedSpecials = specials; |
||||
if (specials.Count == 1) |
||||
clearSpecialsButton.Text = "Clear 1 special"; |
||||
else |
||||
clearSpecialsButton.Text = "Clear " + specials.Count + " specials"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
</root> |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// 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)
|
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
partial class VBDomView : System.Windows.Forms.UserControl |
||||
{ |
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null; |
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the control.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) { |
||||
if (components != null) { |
||||
components.Dispose(); |
||||
} |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent() |
||||
{ |
||||
this.tree = new System.Windows.Forms.TreeView(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// tree
|
||||
//
|
||||
this.tree.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.tree.HideSelection = false; |
||||
this.tree.Location = new System.Drawing.Point(0, 0); |
||||
this.tree.Name = "tree"; |
||||
this.tree.ShowRootLines = false; |
||||
this.tree.Size = new System.Drawing.Size(186, 182); |
||||
this.tree.TabIndex = 0; |
||||
this.tree.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TreeKeyDown); |
||||
//
|
||||
// AstView
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||
this.Controls.Add(this.tree); |
||||
this.Name = "AstView"; |
||||
this.Size = new System.Drawing.Size(186, 182); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.TreeView tree; |
||||
} |
||||
} |
@ -0,0 +1,225 @@
@@ -0,0 +1,225 @@
|
||||
// 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.Windows.Forms; |
||||
using System.Reflection; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
using ICSharpCode.NRefactory.VB; |
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
public partial class VBDomView |
||||
{ |
||||
CompilationUnit unit; |
||||
|
||||
public CompilationUnit Unit { |
||||
get { |
||||
return unit; |
||||
} |
||||
set { |
||||
if (value != null) { |
||||
unit = value; |
||||
UpdateTree(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void UpdateTree() |
||||
{ |
||||
tree.Nodes.Clear(); |
||||
tree.Nodes.Add(new CollectionNode("CompilationUnit", unit.Children)); |
||||
tree.SelectedNode = tree.Nodes[0]; |
||||
} |
||||
|
||||
public VBDomView() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public void DeleteSelectedNode() |
||||
{ |
||||
if (tree.SelectedNode is ElementNode) { |
||||
INode element = (tree.SelectedNode as ElementNode).element; |
||||
if (tree.SelectedNode.Parent is CollectionNode) { |
||||
if (MessageBox.Show("Remove selected node from parent collection?", "Remove node", MessageBoxButtons.YesNo, MessageBoxIcon.Question) |
||||
== DialogResult.Yes) |
||||
{ |
||||
IList col = (tree.SelectedNode.Parent as CollectionNode).collection; |
||||
col.Remove(element); |
||||
(tree.SelectedNode.Parent as CollectionNode).Update(); |
||||
} |
||||
} else if (tree.SelectedNode.Parent is ElementNode) { |
||||
if (MessageBox.Show("Set selected property to null?", "Remove node", MessageBoxButtons.YesNo, MessageBoxIcon.Question) |
||||
== DialogResult.Yes) |
||||
{ |
||||
// get parent element
|
||||
element = (tree.SelectedNode.Parent as ElementNode).element; |
||||
string propertyName = (string)tree.SelectedNode.Tag; |
||||
element.GetType().GetProperty(propertyName).SetValue(element, null, null); |
||||
(tree.SelectedNode.Parent as ElementNode).Update(); |
||||
} |
||||
} |
||||
} else if (tree.SelectedNode is CollectionNode) { |
||||
if (MessageBox.Show("Remove all elements from selected collection?", "Clear collection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) |
||||
== DialogResult.Yes) |
||||
{ |
||||
IList col = (tree.SelectedNode as CollectionNode).collection; |
||||
col.Clear(); |
||||
(tree.SelectedNode as CollectionNode).Update(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void EditSelectedNode() |
||||
{ |
||||
TreeNode node = tree.SelectedNode; |
||||
while (!(node is ElementNode)) { |
||||
if (node == null) { |
||||
return; |
||||
} |
||||
node = node.Parent; |
||||
} |
||||
INode element = ((ElementNode)node).element; |
||||
using (VBEditDialog dlg = new VBEditDialog(element)) { |
||||
dlg.ShowDialog(); |
||||
} |
||||
((ElementNode)node).Update(); |
||||
} |
||||
|
||||
public void ApplyTransformation(IDomVisitor visitor) |
||||
{ |
||||
if (tree.SelectedNode == tree.Nodes[0]) { |
||||
unit.AcceptVisitor(visitor, null); |
||||
UpdateTree(); |
||||
} else { |
||||
string name = visitor.GetType().Name; |
||||
ElementNode elementNode = tree.SelectedNode as ElementNode; |
||||
CollectionNode collectionNode = tree.SelectedNode as CollectionNode; |
||||
if (elementNode != null) { |
||||
if (MessageBox.Show(("Apply " + name + " to selected element '" + elementNode.Text + "'?"), |
||||
"Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) |
||||
== DialogResult.Yes) |
||||
{ |
||||
elementNode.element.AcceptVisitor(visitor, null); |
||||
elementNode.Update(); |
||||
} |
||||
} else if (collectionNode != null) { |
||||
if (MessageBox.Show(("Apply " + name + " to all elements in selected collection '" + collectionNode.Text + "'?"), |
||||
"Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) |
||||
== DialogResult.Yes) |
||||
{ |
||||
foreach (TreeNode subNode in collectionNode.Nodes) { |
||||
if (subNode is ElementNode) { |
||||
(subNode as ElementNode).element.AcceptVisitor(visitor, null); |
||||
} |
||||
} |
||||
collectionNode.Update(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
static TreeNode CreateNode(object child) |
||||
{ |
||||
if (child == null) { |
||||
return new TreeNode("*null reference*"); |
||||
} else if (child is INode) { |
||||
return new ElementNode(child as INode); |
||||
} else { |
||||
return new TreeNode(child.ToString()); |
||||
} |
||||
} |
||||
|
||||
class CollectionNode : TreeNode |
||||
{ |
||||
internal IList collection; |
||||
string baseName; |
||||
|
||||
public CollectionNode(string text, IList children) : base(text) |
||||
{ |
||||
this.baseName = text; |
||||
this.collection = children; |
||||
Update(); |
||||
} |
||||
|
||||
public void Update() |
||||
{ |
||||
if (collection.Count == 0) { |
||||
Text = baseName + " (empty collection)"; |
||||
} else if (collection.Count == 1) { |
||||
Text = baseName + " (collection with 1 element)"; |
||||
} else { |
||||
Text = baseName + " (collection with " + collection.Count + " elements)"; |
||||
} |
||||
Nodes.Clear(); |
||||
foreach (object child in collection) { |
||||
Nodes.Add(CreateNode(child)); |
||||
} |
||||
Expand(); |
||||
} |
||||
} |
||||
|
||||
class ElementNode : TreeNode |
||||
{ |
||||
internal INode element; |
||||
|
||||
public ElementNode(INode node) |
||||
{ |
||||
this.element = node; |
||||
Update(); |
||||
} |
||||
|
||||
public void Update() |
||||
{ |
||||
Nodes.Clear(); |
||||
Type type = element.GetType(); |
||||
Text = type.Name; |
||||
if (Tag != null) { // HACK: after editing property element
|
||||
Text = Tag.ToString() + " = " + Text; |
||||
} |
||||
if (!(element is INullable && (element as INullable).IsNull)) { |
||||
AddProperties(type, element); |
||||
if (element.Children.Count > 0) { |
||||
Nodes.Add(new CollectionNode("Children", element.Children)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void AddProperties(Type type, INode node) |
||||
{ |
||||
if (type == typeof(AbstractNode)) |
||||
return; |
||||
foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { |
||||
if (pi.DeclaringType != type) // don't add derived properties
|
||||
continue; |
||||
if (pi.Name == "IsNull") |
||||
continue; |
||||
object value = pi.GetValue(node, null); |
||||
if (value is IList) { |
||||
Nodes.Add(new CollectionNode(pi.Name, (IList)value)); |
||||
} else if (value is string) { |
||||
Text += " " + pi.Name + "='" + value + "'"; |
||||
} else { |
||||
TreeNode treeNode = CreateNode(value); |
||||
treeNode.Text = pi.Name + " = " + treeNode.Text; |
||||
treeNode.Tag = pi.Name; |
||||
Nodes.Add(treeNode); |
||||
} |
||||
} |
||||
AddProperties(type.BaseType, node); |
||||
} |
||||
} |
||||
|
||||
void TreeKeyDown(object sender, KeyEventArgs e) |
||||
{ |
||||
if (e.KeyData == Keys.Delete) { |
||||
DeleteSelectedNode(); |
||||
} else if (e.KeyData == Keys.Space || e.KeyData == Keys.Enter) { |
||||
EditSelectedNode(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
</root> |
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
// 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)
|
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
partial class VBEditDialog : System.Windows.Forms.Form |
||||
{ |
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null; |
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) { |
||||
if (components != null) { |
||||
components.Dispose(); |
||||
} |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent() |
||||
{ |
||||
this.propertyGrid = new System.Windows.Forms.PropertyGrid(); |
||||
this.panel1 = new System.Windows.Forms.Panel(); |
||||
this.okButton = new System.Windows.Forms.Button(); |
||||
this.panel1.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// propertyGrid
|
||||
//
|
||||
this.propertyGrid.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.propertyGrid.HelpVisible = false; |
||||
this.propertyGrid.Location = new System.Drawing.Point(0, 0); |
||||
this.propertyGrid.Name = "propertyGrid"; |
||||
this.propertyGrid.PropertySort = System.Windows.Forms.PropertySort.Alphabetical; |
||||
this.propertyGrid.Size = new System.Drawing.Size(477, 436); |
||||
this.propertyGrid.TabIndex = 0; |
||||
this.propertyGrid.ToolbarVisible = false; |
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.okButton); |
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; |
||||
this.panel1.Location = new System.Drawing.Point(0, 436); |
||||
this.panel1.Name = "panel1"; |
||||
this.panel1.Size = new System.Drawing.Size(477, 38); |
||||
this.panel1.TabIndex = 1; |
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
||||
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; |
||||
this.okButton.Location = new System.Drawing.Point(390, 6); |
||||
this.okButton.Name = "okButton"; |
||||
this.okButton.Size = new System.Drawing.Size(75, 23); |
||||
this.okButton.TabIndex = 0; |
||||
this.okButton.Text = "OK"; |
||||
this.okButton.UseVisualStyleBackColor = true; |
||||
//
|
||||
// EditDialog
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||
this.CancelButton = this.okButton; |
||||
this.ClientSize = new System.Drawing.Size(477, 474); |
||||
this.Controls.Add(this.propertyGrid); |
||||
this.Controls.Add(this.panel1); |
||||
this.Name = "EditDialog"; |
||||
this.Text = "EditDialog"; |
||||
this.panel1.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.PropertyGrid propertyGrid; |
||||
private System.Windows.Forms.Button okButton; |
||||
private System.Windows.Forms.Panel panel1; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// 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.Drawing; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.NRefactory.Demo |
||||
{ |
||||
public partial class VBEditDialog |
||||
{ |
||||
public VBEditDialog(object element) |
||||
{ |
||||
InitializeComponent(); |
||||
propertyGrid.SelectedObject = element; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
</root> |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
|
||||
bin/ |
||||
obj/ |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// 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.Reflection; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
[TestFixture] |
||||
public class AstStructureTests |
||||
{ |
||||
[Test] |
||||
public void RolesAreStaticReadOnly() |
||||
{ |
||||
foreach (Type type in typeof(AstNode).Assembly.GetExportedTypes()) { |
||||
if (type.IsSubclassOf(typeof(AstNode))) { |
||||
foreach (FieldInfo field in type.GetFields()) { |
||||
if (field.FieldType.IsSubclassOf(typeof(Role))) { |
||||
Assert.IsTrue(field.IsPublic); |
||||
Assert.IsTrue(field.IsStatic); |
||||
Assert.IsTrue(field.IsInitOnly); |
||||
Assert.IsTrue(field.Name.EndsWith("Role", StringComparison.Ordinal)); |
||||
Assert.IsNotNull(field.GetValue(null)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
// 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.IO; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
[TestFixture] |
||||
public class InsertParenthesesVisitorTests |
||||
{ |
||||
string InsertReadable(Expression expr) |
||||
{ |
||||
expr = expr.Clone(); |
||||
expr.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }, null); |
||||
StringWriter w = new StringWriter(); |
||||
expr.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null); |
||||
return w.ToString(); |
||||
} |
||||
|
||||
string InsertRequired(Expression expr) |
||||
{ |
||||
expr = expr.Clone(); |
||||
expr.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = false }, null); |
||||
StringWriter w = new StringWriter(); |
||||
expr.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null); |
||||
return w.ToString(); |
||||
} |
||||
|
||||
[Test] |
||||
public void EqualityInAssignment() |
||||
{ |
||||
Expression expr = new AssignmentExpression( |
||||
new IdentifierExpression("cond"), |
||||
new BinaryOperatorExpression( |
||||
new IdentifierExpression("a"), |
||||
BinaryOperatorType.Equality, |
||||
new IdentifierExpression("b") |
||||
) |
||||
); |
||||
|
||||
Assert.AreEqual("cond = a == b", InsertRequired(expr)); |
||||
Assert.AreEqual("cond = (a == b)", InsertReadable(expr)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TrickyCast1() |
||||
{ |
||||
Expression expr = new UnaryOperatorExpression( |
||||
UnaryOperatorType.Minus, new IdentifierExpression("a") |
||||
).CastTo(new PrimitiveType("int")); |
||||
|
||||
Assert.AreEqual("(int)-a", InsertRequired(expr)); |
||||
Assert.AreEqual("(int)(-a)", InsertReadable(expr)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TrickyCast2() |
||||
{ |
||||
Expression expr = new UnaryOperatorExpression( |
||||
UnaryOperatorType.Minus, new IdentifierExpression("a") |
||||
).CastTo(new SimpleType("MyType")); |
||||
|
||||
Assert.AreEqual("(MyType)(-a)", InsertRequired(expr)); |
||||
Assert.AreEqual("(MyType)(-a)", InsertReadable(expr)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TrickyCast3() |
||||
{ |
||||
Expression expr = new UnaryOperatorExpression( |
||||
UnaryOperatorType.Not, new IdentifierExpression("a") |
||||
).CastTo(new SimpleType("MyType")); |
||||
|
||||
Assert.AreEqual("(MyType)!a", InsertRequired(expr)); |
||||
Assert.AreEqual("(MyType)(!a)", InsertReadable(expr)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CastAndInvoke() |
||||
{ |
||||
Expression expr = new IdentifierExpression("a") |
||||
.CastTo(new PrimitiveType("string")) |
||||
.Member("Length"); |
||||
|
||||
Assert.AreEqual("((string)a).Length", InsertRequired(expr)); |
||||
Assert.AreEqual("((string)a).Length", InsertReadable(expr)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// 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.IO; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class AliasReferenceExpressionTests |
||||
{ |
||||
[Test, Ignore] |
||||
public void GlobalReferenceExpressionTest() |
||||
{ |
||||
CSharpParser parser = new CSharpParser(); |
||||
parser.ParseTypeReference(new StringReader("global::System")); |
||||
//Assert.IsTrue(tre.TypeReference.IsGlobal);
|
||||
//Assert.AreEqual("System", tre.TypeReference.Type);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void GlobalTypeDeclaration() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("global::System.String a;"); |
||||
//TypeReference typeRef = lvd.GetTypeForVariable(0);
|
||||
//Assert.IsTrue(typeRef.IsGlobal);
|
||||
//Assert.AreEqual("System.String", typeRef.Type);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
// TODO: add tests for aliases other than 'global'
|
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// 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.IO; |
||||
using System.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class AnonymousMethodTests |
||||
{ |
||||
AnonymousMethodExpression Parse(string expression) |
||||
{ |
||||
return ParseUtilCSharp.ParseExpression<AnonymousMethodExpression>(expression); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnonymousMethodWithoutParameterList() |
||||
{ |
||||
AnonymousMethodExpression ame = Parse("delegate {}"); |
||||
Assert.AreEqual(0, ame.Parameters.Count()); |
||||
Assert.AreEqual(0, ame.Body.Statements.Count()); |
||||
Assert.IsFalse(ame.HasParameterList); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnonymousMethodAfterCast() |
||||
{ |
||||
CastExpression c = ParseUtilCSharp.ParseExpression<CastExpression>("(ThreadStart)delegate {}"); |
||||
AnonymousMethodExpression ame = (AnonymousMethodExpression)c.Expression; |
||||
Assert.AreEqual(0, ame.Parameters.Count()); |
||||
Assert.AreEqual(0, ame.Body.Statements.Count()); |
||||
} |
||||
|
||||
[Test, Ignore("Parameter list is broken")] |
||||
public void EmptyAnonymousMethod() |
||||
{ |
||||
AnonymousMethodExpression ame = Parse("delegate() {}"); |
||||
Assert.AreEqual(0, ame.Parameters.Count()); |
||||
Assert.AreEqual(0, ame.Body.Statements.Count()); |
||||
Assert.IsTrue(ame.HasParameterList); |
||||
} |
||||
|
||||
[Test, Ignore("Parameter list is broken")] |
||||
public void SimpleAnonymousMethod() |
||||
{ |
||||
AnonymousMethodExpression ame = Parse("delegate(int a, int b) { return a + b; }"); |
||||
Assert.AreEqual(2, ame.Parameters.Count()); |
||||
Assert.AreEqual(1, ame.Body.Statements.Count()); |
||||
Assert.IsTrue(ame.Body.Children.First() is ReturnStatement); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore("Needs to be ported to new NRefactory")] |
||||
public class ArrayObjectCreateExpressionTests |
||||
{ |
||||
[Test] |
||||
public void ArrayCreateExpressionTest1() |
||||
{ |
||||
/* |
||||
ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression<ArrayCreateExpression>("new int[5]"); |
||||
Assert.AreEqual("System.Int32", ace.CreateType.Type); |
||||
Assert.IsTrue(ace.CreateType.IsKeyword); |
||||
Assert.AreEqual(1, ace.Arguments.Count); |
||||
Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier); |
||||
*/ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedArrayCreateExpression() |
||||
{ |
||||
/* |
||||
ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression<ArrayCreateExpression>("new[] { 1, 10, 100, 1000 }"); |
||||
Assert.AreEqual("", ace.CreateType.Type); |
||||
Assert.AreEqual(0, ace.Arguments.Count); |
||||
Assert.AreEqual(4, ace.ArrayInitializer.CreateExpressions.Count);*/ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class AssignmentExpressionTests |
||||
{ |
||||
void TestAssignmentExpression(string program, AssignmentOperatorType op) |
||||
{ |
||||
AssignmentExpression ae = ParseUtilCSharp.ParseExpression<AssignmentExpression>(program); |
||||
|
||||
Assert.AreEqual(op, ae.Operator); |
||||
|
||||
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 ModulusTest() |
||||
{ |
||||
TestAssignmentExpression("a %= b", AssignmentOperatorType.Modulus); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShiftLeftTest() |
||||
{ |
||||
TestAssignmentExpression("a <<= b", AssignmentOperatorType.ShiftLeft); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShiftRightTest() |
||||
{ |
||||
TestAssignmentExpression("a >>= b", AssignmentOperatorType.ShiftRight); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitwiseAndTest() |
||||
{ |
||||
TestAssignmentExpression("a &= b", AssignmentOperatorType.BitwiseAnd); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitwiseOrTest() |
||||
{ |
||||
TestAssignmentExpression("a |= b", AssignmentOperatorType.BitwiseOr); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclusiveOrTest() |
||||
{ |
||||
TestAssignmentExpression("a ^= b", AssignmentOperatorType.ExclusiveOr); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class BaseReferenceExpressionTests |
||||
{ |
||||
[Test] |
||||
public void BaseReferenceExpressionTest1() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("base.myField"); |
||||
Assert.IsTrue(fre.Target is BaseReferenceExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,227 @@
@@ -0,0 +1,227 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class BinaryOperatorExpressionTests |
||||
{ |
||||
#region Precedence Tests
|
||||
void OperatorPrecedenceTest(string strongOperator, BinaryOperatorType strongOperatorType, |
||||
string weakOperator, BinaryOperatorType weakOperatorType, bool vb) |
||||
{ |
||||
string program = "a " + weakOperator + " b " + strongOperator + " c"; |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(weakOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
boe = (BinaryOperatorExpression)boe.Right; |
||||
Assert.AreEqual(strongOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
|
||||
program = "a " + strongOperator + " b " + weakOperator + " c"; |
||||
|
||||
boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(weakOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
boe = (BinaryOperatorExpression)boe.Left; |
||||
Assert.AreEqual(strongOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
} |
||||
|
||||
void SameOperatorPrecedenceTest(string firstOperator, BinaryOperatorType firstOperatorType, |
||||
string secondOperator, BinaryOperatorType secondOperatorType, bool vb) |
||||
{ |
||||
string program = "a " + secondOperator + " b " + firstOperator + " c"; |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(firstOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
boe = (BinaryOperatorExpression)boe.Left; |
||||
Assert.AreEqual(secondOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
|
||||
program = "a " + firstOperator + " b " + secondOperator + " c"; |
||||
boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(secondOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
boe = (BinaryOperatorExpression)boe.Left; |
||||
Assert.AreEqual(firstOperatorType, boe.Operator); |
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void OperatorPrecedenceTest() |
||||
{ |
||||
SameOperatorPrecedenceTest("*", BinaryOperatorType.Multiply, "/", BinaryOperatorType.Divide, false); |
||||
SameOperatorPrecedenceTest("*", BinaryOperatorType.Multiply, "%", BinaryOperatorType.Modulus, false); |
||||
OperatorPrecedenceTest("*", BinaryOperatorType.Multiply, "+", BinaryOperatorType.Add, false); |
||||
SameOperatorPrecedenceTest("-", BinaryOperatorType.Subtract, "+", BinaryOperatorType.Add, false); |
||||
OperatorPrecedenceTest("+", BinaryOperatorType.Add, "<<", BinaryOperatorType.ShiftLeft, false); |
||||
SameOperatorPrecedenceTest(">>", BinaryOperatorType.ShiftRight, "<<", BinaryOperatorType.ShiftLeft, false); |
||||
OperatorPrecedenceTest("<<", BinaryOperatorType.ShiftLeft, "==", BinaryOperatorType.Equality, false); |
||||
SameOperatorPrecedenceTest("!=", BinaryOperatorType.InEquality, "==", BinaryOperatorType.Equality, false); |
||||
OperatorPrecedenceTest("==", BinaryOperatorType.Equality, "&", BinaryOperatorType.BitwiseAnd, false); |
||||
OperatorPrecedenceTest("&", BinaryOperatorType.BitwiseAnd, "^", BinaryOperatorType.ExclusiveOr, false); |
||||
OperatorPrecedenceTest("^", BinaryOperatorType.ExclusiveOr, "|", BinaryOperatorType.BitwiseOr, false); |
||||
OperatorPrecedenceTest("|", BinaryOperatorType.BitwiseOr, "&&", BinaryOperatorType.ConditionalAnd, false); |
||||
OperatorPrecedenceTest("&&", BinaryOperatorType.ConditionalAnd, "||", BinaryOperatorType.ConditionalOr, false); |
||||
OperatorPrecedenceTest("||", BinaryOperatorType.ConditionalOr, "??", BinaryOperatorType.NullCoalescing, false); |
||||
} |
||||
#endregion
|
||||
|
||||
void TestBinaryOperatorExpressionTest(string program, BinaryOperatorType op) |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program); |
||||
Assert.AreEqual(op, boe.Operator); |
||||
|
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
|
||||
} |
||||
|
||||
[Test] |
||||
public void SubtractionLeftToRight() |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("a - b - c"); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
Assert.IsTrue(boe.Left is BinaryOperatorExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullCoalescingRightToLeft() |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("a ?? b ?? c"); |
||||
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||
Assert.IsTrue(boe.Right is BinaryOperatorExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitwiseAndTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a & b", BinaryOperatorType.BitwiseAnd); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitwiseOrTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a | b", BinaryOperatorType.BitwiseOr); |
||||
} |
||||
|
||||
[Test] |
||||
public void LogicalAndTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a && b", BinaryOperatorType.ConditionalAnd); |
||||
} |
||||
|
||||
[Test] |
||||
public void LogicalOrTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a || b", BinaryOperatorType.ConditionalOr); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclusiveOrTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a ^ b", BinaryOperatorType.ExclusiveOr); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void GreaterThanTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a > b", BinaryOperatorType.GreaterThan); |
||||
} |
||||
|
||||
[Test] |
||||
public void GreaterThanOrEqualTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a >= b", BinaryOperatorType.GreaterThanOrEqual); |
||||
} |
||||
|
||||
[Test] |
||||
public void EqualityTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a == b", BinaryOperatorType.Equality); |
||||
} |
||||
|
||||
[Test] |
||||
public void InEqualityTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a != b", BinaryOperatorType.InEquality); |
||||
} |
||||
|
||||
[Test] |
||||
public void LessThanTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a < b", BinaryOperatorType.LessThan); |
||||
} |
||||
|
||||
[Test] |
||||
public void LessThanOrEqualTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a <= b", BinaryOperatorType.LessThanOrEqual); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a + b", BinaryOperatorType.Add); |
||||
} |
||||
|
||||
[Test] |
||||
public void SubtractTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a - b", BinaryOperatorType.Subtract); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultiplyTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a * b", BinaryOperatorType.Multiply); |
||||
} |
||||
|
||||
[Test] |
||||
public void DivideTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a / b", BinaryOperatorType.Divide); |
||||
} |
||||
|
||||
[Test] |
||||
public void ModulusTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a % b", BinaryOperatorType.Modulus); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShiftLeftTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a << b", BinaryOperatorType.ShiftLeft); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShiftRightTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a >> b", BinaryOperatorType.ShiftRight); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullCoalescingTest() |
||||
{ |
||||
TestBinaryOperatorExpressionTest("a ?? b", BinaryOperatorType.NullCoalescing); |
||||
} |
||||
|
||||
[Test] |
||||
public void LessThanOrGreaterTest() |
||||
{ |
||||
const string expr = "i1 < 0 || i1 > (Count - 1)"; |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(expr); |
||||
Assert.AreEqual(BinaryOperatorType.ConditionalOr, boe.Operator); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore("Port unit tests to new DOM")] |
||||
public class CastExpressionTests |
||||
{ |
||||
/* |
||||
[Test] |
||||
public void SimpleCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyObject)o"); |
||||
Assert.AreEqual("MyObject", ce.CastTo.Type); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType[])o"); |
||||
Assert.AreEqual("MyType", ce.CastTo.Type); |
||||
Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullablePrimitiveCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(int?)o"); |
||||
Assert.AreEqual("System.Nullable", ce.CastTo.Type); |
||||
Assert.AreEqual("System.Int32", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType?)o"); |
||||
Assert.AreEqual("System.Nullable", ce.CastTo.Type); |
||||
Assert.AreEqual("MyType", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableTryCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("o as int?"); |
||||
Assert.AreEqual("System.Nullable", ce.CastTo.Type); |
||||
Assert.IsTrue(ce.CastTo.IsKeyword); |
||||
Assert.AreEqual("System.Int32", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.TryCast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(List<string>)o"); |
||||
Assert.AreEqual("List", ce.CastTo.Type); |
||||
Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericArrayCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(List<string>[])o"); |
||||
Assert.AreEqual("List", ce.CastTo.Type); |
||||
Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericArrayAsCastExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("o as List<string>[]"); |
||||
Assert.AreEqual("List", ce.CastTo.Type); |
||||
Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type); |
||||
Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
Assert.AreEqual(CastType.TryCast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void CastMemberReferenceOnParenthesizedExpression() |
||||
{ |
||||
// yes, we really wanted to evaluate .Member on expr and THEN cast the result to MyType
|
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType)(expr).Member"); |
||||
Assert.AreEqual("MyType", ce.CastTo.Type); |
||||
Assert.IsTrue(ce.Expression is MemberReferenceExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void TryCastParenthesizedExpression() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(o) as string"); |
||||
Assert.AreEqual("System.String", ce.CastTo.ToString()); |
||||
Assert.IsTrue(ce.Expression is ParenthesizedExpression); |
||||
Assert.AreEqual(CastType.TryCast, ce.CastType); |
||||
} |
||||
|
||||
[Test] |
||||
public void CastNegation() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(uint)-negativeValue"); |
||||
Assert.AreEqual("System.UInt32", ce.CastTo.ToString()); |
||||
Assert.IsTrue(ce.Expression is UnaryOperatorExpression); |
||||
Assert.AreEqual(CastType.Cast, ce.CastType); |
||||
} |
||||
*/ |
||||
|
||||
[Test] |
||||
public void SubtractionIsNotCast() |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("(BigInt)-negativeValue"); |
||||
Assert.IsTrue(boe.Left is ParenthesizedExpression); |
||||
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void IntMaxValueToBigInt() |
||||
{ |
||||
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(BigInt)int.MaxValue"); |
||||
Assert.AreEqual("BigInt", ce.Type.ToString()); |
||||
Assert.IsTrue(ce.Expression is MemberReferenceExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class CheckedExpressionTests |
||||
{ |
||||
[Test] |
||||
public void CheckedExpressionTest() |
||||
{ |
||||
CheckedExpression ce = ParseUtilCSharp.ParseExpression<CheckedExpression>("checked(a)"); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void UncheckedExpressionTest() |
||||
{ |
||||
UncheckedExpression ce = ParseUtilCSharp.ParseExpression<UncheckedExpression>("unchecked(a)"); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class ConditionalExpressionTests |
||||
{ |
||||
[Test] |
||||
public void ConditionalExpressionTest() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a == b ? a() : a.B"); |
||||
|
||||
Assert.IsTrue(ce.Condition is BinaryOperatorExpression); |
||||
Assert.IsTrue(ce.TrueExpression is InvocationExpression); |
||||
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConditionalIsExpressionTest() |
||||
{ |
||||
// (as is b?) ERROR (conflict with nullables, SD-419)
|
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b ? a() : a.B"); |
||||
|
||||
Assert.IsTrue(ce.Condition is IsExpression); |
||||
Assert.IsTrue(ce.TrueExpression is InvocationExpression); |
||||
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression); |
||||
} |
||||
|
||||
[Test, Ignore("crashes the parser")] |
||||
public void ConditionalIsWithNullableExpressionTest() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b? ? a() : a.B"); |
||||
|
||||
Assert.IsTrue(ce.Condition is IsExpression); |
||||
Assert.IsTrue(ce.TrueExpression is InvocationExpression); |
||||
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConditionalIsExpressionTest2() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b ? (a()) : a.B"); |
||||
|
||||
Assert.IsTrue(ce.Condition is IsExpression); |
||||
Assert.IsTrue(ce.TrueExpression is ParenthesizedExpression); |
||||
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConditionalExpressionNegativeValue() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("isNegative ? -1 : 1"); |
||||
|
||||
Assert.IsTrue(ce.Condition is IdentifierExpression); |
||||
Assert.IsTrue(ce.TrueExpression is UnaryOperatorExpression); |
||||
Assert.IsTrue(ce.FalseExpression is PrimitiveExpression); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void ConditionalIsWithNegativeValue() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b ? -1 : 1"); |
||||
|
||||
Assert.IsTrue(ce.Condition is IsExpression); |
||||
Assert.IsTrue(ce.TrueExpression is UnaryOperatorExpression); |
||||
Assert.IsTrue(ce.FalseExpression is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConditionalIsWithExplicitPositiveValue() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b ? +1 : 1"); |
||||
|
||||
Assert.IsTrue(ce.Condition is IsExpression); |
||||
Assert.IsTrue(ce.TrueExpression is UnaryOperatorExpression); |
||||
Assert.IsTrue(ce.FalseExpression is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void RepeatedConditionalExpr() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a ? b : c ? d : e"); |
||||
|
||||
Assert.AreEqual("a", ((IdentifierExpression)ce.Condition).Identifier); |
||||
Assert.AreEqual("b", ((IdentifierExpression)ce.TrueExpression).Identifier); |
||||
Assert.IsTrue(ce.FalseExpression is ConditionalExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedConditionalExpr() |
||||
{ |
||||
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a ? b ? c : d : e"); |
||||
|
||||
Assert.AreEqual("a", ((IdentifierExpression)ce.Condition).Identifier); |
||||
Assert.AreEqual("e", ((IdentifierExpression)ce.FalseExpression).Identifier); |
||||
Assert.IsTrue(ce.TrueExpression is ConditionalExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore("tests need to be ported")] |
||||
public class DefaultValueExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleDefaultValue() |
||||
{ |
||||
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(T)"); |
||||
Assert.AreEqual("T", toe.Type); |
||||
} |
||||
|
||||
/* |
||||
[Test] |
||||
public void FullQualifiedDefaultValue() |
||||
{ |
||||
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(global::MyNamespace.N1.MyType)"); |
||||
Assert.IsTrue(toe.TypeReference.IsGlobal); |
||||
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericDefaultValue() |
||||
{ |
||||
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(MyNamespace.N1.MyType<string>)"); |
||||
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); |
||||
Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultValueAsIntializer() |
||||
{ |
||||
// This test is failing because we need a resolver for the "default:" / "default(" conflict.
|
||||
LocalVariableDeclaration lvd = ParseUtilCSharp.ParseStatement<LocalVariableDeclaration>("T a = default(T);"); |
||||
DefaultValueExpression dve = (DefaultValueExpression)lvd.Variables[0].Initializer; |
||||
Assert.AreEqual("T", dve.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultValueInReturnStatement() |
||||
{ |
||||
ReturnStatement rs = ParseUtilCSharp.ParseStatement<ReturnStatement>("return default(T);"); |
||||
DefaultValueExpression dve = (DefaultValueExpression)rs.Expression; |
||||
Assert.AreEqual("T", dve.TypeReference.Type); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class IdentifierExpressionTests |
||||
{ |
||||
void CheckIdentifier(string sourceCode, string identifier) |
||||
{ |
||||
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>(sourceCode); |
||||
Assert.AreEqual(identifier, ident.Identifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestIdentifier() |
||||
{ |
||||
CheckIdentifier("a_Bc05", "a_Bc05"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestIdentifierStartingWithUnderscore() |
||||
{ |
||||
CheckIdentifier("_Bc05", "_Bc05"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestIdentifierStartingWithEscapeSequence() |
||||
{ |
||||
CheckIdentifier(@"\u006cexer", "lexer"); |
||||
} |
||||
|
||||
[Test, Ignore("Mono parser bug?")] |
||||
public void TestIdentifierContainingEscapeSequence() |
||||
{ |
||||
CheckIdentifier(@"l\U00000065xer", "lexer"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestKeyWordAsIdentifier() |
||||
{ |
||||
CheckIdentifier("@int", "int"); |
||||
} |
||||
|
||||
[Test, Ignore("Mono parser bug?")] |
||||
public void TestKeywordWithEscapeSequenceIsIdentifier() |
||||
{ |
||||
CheckIdentifier(@"i\u006et", "int"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestKeyWordAsIdentifierStartingWithUnderscore() |
||||
{ |
||||
CheckIdentifier("@_int", "_int"); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void GenericMethodReference() |
||||
{ |
||||
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("M<int>"); |
||||
Assert.AreEqual("M", ident.Identifier); |
||||
//Assert.AreEqual(1, ident.TypeArguments.Count);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void GenericMethodReference2() |
||||
{ |
||||
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("TargetMethod<string>"); |
||||
Assert.AreEqual("TargetMethod", ident.Identifier); |
||||
//Assert.AreEqual(1, ident.TypeArguments.Count);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class IndexerExpressionTests |
||||
{ |
||||
[Test] |
||||
public void IndexerExpressionTest() |
||||
{ |
||||
IndexerExpression ie = ParseUtilCSharp.ParseExpression<IndexerExpression>("field[1, \"Hello\", 'a']"); |
||||
Assert.IsTrue(ie.Target is IdentifierExpression); |
||||
|
||||
Assert.AreEqual(3, ie.Arguments.Count()); |
||||
|
||||
Assert.IsTrue(ie.Arguments.ElementAt(0) is PrimitiveExpression); |
||||
Assert.AreEqual(1, (int)((PrimitiveExpression)ie.Arguments.ElementAt(0)).Value); |
||||
Assert.IsTrue(ie.Arguments.ElementAt(1) is PrimitiveExpression); |
||||
Assert.AreEqual("Hello", (string)((PrimitiveExpression)ie.Arguments.ElementAt(1)).Value); |
||||
Assert.IsTrue(ie.Arguments.ElementAt(2) is PrimitiveExpression); |
||||
Assert.AreEqual('a', (char)((PrimitiveExpression)ie.Arguments.ElementAt(2)).Value); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,155 @@
@@ -0,0 +1,155 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore("Port unit tests to new DOM")] |
||||
public class InvocationExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleInvocationExpressionTest() |
||||
{ |
||||
var ie = ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod()"); |
||||
Assert.AreEqual(0, ie.Arguments.Count()); |
||||
Assert.IsTrue(ie.Target is IdentifierExpression); |
||||
Assert.AreEqual("myMethod", ((IdentifierExpression)ie.Target).Identifier); |
||||
} |
||||
|
||||
/* TODO port unit tests to new DOM |
||||
[Test] |
||||
public void GenericInvocationExpressionTest() |
||||
{ |
||||
var expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod<char>('a')"); |
||||
Assert.AreEqual(1, expr.Arguments.Count()); |
||||
Assert.IsTrue(expr.TargetObject is IdentifierExpression); |
||||
IdentifierExpression ident = (IdentifierExpression)expr.TargetObject; |
||||
Assert.AreEqual("myMethod", ident.Identifier); |
||||
Assert.AreEqual(1, ident.TypeArguments.Count); |
||||
Assert.AreEqual("System.Char", ident.TypeArguments[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericInvocation2ExpressionTest() |
||||
{ |
||||
var expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod<T,bool>()"); |
||||
Assert.AreEqual(0, expr.Arguments.Count); |
||||
Assert.IsTrue(expr.TargetObject is IdentifierExpression); |
||||
IdentifierExpression ident = (IdentifierExpression)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); |
||||
} |
||||
|
||||
[Test] |
||||
public void AmbiguousGrammarGenericMethodCall() |
||||
{ |
||||
InvocationExpression ie = ParseUtilCSharp.ParseExpression<InvocationExpression>("F(G<A,B>(7))"); |
||||
Assert.IsTrue(ie.TargetObject is IdentifierExpression); |
||||
Assert.AreEqual(1, ie.Arguments.Count); |
||||
ie = (InvocationExpression)ie.Arguments[0]; |
||||
Assert.AreEqual(1, ie.Arguments.Count); |
||||
Assert.IsTrue(ie.Arguments[0] is PrimitiveExpression); |
||||
IdentifierExpression ident = (IdentifierExpression)ie.TargetObject; |
||||
Assert.AreEqual("G", ident.Identifier); |
||||
Assert.AreEqual(2, ident.TypeArguments.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void AmbiguousGrammarNotAGenericMethodCall() |
||||
{ |
||||
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("F<A>+y"); |
||||
Assert.AreEqual(BinaryOperatorType.GreaterThan, boe.Op); |
||||
Assert.IsTrue(boe.Left is BinaryOperatorExpression); |
||||
Assert.IsTrue(boe.Right is UnaryOperatorExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidNestedInvocationExpressionTest() |
||||
{ |
||||
// this test was written because this bug caused the AbstractASTVisitor to crash
|
||||
|
||||
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("WriteLine(myMethod(,))", true); |
||||
Assert.IsTrue(expr.TargetObject is IdentifierExpression); |
||||
Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.TargetObject).Identifier); |
||||
|
||||
Assert.AreEqual(1, expr.Arguments.Count); // here a second null parameter was added incorrectly
|
||||
|
||||
Assert.IsTrue(expr.Arguments[0] is InvocationExpression); |
||||
CheckSimpleInvoke((InvocationExpression)expr.Arguments[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedInvocationPositions() |
||||
{ |
||||
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("a.B().C(args)"); |
||||
Assert.AreEqual(new Location(8, 1), expr.StartLocation); |
||||
Assert.AreEqual(new Location(14, 1), expr.EndLocation); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual(new Location(6, 1), mre.StartLocation); |
||||
Assert.AreEqual(new Location(8, 1), mre.EndLocation); |
||||
|
||||
Assert.AreEqual(new Location(4, 1), mre.TargetObject.StartLocation); |
||||
Assert.AreEqual(new Location(6, 1), mre.TargetObject.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvocationOnGenericType() |
||||
{ |
||||
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("A<T>.Foo()"); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual("Foo", mre.MemberName); |
||||
TypeReferenceExpression tre = (TypeReferenceExpression)mre.TargetObject; |
||||
Assert.AreEqual("A", tre.TypeReference.Type); |
||||
Assert.AreEqual("T", tre.TypeReference.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvocationOnInnerClassInGenericType() |
||||
{ |
||||
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("A<T>.B.Foo()"); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual("Foo", mre.MemberName); |
||||
MemberReferenceExpression mre2 = (MemberReferenceExpression)mre.TargetObject; |
||||
Assert.AreEqual("B", mre2.MemberName); |
||||
TypeReferenceExpression tre = (TypeReferenceExpression)mre2.TargetObject; |
||||
Assert.AreEqual("A", tre.TypeReference.Type); |
||||
Assert.AreEqual("T", tre.TypeReference.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvocationOnGenericInnerClassInGenericType() |
||||
{ |
||||
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("A<T>.B.C<U>.Foo()"); |
||||
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject; |
||||
Assert.AreEqual("Foo", mre.MemberName); |
||||
TypeReferenceExpression tre = (TypeReferenceExpression)mre.TargetObject; |
||||
InnerClassTypeReference ictr = (InnerClassTypeReference)tre.TypeReference; |
||||
Assert.AreEqual("B.C", ictr.Type); |
||||
Assert.AreEqual(1, ictr.GenericTypes.Count); |
||||
Assert.AreEqual("U", ictr.GenericTypes[0].Type); |
||||
|
||||
Assert.AreEqual("A", ictr.BaseType.Type); |
||||
Assert.AreEqual(1, ictr.BaseType.GenericTypes.Count); |
||||
Assert.AreEqual("T", ictr.BaseType.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvocationWithNamedArgument() |
||||
{ |
||||
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("a(arg: ref v)"); |
||||
Assert.AreEqual(1, expr.Arguments.Count); |
||||
NamedArgumentExpression nae = (NamedArgumentExpression)expr.Arguments[0]; |
||||
Assert.AreEqual("arg", nae.Name); |
||||
DirectionExpression dir = (DirectionExpression)nae.Expression; |
||||
Assert.AreEqual(FieldDirection.Ref, dir.FieldDirection); |
||||
Assert.IsInstanceOf<IdentifierExpression>(dir.Expression); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class IsExpressionTests |
||||
{ |
||||
[Test, Ignore] |
||||
public void GenericArrayIsExpression() |
||||
{ |
||||
/* TODO |
||||
TypeOfIsExpression ce = ParseUtilCSharp.ParseExpression<TypeOfIsExpression>("o is List<string>[]"); |
||||
Assert.AreEqual("List", ce.TypeReference.Type); |
||||
Assert.AreEqual("System.String", ce.TypeReference.GenericTypes[0].Type); |
||||
Assert.AreEqual(new int[] { 0 }, ce.TypeReference.RankSpecifier); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression);*/ |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableIsExpression() |
||||
{ |
||||
IsExpression ce = ParseUtilCSharp.ParseExpression<IsExpression>("o is int?"); |
||||
ComposedType type = (ComposedType)ce.Type; |
||||
Assert.IsTrue(type.HasNullableSpecifier); |
||||
Assert.AreEqual("int", ((PrimitiveType)type.BaseType).Keyword); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableIsExpressionInBinaryOperatorExpression() |
||||
{ |
||||
BinaryOperatorExpression boe; |
||||
boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("o is int? == true"); |
||||
IsExpression ce = (IsExpression)boe.Left; |
||||
ComposedType type = (ComposedType)ce.Type; |
||||
Assert.IsTrue(type.HasNullableSpecifier); |
||||
Assert.AreEqual("int", ((PrimitiveType)type.BaseType).Keyword); |
||||
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore("Port unit tests")] |
||||
public class LambdaExpressionTests |
||||
{ |
||||
static LambdaExpression ParseCSharp(string program) |
||||
{ |
||||
return ParseUtilCSharp.ParseExpression<LambdaExpression>(program); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedExpressionBody() |
||||
{ |
||||
/* |
||||
LambdaExpression e = ParseCSharp("(x) => x + 1"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); |
||||
Assert.IsTrue(e.ReturnType.IsNull);*/ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* TODO Port unit tests |
||||
[Test] |
||||
public void ImplicitlyTypedExpressionBodyWithoutParenthesis() |
||||
{ |
||||
LambdaExpression e = ParseCSharp("x => x + 1"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedStatementBody() |
||||
{ |
||||
LambdaExpression e = ParseCSharp("(x) => { return x + 1; }"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedStatementBodyWithoutParenthesis() |
||||
{ |
||||
LambdaExpression e = ParseCSharp("x => { return x + 1; }"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitlyTypedStatementBody() |
||||
{ |
||||
LambdaExpression e = ParseCSharp("(int x) => { return x + 1; }"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.AreEqual("System.Int32", e.Parameters[0].TypeReference.Type); |
||||
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitlyTypedStatementBodyWithRefParameter() |
||||
{ |
||||
LambdaExpression e = ParseCSharp("(ref int i) => i = 1"); |
||||
Assert.AreEqual("i", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue((e.Parameters[0].ParamModifier & ParameterModifiers.Ref) == ParameterModifiers.Ref); |
||||
Assert.AreEqual("System.Int32", e.Parameters[0].TypeReference.Type); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaExpressionContainingConditionalExpression() |
||||
{ |
||||
LambdaExpression e = ParseCSharp("rr => rr != null ? rr.ResolvedType : null"); |
||||
Assert.AreEqual("rr", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.ExpressionBody is ConditionalExpression); |
||||
Assert.IsTrue(e.ReturnType.IsNull); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class MemberReferenceExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("myTargetObject.myField"); |
||||
//Assert.AreEqual("myField", fre.MemberName);
|
||||
//Assert.IsTrue(fre.TargetObject is IdentifierExpression);
|
||||
//Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* TODO port unit tests |
||||
[Test] |
||||
public void GenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("SomeClass<string>.myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); |
||||
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; |
||||
Assert.AreEqual("SomeClass", tr.Type); |
||||
Assert.AreEqual(1, tr.GenericTypes.Count); |
||||
Assert.AreEqual("System.String", tr.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void FullNamespaceGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("Namespace.Subnamespace.SomeClass<string>.myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); |
||||
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; |
||||
Assert.AreEqual("Namespace.Subnamespace.SomeClass", tr.Type); |
||||
Assert.AreEqual(1, tr.GenericTypes.Count); |
||||
Assert.AreEqual("System.String", tr.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void GlobalFullNamespaceGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("global::Namespace.Subnamespace.SomeClass<string>.myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); |
||||
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; |
||||
Assert.IsFalse(tr is InnerClassTypeReference); |
||||
Assert.AreEqual("Namespace.Subnamespace.SomeClass", tr.Type); |
||||
Assert.AreEqual(1, tr.GenericTypes.Count); |
||||
Assert.AreEqual("System.String", tr.GenericTypes[0].Type); |
||||
Assert.IsTrue(tr.IsGlobal); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedGenericFieldReferenceExpressionTest() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("MyType<string>.InnerClass<int>.myField"); |
||||
Assert.AreEqual("myField", fre.MemberName); |
||||
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); |
||||
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference; |
||||
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); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class ParenthesizedExpressionTests |
||||
{ |
||||
[Test] |
||||
public void PrimitiveParenthesizedExpression() |
||||
{ |
||||
ParenthesizedExpression p = ParseUtilCSharp.ParseExpression<ParenthesizedExpression>("((1))"); |
||||
Assert.IsTrue(p.Expression is ParenthesizedExpression); |
||||
p = (ParenthesizedExpression)p.Expression; |
||||
Assert.IsTrue(p.Expression is PrimitiveExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class PointerReferenceExpressionTests |
||||
{ |
||||
[Test, Ignore("where did PointerReferenceExpression.MemberName go?")] |
||||
public void PointerReferenceExpressionTest() |
||||
{ |
||||
PointerReferenceExpression pre = ParseUtilCSharp.ParseExpression<PointerReferenceExpression>("myObj.field->b"); |
||||
Assert.IsTrue(pre.Target is MemberReferenceExpression); |
||||
//Assert.AreEqual("b", pre.MemberName);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,203 @@
@@ -0,0 +1,203 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class PrimitiveExpressionTests |
||||
{ |
||||
[Test] |
||||
public void HexIntegerTest1() |
||||
{ |
||||
InvocationExpression invExpr = ParseUtilCSharp.ParseExpression<InvocationExpression>("0xAFFE.ToString()"); |
||||
Assert.AreEqual(0, invExpr.Arguments.Count()); |
||||
Assert.IsTrue(invExpr.Target is MemberReferenceExpression); |
||||
MemberReferenceExpression fre = invExpr.Target as MemberReferenceExpression; |
||||
Assert.AreEqual("ToString", fre.MemberName); |
||||
|
||||
Assert.IsTrue(fre.Target is PrimitiveExpression); |
||||
PrimitiveExpression pe = fre.Target as PrimitiveExpression; |
||||
|
||||
Assert.AreEqual(0xAFFE, (int)pe.Value); |
||||
|
||||
} |
||||
|
||||
void CheckLiteral(string code, object value) |
||||
{ |
||||
PrimitiveExpression pe = ParseUtilCSharp.ParseExpression<PrimitiveExpression>(code); |
||||
Assert.AreEqual(value.GetType(), pe.Value.GetType()); |
||||
Assert.AreEqual(value, pe.Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void DoubleTest1() |
||||
{ |
||||
CheckLiteral(".5e-06", .5e-06); |
||||
} |
||||
|
||||
[Test] |
||||
public void CharTest1() |
||||
{ |
||||
CheckLiteral("'\\u0356'", '\u0356'); |
||||
} |
||||
|
||||
[Test, Ignore("this special case isn't implemented yet")] |
||||
public void IntMinValueTest() |
||||
{ |
||||
CheckLiteral("-2147483648", -2147483648); |
||||
} |
||||
|
||||
[Test] |
||||
public void IntMaxValueTest() |
||||
{ |
||||
CheckLiteral("2147483647", 2147483647); // int
|
||||
CheckLiteral("2147483648", 2147483648); // uint
|
||||
} |
||||
|
||||
[Test, Ignore("this special case isn't implemented yet")] |
||||
public void LongMinValueTest() |
||||
{ |
||||
CheckLiteral("-9223372036854775808", -9223372036854775808); |
||||
} |
||||
|
||||
[Test] |
||||
public void LongMaxValueTest() |
||||
{ |
||||
CheckLiteral("9223372036854775807", 9223372036854775807); // long
|
||||
CheckLiteral("9223372036854775808", 9223372036854775808); // ulong
|
||||
} |
||||
|
||||
[Test] |
||||
public void StringTest1() |
||||
{ |
||||
CheckLiteral("\"\\n\\t\\u0005 Hello World !!!\"", "\n\t\u0005 Hello World !!!"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleDigit() |
||||
{ |
||||
CheckLiteral("5", 5); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestZero() |
||||
{ |
||||
CheckLiteral("0", 0); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestInteger() |
||||
{ |
||||
CheckLiteral("66", 66); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestNonOctalInteger() |
||||
{ |
||||
// C# does not have octal integers, so 077 should parse to 77
|
||||
Assert.IsTrue(077 == 77); |
||||
|
||||
CheckLiteral("077", 077); |
||||
CheckLiteral("056", 056); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestHexadecimalInteger() |
||||
{ |
||||
CheckLiteral("0x99F", 0x99F); |
||||
CheckLiteral("0xAB1f", 0xAB1f); |
||||
CheckLiteral("0xffffffff", 0xffffffff); |
||||
CheckLiteral("0xffffffffL", 0xffffffffL); |
||||
CheckLiteral("0xffffffffuL", 0xffffffffuL); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidHexadecimalInteger() |
||||
{ |
||||
// don't check result, just make sure there is no exception
|
||||
ParseUtilCSharp.ParseExpression<PrimitiveExpression>("0x2GF", expectErrors: true); |
||||
ParseUtilCSharp.ParseExpression<PrimitiveExpression>("0xG2F", expectErrors: true); |
||||
ParseUtilCSharp.ParseExpression<PrimitiveExpression>("0x", expectErrors: true); // SD-457
|
||||
// hexadecimal integer >ulong.MaxValue
|
||||
ParseUtilCSharp.ParseExpression<PrimitiveExpression>("0xfedcba98765432100", expectErrors: true); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestLongHexadecimalInteger() |
||||
{ |
||||
CheckLiteral("0x4244636f446c6d58", 0x4244636f446c6d58); |
||||
CheckLiteral("0xf244636f446c6d58", 0xf244636f446c6d58); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestLongInteger() |
||||
{ |
||||
CheckLiteral("9223372036854775807", 9223372036854775807); // long.MaxValue
|
||||
CheckLiteral("9223372036854775808", 9223372036854775808); // long.MaxValue+1
|
||||
CheckLiteral("18446744073709551615", 18446744073709551615); // ulong.MaxValue
|
||||
} |
||||
|
||||
[Test] |
||||
public void TestTooLongInteger() |
||||
{ |
||||
// ulong.MaxValue+1
|
||||
ParseUtilCSharp.ParseExpression<PrimitiveExpression>("18446744073709551616", expectErrors: true); |
||||
|
||||
CheckLiteral("18446744073709551616f", 18446744073709551616f); // ulong.MaxValue+1 as float
|
||||
CheckLiteral("18446744073709551616d", 18446744073709551616d); // ulong.MaxValue+1 as double
|
||||
CheckLiteral("18446744073709551616m", 18446744073709551616m); // ulong.MaxValue+1 as decimal
|
||||
} |
||||
|
||||
[Test] |
||||
public void TestDouble() |
||||
{ |
||||
CheckLiteral("1.0", 1.0); |
||||
CheckLiteral("1.1", 1.1); |
||||
CheckLiteral("1.1e-2", 1.1e-2); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFloat() |
||||
{ |
||||
CheckLiteral("1f", 1f); |
||||
CheckLiteral("1.0f", 1.0f); |
||||
CheckLiteral("1.1f", 1.1f); |
||||
CheckLiteral("1.1e-2f", 1.1e-2f); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDecimal() |
||||
{ |
||||
CheckLiteral("1m", 1m); |
||||
CheckLiteral("1.0m", 1.0m); |
||||
CheckLiteral("1.1m", 1.1m); |
||||
CheckLiteral("1.1e-2m", 1.1e-2m); |
||||
CheckLiteral("2.0e-5m", 2.0e-5m); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestString() |
||||
{ |
||||
CheckLiteral(@"@""-->""""<--""", @"-->""<--"); |
||||
CheckLiteral(@"""-->\""<--""", "-->\"<--"); |
||||
|
||||
CheckLiteral(@"""\U00000041""", "\U00000041"); |
||||
CheckLiteral(@"""\U00010041""", "\U00010041"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCharLiteral() |
||||
{ |
||||
CheckLiteral(@"'a'", 'a'); |
||||
CheckLiteral(@"'\u0041'", '\u0041'); |
||||
CheckLiteral(@"'\x41'", '\x41'); |
||||
CheckLiteral(@"'\x041'", '\x041'); |
||||
CheckLiteral(@"'\x0041'", '\x0041'); |
||||
CheckLiteral(@"'\U00000041'", '\U00000041'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class QueryExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleExpression() |
||||
{ |
||||
/* |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from c in customers where c.City == \"London\" select c" |
||||
); |
||||
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier); |
||||
Assert.AreEqual(1, qe.MiddleClauses.Count); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionWhereClause), qe.MiddleClauses[0]); |
||||
QueryExpressionWhereClause wc = (QueryExpressionWhereClause)qe.MiddleClauses[0]; |
||||
Assert.IsInstanceOf(typeof(BinaryOperatorExpression), wc.Condition); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);*/ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* TODO port unit tests |
||||
[Test] |
||||
public void ExpressionWithType1() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from Customer c in customers select c" |
||||
); |
||||
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier); |
||||
Assert.AreEqual("Customer", qe.FromClause.Sources.First().Type.ToString()); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpressionWithType2() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from int c in customers select c" |
||||
); |
||||
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier); |
||||
Assert.AreEqual("System.Int32", qe.FromClause.Sources.First().Type.Type); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void ExpressionWithType3() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from S<int[]>? c in customers select c" |
||||
); |
||||
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier); |
||||
Assert.AreEqual("System.Nullable<S<System.Int32[]>>", qe.FromClause.Sources.First().Type.ToString()); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultipleGenerators() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(@"
|
||||
from c in customers |
||||
where c.City == ""London"" |
||||
from o in c.Orders |
||||
where o.OrderDate.Year == 2005 |
||||
select new { c.Name, o.OrderID, o.Total }");
|
||||
Assert.AreEqual(3, qe.MiddleClauses.Count); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionWhereClause), qe.MiddleClauses[0]); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionFromClause), qe.MiddleClauses[1]); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionWhereClause), qe.MiddleClauses[2]); |
||||
|
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpressionWithOrderBy() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from c in customers orderby c.Name select c" |
||||
); |
||||
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionOrderClause), qe.MiddleClauses[0]); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpressionWithOrderByAndLet() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from c in customers orderby c.Name let x = c select x" |
||||
); |
||||
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionOrderClause), qe.MiddleClauses[0]); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionLetClause), qe.MiddleClauses[1]); |
||||
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class SizeOfExpressionTests |
||||
{ |
||||
[Test, Ignore("type references not implemented yet")] |
||||
public void SizeOfExpressionTest() |
||||
{ |
||||
SizeOfExpression soe = ParseUtilCSharp.ParseExpression<SizeOfExpression>("sizeof(MyType)"); |
||||
Assert.AreEqual("MyType", soe.Type); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class StackAllocExpressionTests |
||||
{ |
||||
[Test, Ignore] |
||||
public void StackAllocExpressionTest() |
||||
{ |
||||
var sae = ParseUtilCSharp.ParseExpression<StackAllocExpression>("stackalloc int[100]"); |
||||
throw new NotImplementedException(); // TODO: verify type + length expression
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class ThisReferenceExpressionTests |
||||
{ |
||||
[Test] |
||||
public void TestMethod() |
||||
{ |
||||
ParseUtilCSharp.ParseExpression<ThisReferenceExpression>("this"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class TypeOfExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleTypeOfExpressionTest() |
||||
{ |
||||
//TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyNamespace.N1.MyType)");
|
||||
//Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* TODO |
||||
[Test] |
||||
public void GlobalTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(global::System.Console)"); |
||||
Assert.AreEqual("System.Console", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void PrimitiveTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(int)"); |
||||
Assert.AreEqual("System.Int32", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VoidTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(void)"); |
||||
Assert.AreEqual("System.Void", toe.TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType[])"); |
||||
Assert.AreEqual("MyType", toe.TypeReference.Type); |
||||
Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyNamespace.N1.MyType<string>)"); |
||||
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); |
||||
Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedGenericTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType<string>.InnerClass<int>.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); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyStruct?)"); |
||||
Assert.AreEqual("System.Nullable", toe.TypeReference.Type); |
||||
Assert.AreEqual("MyStruct", toe.TypeReference.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void UnboundTypeOfExpressionTest() |
||||
{ |
||||
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType<,>)"); |
||||
Assert.AreEqual("MyType", toe.TypeReference.Type); |
||||
Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull); |
||||
Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class TypeReferenceExpressionTests |
||||
{ |
||||
[Test] |
||||
public void GlobalTypeReferenceExpression() |
||||
{ |
||||
/*TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::System"); |
||||
Assert.AreEqual("System", tr.TypeReference.Type); |
||||
Assert.IsTrue(tr.TypeReference.IsGlobal);*/ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* TODO |
||||
[Test] |
||||
public void GlobalTypeReferenceExpressionWithoutTypeName() |
||||
{ |
||||
TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::", true); |
||||
Assert.AreEqual("?", tr.TypeReference.Type); |
||||
Assert.IsTrue(tr.TypeReference.IsGlobal); |
||||
} |
||||
|
||||
[Test] |
||||
public void IntReferenceExpression() |
||||
{ |
||||
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("int.MaxValue"); |
||||
Assert.AreEqual("MaxValue", fre.MemberName); |
||||
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void StandaloneIntReferenceExpression() |
||||
{ |
||||
TypeReferenceExpression tre = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("int"); |
||||
Assert.AreEqual("System.Int32", tre.TypeReference.Type); |
||||
} |
||||
*/ |
||||
} |
||||
} |
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression |
||||
{ |
||||
[TestFixture] |
||||
public class UnaryOperatorExpressionTests |
||||
{ |
||||
void TestUnaryOperatorExpressionTest(string program, UnaryOperatorType op) |
||||
{ |
||||
UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression<UnaryOperatorExpression>(program); |
||||
Assert.AreEqual(op, uoe.Operator); |
||||
|
||||
Assert.IsTrue(uoe.Expression is IdentifierExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("!a", UnaryOperatorType.Not); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitNotTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("~a", UnaryOperatorType.BitNot); |
||||
} |
||||
|
||||
[Test] |
||||
public void MinusTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("-a", UnaryOperatorType.Minus); |
||||
} |
||||
|
||||
[Test] |
||||
public void PlusTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("+a", UnaryOperatorType.Plus); |
||||
} |
||||
|
||||
[Test] |
||||
public void IncrementTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("++a", UnaryOperatorType.Increment); |
||||
} |
||||
|
||||
[Test] |
||||
public void DecrementTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("--a", UnaryOperatorType.Decrement); |
||||
} |
||||
|
||||
[Test] |
||||
public void PostIncrementTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("a++", UnaryOperatorType.PostIncrement); |
||||
} |
||||
|
||||
[Test] |
||||
public void PostDecrementTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("a--", UnaryOperatorType.PostDecrement); |
||||
} |
||||
|
||||
[Test] |
||||
public void StarTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("*a", UnaryOperatorType.Dereference); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitWiseAndTest() |
||||
{ |
||||
TestUnaryOperatorExpressionTest("&a", UnaryOperatorType.AddressOf); |
||||
} |
||||
|
||||
[Test] |
||||
public void DereferenceAfterCast() |
||||
{ |
||||
UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression<UnaryOperatorExpression>("*((SomeType*) &w)"); |
||||
Assert.AreEqual(UnaryOperatorType.Dereference, uoe.Operator); |
||||
ParenthesizedExpression pe = (ParenthesizedExpression)uoe.Expression; |
||||
CastExpression ce = (CastExpression)pe.Expression; |
||||
//Assert.AreEqual("SomeType", ce.CastTo.Type);
|
||||
//Assert.AreEqual(1, ce.CastTo.PointerNestingLevel);
|
||||
Assert.Ignore("need to check target type"); // TODO
|
||||
|
||||
UnaryOperatorExpression adrOf = (UnaryOperatorExpression)ce.Expression; |
||||
Assert.AreEqual(UnaryOperatorType.AddressOf, adrOf.Operator); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class AttributeSectionTests |
||||
{ |
||||
[Test, Ignore] |
||||
public void GlobalAttributeCSharp() |
||||
{ |
||||
string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
|
||||
[someprefix::DesignerGenerated()] |
||||
public class Form1 { |
||||
}";
|
||||
// TODO This old NRefactory test checked that [global] attributes are incorrectly applied to the following type???
|
||||
|
||||
//TypeDeclaration decl = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
|
||||
//Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes.First().Attributes.Single().Name);
|
||||
//Assert.AreEqual("someprefix.DesignerGenerated", decl.Attributes.Last().Attributes.Single().Name);
|
||||
} |
||||
|
||||
[Test] |
||||
public void AssemblyAttributeCSharp() |
||||
{ |
||||
string program = @"[assembly: System.Attribute()]"; |
||||
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program); |
||||
Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation); |
||||
Assert.AreEqual("assembly", decl.AttributeTarget); |
||||
} |
||||
|
||||
[Test] |
||||
public void AssemblyAttributeCSharpWithNamedArguments() |
||||
{ |
||||
string program = @"[assembly: Foo(1, namedArg: 2, prop = 3)]"; |
||||
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program); |
||||
Assert.AreEqual("assembly", decl.AttributeTarget); |
||||
var a = decl.Attributes.Single(); |
||||
Assert.AreEqual("Foo", a.Type); |
||||
Assert.AreEqual(3, a.Arguments.Count()); |
||||
|
||||
// TODO: check arguments
|
||||
} |
||||
|
||||
[Test] |
||||
public void ModuleAttributeCSharp() |
||||
{ |
||||
string program = @"[module: System.Attribute()]"; |
||||
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program); |
||||
Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation); |
||||
Assert.AreEqual(AttributeTarget.Module, decl.AttributeTarget); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeAttributeCSharp() |
||||
{ |
||||
string program = @"[type: System.Attribute()] class Test {}"; |
||||
TypeDeclaration type = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); |
||||
AttributeSection decl = type.Attributes.Single(); |
||||
Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation); |
||||
Assert.AreEqual(AttributeTarget.Type, decl.AttributeTarget); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope |
||||
{ |
||||
[TestFixture, Ignore("delegates are completely broken at the moment")] |
||||
public class DelegateDeclarationTests |
||||
{ |
||||
void TestParameters(DelegateDeclaration dd) |
||||
{ |
||||
Assert.AreEqual(3, dd.Parameters.Count()); |
||||
|
||||
Assert.AreEqual("a", ((ParameterDeclaration)dd.Parameters.ElementAt(0)).Name); |
||||
//Assert.AreEqual("System.Int32", ((ParameterDeclaration)dd.Parameters.ElementAt(0)).TypeReference.Type);
|
||||
Assert.Ignore("check types"); // TODO
|
||||
Assert.AreEqual("secondParam", ((ParameterDeclaration)dd.Parameters.ElementAt(1)).Name); |
||||
//Assert.AreEqual("System.Int32", ((ParameterDeclaration)dd.Parameters.ElementAt(1)).TypeReference.Type);
|
||||
|
||||
Assert.AreEqual("lastParam", ((ParameterDeclaration)dd.Parameters.ElementAt(2)).Name); |
||||
//Assert.AreEqual("MyObj", ((ParameterDeclaration)dd.Parameters.ElementAt(2)).TypeReference.Type);
|
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleCSharpDelegateDeclarationTest() |
||||
{ |
||||
string program = "public delegate void MyDelegate(int a, int secondParam, MyObj lastParam);\n"; |
||||
DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal<DelegateDeclaration>(program); |
||||
Assert.AreEqual("MyDelegate", dd.Name); |
||||
//Assert.AreEqual("System.Void", dd.ReturnType.Type);
|
||||
TestParameters(dd); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void DelegateWithoutNameDeclarationTest() |
||||
{ |
||||
string program = "public delegate void(int a, int secondParam, MyObj lastParam);\n"; |
||||
DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal<DelegateDeclaration>(program, true); |
||||
//Assert.AreEqual("System.Void", dd.ReturnType.Type);
|
||||
//Assert.AreEqual("?", dd.Name);
|
||||
TestParameters(dd); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void GenericDelegateDeclarationTest() |
||||
{ |
||||
string program = "public delegate T CreateObject<T>() where T : ICloneable;\n"; |
||||
DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal<DelegateDeclaration>(program); |
||||
Assert.AreEqual("CreateObject", dd.Name); |
||||
//Assert.AreEqual("T", dd.ReturnType.Type);
|
||||
Assert.AreEqual(0, dd.Parameters.Count()); |
||||
/*Assert.AreEqual(1, dd.Templates.Count); |
||||
Assert.AreEqual("T", dd.Templates[0].Name); |
||||
Assert.AreEqual(1, dd.Templates[0].Bases.Count); |
||||
Assert.AreEqual("ICloneable", dd.Templates[0].Bases[0].Type);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test] |
||||
public void DelegateDeclarationInNamespace() |
||||
{ |
||||
string program = "namespace N { delegate void MyDelegate(); }"; |
||||
NamespaceDeclaration nd = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>(program); |
||||
Assert.AreEqual("MyDelegate", ((DelegateDeclaration)nd.Members.Single()).Name); |
||||
} |
||||
|
||||
[Test, Ignore("inner classes not yet implemented")] |
||||
public void DelegateDeclarationInClass() |
||||
{ |
||||
string program = "class Outer { delegate void Inner(); }"; |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); |
||||
Assert.AreEqual("Inner", ((DelegateDeclaration)td.Members.Single()).Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope |
||||
{ |
||||
[TestFixture] |
||||
public class NamespaceDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void SimpleNamespaceTest() |
||||
{ |
||||
string program = "namespace TestNamespace {\n" + |
||||
"}\n"; |
||||
NamespaceDeclaration ns = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>(program); |
||||
Assert.AreEqual("TestNamespace", ns.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedNamespaceTest() |
||||
{ |
||||
string program = "namespace N1 {//TestNamespace\n" + |
||||
" namespace N2 {// Declares a namespace named N2 within N1.\n" + |
||||
" }\n" + |
||||
"}\n"; |
||||
NamespaceDeclaration ns = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>(program); |
||||
|
||||
Assert.AreEqual("N1", ns.Name); |
||||
|
||||
Assert.AreEqual("N2", ns.Children.OfType<NamespaceDeclaration>().Single().Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,240 @@
@@ -0,0 +1,240 @@
|
||||
// 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.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope |
||||
{ |
||||
[TestFixture] |
||||
public class TypeDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void SimpleClassTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("class MyClass : My.Base.Class { }"); |
||||
|
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("MyClass", td.Name); |
||||
//Assert.AreEqual("My.Base.Class", td.BaseTypes[0].Type);
|
||||
Assert.Ignore("need to check base type"); // TODO
|
||||
Assert.AreEqual(Modifiers.None, td.Modifiers); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleClassRegionTest() |
||||
{ |
||||
const string program = "class MyClass\n{\n}\n"; |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); |
||||
Assert.AreEqual(1, td.StartLocation.Line, "StartLocation.Y"); |
||||
Assert.AreEqual(1, td.StartLocation.Column, "StartLocation.X"); |
||||
AstLocation bodyStartLocation = td.GetChildByRole(AstNode.Roles.LBrace).PrevSibling.EndLocation; |
||||
Assert.AreEqual(1, bodyStartLocation.Line, "BodyStartLocation.Y"); |
||||
Assert.AreEqual(14, bodyStartLocation.Column, "BodyStartLocation.X"); |
||||
Assert.AreEqual(3, td.EndLocation.Line, "EndLocation.Y"); |
||||
Assert.AreEqual(2, td.EndLocation.Column, "EndLocation.Y"); |
||||
} |
||||
|
||||
[Test, Ignore("partial modifier is broken")] |
||||
public void SimplePartialClassTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class MyClass { }"); |
||||
Assert.IsFalse(td.IsNull); |
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("MyClass", td.Name); |
||||
Assert.AreEqual(Modifiers.Partial, td.Modifiers); |
||||
} |
||||
|
||||
[Test, Ignore("nested classes are broken")] |
||||
public void NestedClassesTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("class MyClass { partial class P1 {} public partial class P2 {} static class P3 {} internal static class P4 {} }"); |
||||
Assert.IsFalse(td.IsNull); |
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("MyClass", td.Name); |
||||
Assert.AreEqual(Modifiers.Partial, ((TypeDeclaration)td.Members.ElementAt(0)).Modifiers); |
||||
Assert.AreEqual(Modifiers.Partial | Modifiers.Public, ((TypeDeclaration)td.Members.ElementAt(1)).Modifiers); |
||||
Assert.AreEqual(Modifiers.Static, ((TypeDeclaration)td.Members.ElementAt(2)).Modifiers); |
||||
Assert.AreEqual(Modifiers.Static | Modifiers.Internal, ((TypeDeclaration)td.Members.ElementAt(3)).Modifiers); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleStaticClassTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("static class MyClass { }"); |
||||
Assert.IsFalse(td.IsNull); |
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("MyClass", td.Name); |
||||
Assert.AreEqual(Modifiers.Static, td.Modifiers); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void GenericClassTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("public class G<T> {}"); |
||||
|
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("G", td.Name); |
||||
Assert.AreEqual(Modifiers.Public, td.Modifiers); |
||||
/*Assert.AreEqual(0, td.BaseTypes.Count); |
||||
Assert.AreEqual(1, td.TypeArguments.Count()); |
||||
Assert.AreEqual("T", td.TypeArguments.Single().Name);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
|
||||
[Test, Ignore] |
||||
public void GenericClassWithWhere() |
||||
{ |
||||
string declr = @"
|
||||
public class Test<T> where T : IMyInterface |
||||
{ |
||||
} |
||||
";
|
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(declr); |
||||
|
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
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);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void ComplexGenericClassTypeDeclarationTest() |
||||
{ |
||||
string declr = @"
|
||||
public class Generic<T, S> : System.IComparable where S : G<T[]> where T : MyNamespace.IMyInterface |
||||
{ |
||||
} |
||||
";
|
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(declr); |
||||
|
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("Generic", td.Name); |
||||
Assert.AreEqual(Modifiers.Public, td.Modifiers); |
||||
/*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("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);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void ComplexClassTypeDeclarationTest() |
||||
{ |
||||
string declr = @"
|
||||
[MyAttr()] |
||||
public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 |
||||
{ |
||||
} |
||||
";
|
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(declr); |
||||
|
||||
Assert.AreEqual(ClassType.Class, td.ClassType); |
||||
Assert.AreEqual("MyClass", td.Name); |
||||
Assert.AreEqual(Modifiers.Public | Modifiers.Abstract, td.Modifiers); |
||||
Assert.AreEqual(1, td.Attributes.Count()); |
||||
/* Assert.AreEqual(3, td.BaseTypes.Count); |
||||
Assert.AreEqual("MyBase", td.BaseTypes[0].Type); |
||||
Assert.AreEqual("Interface1", td.BaseTypes[1].Type); |
||||
Assert.AreEqual("My.Test.Interface2", td.BaseTypes[2].Type);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleStructTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("struct MyStruct {}"); |
||||
|
||||
Assert.AreEqual(ClassType.Struct, td.ClassType); |
||||
Assert.AreEqual("MyStruct", td.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleInterfaceTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("interface MyInterface {}"); |
||||
|
||||
Assert.AreEqual(ClassType.Interface, td.ClassType); |
||||
Assert.AreEqual("MyInterface", td.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleEnumTypeDeclarationTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum {}"); |
||||
|
||||
Assert.AreEqual(ClassType.Enum, td.ClassType); |
||||
Assert.AreEqual("MyEnum", td.Name); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void ContextSensitiveKeywordTest() |
||||
{ |
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class partial<[partial: where] where> where where : partial<where> { }"); |
||||
|
||||
Assert.AreEqual(Modifiers.Partial, td.Modifiers); |
||||
Assert.AreEqual("partial", td.Name); |
||||
|
||||
/* |
||||
Assert.AreEqual(1, td.Templates.Count); |
||||
TemplateDefinition tp = td.Templates[0]; |
||||
Assert.AreEqual("where", tp.Name); |
||||
|
||||
Assert.AreEqual(1, tp.Attributes.Count); |
||||
Assert.AreEqual("partial", tp.Attributes[0].AttributeTarget); |
||||
Assert.AreEqual(1, tp.Attributes[0].Attributes.Count); |
||||
Assert.AreEqual("where", tp.Attributes[0].Attributes[0].Name); |
||||
|
||||
Assert.AreEqual(1, tp.Bases.Count); |
||||
Assert.AreEqual("partial", tp.Bases[0].Type); |
||||
Assert.AreEqual("where", tp.Bases[0].GenericTypes[0].Type);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeInNamespaceTest() |
||||
{ |
||||
NamespaceDeclaration ns = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>("namespace N { class MyClass { } }"); |
||||
|
||||
Assert.AreEqual("N", ns.Name); |
||||
Assert.AreEqual("MyClass", ((TypeDeclaration)ns.Members.Single()).Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void StructInNamespaceTest() |
||||
{ |
||||
NamespaceDeclaration ns = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>("namespace N { struct MyClass { } }"); |
||||
|
||||
Assert.AreEqual("N", ns.Name); |
||||
Assert.AreEqual("MyClass", ((TypeDeclaration)ns.Members.Single()).Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumInNamespaceTest() |
||||
{ |
||||
NamespaceDeclaration ns = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>("namespace N { enum MyClass { } }"); |
||||
|
||||
Assert.AreEqual("N", ns.Name); |
||||
Assert.AreEqual("MyClass", ((TypeDeclaration)ns.Members.Single()).Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void InterfaceInNamespaceTest() |
||||
{ |
||||
NamespaceDeclaration ns = ParseUtilCSharp.ParseGlobal<NamespaceDeclaration>("namespace N { interface MyClass { } }"); |
||||
|
||||
Assert.AreEqual("N", ns.Name); |
||||
Assert.AreEqual("MyClass", ((TypeDeclaration)ns.Members.Single()).Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
// 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.IO; |
||||
using System.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope |
||||
{ |
||||
[TestFixture] |
||||
public class UsingDeclarationTests |
||||
{ |
||||
[Test] |
||||
[Ignore("error reporting not yet implemented")] |
||||
public void WrongUsingTest() |
||||
{ |
||||
string program = "using\n"; |
||||
CSharpParser parser = new CSharpParser(); |
||||
CompilationUnit cu = parser.Parse(new StringReader(program)); |
||||
Assert.AreEqual(0, cu.Children.Count()); |
||||
Assert.IsTrue(parser.HasErrors); |
||||
} |
||||
|
||||
[Test] |
||||
public void DeclarationTest() |
||||
{ |
||||
string program = "using System;\n" + |
||||
"using My.Name.Space;\n"; |
||||
CSharpParser parser = new CSharpParser(); |
||||
CompilationUnit cu = parser.Parse(new StringReader(program)); |
||||
Assert.IsFalse(parser.HasErrors); |
||||
|
||||
Assert.AreEqual(2, cu.Children.Count()); |
||||
Assert.IsTrue(cu.Children.ElementAt(0) is UsingDeclaration); |
||||
Assert.IsFalse(cu.Children.ElementAt(0) is UsingAliasDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)cu.Children.ElementAt(0); |
||||
Assert.AreEqual("System", ud.Namespace); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(1) is UsingDeclaration); |
||||
Assert.IsFalse(cu.Children.ElementAt(1) is UsingAliasDeclaration); |
||||
ud = (UsingDeclaration)cu.Children.ElementAt(1); |
||||
Assert.AreEqual("My.Name.Space", ud.Namespace); |
||||
} |
||||
|
||||
[Test] |
||||
public void UsingAliasDeclarationTest() |
||||
{ |
||||
string program = "using TESTME=System;\n" + |
||||
"using myAlias=My.Name.Space;\n" + |
||||
"using StringCollection = System.Collections.Generic.List<string>;\n"; |
||||
CSharpParser parser = new CSharpParser(); |
||||
CompilationUnit cu = parser.Parse(new StringReader(program)); |
||||
Assert.IsFalse(parser.HasErrors); |
||||
|
||||
Assert.AreEqual(3, cu.Children.Count()); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(0) is UsingAliasDeclaration); |
||||
UsingAliasDeclaration ud = (UsingAliasDeclaration)cu.Children.ElementAt(0); |
||||
Assert.AreEqual("TESTME", ud.Alias); |
||||
Assert.AreEqual("System", ud.Import.ToString()); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(1) is UsingAliasDeclaration); |
||||
ud = (UsingAliasDeclaration)cu.Children.ElementAt(1); |
||||
Assert.AreEqual("myAlias", ud.Alias); |
||||
Assert.AreEqual("My.Name.Space", ud.Import.ToString()); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(2) is UsingAliasDeclaration); |
||||
ud = (UsingAliasDeclaration)cu.Children.ElementAt(2); |
||||
Assert.AreEqual("StringCollection", ud.Alias); |
||||
Assert.AreEqual("System.Collections.Generic.List<string>", ud.Import.ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void UsingWithAliasing() |
||||
{ |
||||
string program = "using global::System;\n" + |
||||
"using myAlias=global::My.Name.Space;\n" + |
||||
"using a::b.c;\n"; |
||||
CSharpParser parser = new CSharpParser(); |
||||
CompilationUnit cu = parser.Parse(new StringReader(program)); |
||||
Assert.IsFalse(parser.HasErrors); |
||||
|
||||
Assert.AreEqual(3, cu.Children.Count()); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(0) is UsingDeclaration); |
||||
Assert.IsFalse(cu.Children.ElementAt(0) is UsingAliasDeclaration); |
||||
UsingDeclaration ud = (UsingDeclaration)cu.Children.ElementAt(0); |
||||
Assert.AreEqual("global::System", ud.Namespace); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(1) is UsingAliasDeclaration); |
||||
UsingAliasDeclaration uad = (UsingAliasDeclaration)cu.Children.ElementAt(1); |
||||
Assert.AreEqual("myAlias", uad.Alias); |
||||
Assert.AreEqual("global::My.Name.Space", uad.Import.ToString()); |
||||
|
||||
Assert.IsTrue(cu.Children.ElementAt(2) is UsingDeclaration); |
||||
Assert.IsFalse(cu.Children.ElementAt(2) is UsingAliasDeclaration); |
||||
ud = (UsingDeclaration)cu.Children.ElementAt(2); |
||||
Assert.AreEqual("a::b.c", ud.Namespace); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2010 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.IO; |
||||
using System.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Helper methods for parser unit tests.
|
||||
/// </summary>
|
||||
public class ParseUtilCSharp |
||||
{ |
||||
public static T ParseGlobal<T>(string code, bool expectErrors = false) where T : AstNode |
||||
{ |
||||
CSharpParser parser = new CSharpParser(); |
||||
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 T ParseStatement<T>(string stmt, bool expectErrors = false) where T : AstNode |
||||
{ |
||||
CSharpParser parser = new CSharpParser(); |
||||
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 T ParseExpression<T>(string expr, bool expectErrors = false) where T : AstNode |
||||
{ |
||||
if (expectErrors) Assert.Ignore("errors not yet implemented"); |
||||
|
||||
CSharpParser parser = new CSharpParser(); |
||||
AstNode parsedExpression = parser.ParseExpression(new StringReader(expr)); |
||||
|
||||
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); |
||||
|
||||
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 T ParseTypeMember<T>(string expr, bool expectErrors = false) where T : AttributedNode |
||||
{ |
||||
if (expectErrors) Assert.Ignore("errors not yet implemented"); |
||||
|
||||
CSharpParser parser = new CSharpParser(); |
||||
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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class BlockStatementTests |
||||
{ |
||||
[Test] |
||||
public void BlockStatementTest() |
||||
{ |
||||
BlockStatement blockStmt = ParseUtilCSharp.ParseStatement<BlockStatement>("{}"); |
||||
Assert.AreEqual(0, blockStmt.Statements.Count()); |
||||
} |
||||
|
||||
[Test, Ignore("position isn't correct when only parsing a block")] |
||||
public void ComplexBlockStatementPositionTest() |
||||
{ |
||||
string code = @"{
|
||||
WebClient wc = new WebClient(); |
||||
wc.Test(); |
||||
wc.UploadStringCompleted += delegate { |
||||
output.BeginInvoke((MethodInvoker)delegate { |
||||
output.Text += newText; |
||||
}); |
||||
}; |
||||
}";
|
||||
BlockStatement blockStmt = ParseUtilCSharp.ParseStatement<BlockStatement>(code); |
||||
Assert.AreEqual(1, blockStmt.StartLocation.Column); |
||||
Assert.AreEqual(1, blockStmt.StartLocation.Line); |
||||
Assert.AreEqual(2, blockStmt.EndLocation.Column); |
||||
Assert.AreEqual(9, blockStmt.EndLocation.Line); |
||||
|
||||
Assert.AreEqual(3, blockStmt.Statements.Count()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class CheckedStatementTests |
||||
{ |
||||
[Test] |
||||
public void CheckedStatementTest() |
||||
{ |
||||
CheckedStatement checkedStatement = ParseUtilCSharp.ParseStatement<CheckedStatement>("checked { }"); |
||||
Assert.IsFalse(checkedStatement.Body.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void CheckedStatementAndExpressionTest() |
||||
{ |
||||
CheckedStatement checkedStatement = ParseUtilCSharp.ParseStatement<CheckedStatement>("checked { checked(++i).ToString(); }"); |
||||
ExpressionStatement es = (ExpressionStatement)checkedStatement.Body.Statements.Single(); |
||||
CheckedExpression ce = (CheckedExpression)((MemberReferenceExpression)((InvocationExpression)es.Expression).Target).Target; |
||||
Assert.IsTrue(ce.Expression is UnaryOperatorExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void UncheckedStatementTest() |
||||
{ |
||||
UncheckedStatement uncheckedStatement = ParseUtilCSharp.ParseStatement<UncheckedStatement>("unchecked { }"); |
||||
Assert.IsFalse(uncheckedStatement.Body.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void UncheckedStatementAndExpressionTest() |
||||
{ |
||||
UncheckedStatement uncheckedStatement = ParseUtilCSharp.ParseStatement<UncheckedStatement>("unchecked { unchecked(++i).ToString(); }"); |
||||
ExpressionStatement es = (ExpressionStatement)uncheckedStatement.Body.Statements.Single(); |
||||
UncheckedExpression ce = (UncheckedExpression)((MemberReferenceExpression)((InvocationExpression)es.Expression).Target).Target; |
||||
Assert.IsTrue(ce.Expression is UnaryOperatorExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class EmptyStatementTests |
||||
{ |
||||
[Test] |
||||
public void EmptyStatementTest() |
||||
{ |
||||
EmptyStatement emptyStmt = ParseUtilCSharp.ParseStatement<EmptyStatement>(";"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class ExpressionStatementTests |
||||
{ |
||||
[Test] |
||||
public void StatementExpressionTest() |
||||
{ |
||||
ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement<ExpressionStatement>("a = my.Obj.PropCall;"); |
||||
Assert.IsTrue(stmtExprStmt.Expression is AssignmentExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void StatementExpressionTest1() |
||||
{ |
||||
ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement<ExpressionStatement>("yield.yield();"); |
||||
Assert.IsTrue(stmtExprStmt.Expression is InvocationExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class FixedStatementTests |
||||
{ |
||||
[Test] |
||||
public void FixedStatementTest() |
||||
{ |
||||
FixedStatement fixedStmt = ParseUtilCSharp.ParseStatement<FixedStatement>("fixed (int* ptr = &myIntArr) { }"); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class ForStatementTests |
||||
{ |
||||
[Test] |
||||
public void ForeachStatementTest() |
||||
{ |
||||
ForeachStatement foreachStmt = ParseUtilCSharp.ParseStatement<ForeachStatement>("foreach (int i in myColl) {} "); |
||||
// TODO : Extend test.
|
||||
} |
||||
|
||||
[Test, Ignore("for statement is broken when Initializers.Count()!=1")] |
||||
public void EmptyForStatementTest() |
||||
{ |
||||
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (;;) ;"); |
||||
Assert.AreEqual(0, forStmt.Initializers.Count()); |
||||
Assert.AreEqual(0, forStmt.Iterators.Count()); |
||||
Assert.IsTrue(forStmt.Condition.IsNull); |
||||
Assert.IsTrue(forStmt.EmbeddedStatement is EmptyStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForStatementTest() |
||||
{ |
||||
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (int i = 5; i < 6; ++i) {} "); |
||||
var init = (VariableDeclarationStatement)forStmt.Initializers.Single(); |
||||
Assert.AreEqual("i", init.Variables.Single().Name); |
||||
|
||||
Assert.IsTrue(forStmt.Condition is BinaryOperatorExpression); |
||||
|
||||
var inc = (ExpressionStatement)forStmt.Iterators.Single(); |
||||
Assert.IsTrue(inc.Expression is UnaryOperatorExpression); |
||||
} |
||||
|
||||
[Test, Ignore("for statement is broken when Initializers.Count()!=1")] |
||||
public void ForStatementTestMultipleInitializers() |
||||
{ |
||||
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (i = 0, j = 1; i < 6; ++i) {} "); |
||||
Assert.AreEqual(2, forStmt.Initializers.Count()); |
||||
Assert.IsTrue(forStmt.Iterators.All(i => i is ExpressionStatement)); |
||||
} |
||||
|
||||
[Test, Ignore("for statement is broken when Iterators.Count()!=1")] |
||||
public void ForStatementTestMultipleIterators() |
||||
{ |
||||
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (int i = 5; i < 6; ++i, j--) {} "); |
||||
Assert.AreEqual(2, forStmt.Iterators.Count()); |
||||
Assert.IsTrue(forStmt.Iterators.All(i => i is ExpressionStatement)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class GotoStatementTests |
||||
{ |
||||
[Test, Ignore("regular goto statement is broken")] |
||||
public void GotoStatementTest() |
||||
{ |
||||
GotoStatement gotoStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto myLabel;"); |
||||
Assert.AreEqual(GotoType.Label, gotoStmt.GotoType); |
||||
Assert.AreEqual("myLabel", gotoStmt.Label); |
||||
} |
||||
|
||||
[Test] |
||||
public void GotoDefaultStatementTest() |
||||
{ |
||||
GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto default;"); |
||||
Assert.AreEqual(GotoType.CaseDefault, gotoCaseStmt.GotoType); |
||||
} |
||||
|
||||
[Test] |
||||
public void GotoCaseStatementTest() |
||||
{ |
||||
GotoStatement gotoCaseStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto case 6;"); |
||||
Assert.AreEqual(GotoType.Case, gotoCaseStmt.GotoType); |
||||
Assert.IsTrue(gotoCaseStmt.LabelExpression is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void BreakStatementTest() |
||||
{ |
||||
BreakStatement breakStmt = ParseUtilCSharp.ParseStatement<BreakStatement>("break;"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContinueStatementTest() |
||||
{ |
||||
ContinueStatement continueStmt = ParseUtilCSharp.ParseStatement<ContinueStatement>("continue;"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class IfElseStatementTests |
||||
{ |
||||
[Test] |
||||
public void SimpleIfStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtilCSharp.ParseStatement<IfElseStatement>("if (true) { }"); |
||||
Assert.IsTrue(ifElseStatement.Condition is PrimitiveExpression); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement is BlockStatement); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleIfElseStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtilCSharp.ParseStatement<IfElseStatement>("if (true) { } else { }"); |
||||
Assert.IsTrue(ifElseStatement.Condition is PrimitiveExpression); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement is BlockStatement); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement is BlockStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfElseIfStatementTest() |
||||
{ |
||||
IfElseStatement ifElseStatement = ParseUtilCSharp.ParseStatement<IfElseStatement>("if (1) { } else if (2) { } else if (3) { } else { }"); |
||||
Assert.IsTrue(ifElseStatement.Condition is PrimitiveExpression); |
||||
Assert.IsTrue(ifElseStatement.TrueStatement is BlockStatement); |
||||
Assert.IsTrue(ifElseStatement.FalseStatement is IfElseStatement); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class LabelStatementTests |
||||
{ |
||||
[Test] |
||||
public void LabelStatementTest() |
||||
{ |
||||
BlockStatement block = ParseUtilCSharp.ParseStatement<BlockStatement>("{ myLabel: ; }"); |
||||
LabelStatement labelStmt = (LabelStatement)block.Statements.First(); |
||||
Assert.AreEqual("myLabel", labelStmt.Label); |
||||
} |
||||
|
||||
[Test] |
||||
public void Label2StatementTest() |
||||
{ |
||||
BlockStatement block = ParseUtilCSharp.ParseStatement<BlockStatement>("{ yield: ; }"); |
||||
LabelStatement labelStmt = (LabelStatement)block.Statements.First(); |
||||
Assert.AreEqual("yield", labelStmt.Label); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class LockStatementTests |
||||
{ |
||||
[Test] |
||||
public void LockStatementTest() |
||||
{ |
||||
LockStatement lockStmt = ParseUtilCSharp.ParseStatement<LockStatement>("lock (myObj) {}"); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class ReturnStatementTests |
||||
{ |
||||
[Test] |
||||
public void EmptyReturnStatementTest() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement<ReturnStatement>("return;"); |
||||
Assert.IsTrue(returnStatement.Expression.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReturnStatementTest() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement<ReturnStatement>("return 5;"); |
||||
Assert.IsTrue(returnStatement.Expression is PrimitiveExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReturnStatementTest1() |
||||
{ |
||||
ReturnStatement returnStatement = ParseUtilCSharp.ParseStatement<ReturnStatement>("return yield;"); |
||||
Assert.IsTrue(returnStatement.Expression is IdentifierExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class SwitchStatementTests |
||||
{ |
||||
[Test] |
||||
public void SwitchStatementTest() |
||||
{ |
||||
SwitchStatement switchStmt = ParseUtilCSharp.ParseStatement<SwitchStatement>("switch (a) { case 4: case 5: break; case 6: break; default: break; }"); |
||||
Assert.AreEqual("a", ((IdentifierExpression)switchStmt.Expression).Identifier); |
||||
// TODO: Extend test
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class ThrowStatementTests |
||||
{ |
||||
[Test] |
||||
public void EmptyThrowStatementTest() |
||||
{ |
||||
ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement<ThrowStatement>("throw;"); |
||||
Assert.IsTrue(throwStmt.Expression.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThrowStatementTest() |
||||
{ |
||||
ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement<ThrowStatement>("throw new Exception();"); |
||||
Assert.IsTrue(throwStmt.Expression is ObjectCreateExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class TryCatchStatementTests |
||||
{ |
||||
[Test] |
||||
public void SimpleTryCatchStatementTest() |
||||
{ |
||||
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch { } "); |
||||
Assert.IsTrue(tryCatchStatement.FinallyBlock.IsNull); |
||||
Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count()); |
||||
Assert.IsTrue(tryCatchStatement.CatchClauses.Single().Type.IsNull); |
||||
Assert.AreEqual(string.Empty, tryCatchStatement.CatchClauses.Single().VariableName); |
||||
} |
||||
|
||||
/* TODO port tests |
||||
[Test] |
||||
public void SimpleTryCatchStatementTest2() |
||||
{ |
||||
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception e) { } "); |
||||
Assert.IsTrue(tryCatchStatement.FinallyBlock.IsNull); |
||||
Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count); |
||||
Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type); |
||||
Assert.AreEqual("e", tryCatchStatement.CatchClauses[0].VariableName); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleTryCatchFinallyStatementTest() |
||||
{ |
||||
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception) { } catch { } finally { } "); |
||||
Assert.IsFalse(tryCatchStatement.FinallyBlock.IsNull); |
||||
Assert.AreEqual(2, tryCatchStatement.CatchClauses.Count); |
||||
Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type); |
||||
Assert.IsEmpty(tryCatchStatement.CatchClauses[0].VariableName); |
||||
Assert.IsTrue(tryCatchStatement.CatchClauses[1].TypeReference.IsNull); |
||||
Assert.IsEmpty(tryCatchStatement.CatchClauses[1].VariableName); |
||||
} |
||||
*/ |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class UnsafeStatementTests |
||||
{ |
||||
[Test] |
||||
public void UnsafeStatementTest() |
||||
{ |
||||
UnsafeStatement unsafeStatement = ParseUtilCSharp.ParseStatement<UnsafeStatement>("unsafe { }"); |
||||
Assert.IsFalse(unsafeStatement.Body.IsNull); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class UsingStatementTests |
||||
{ |
||||
[Test] |
||||
public void UsingStatementTest() |
||||
{ |
||||
UsingStatement usingStmt = ParseUtilCSharp.ParseStatement<UsingStatement>("using (MyVar var = new MyVar()) { } "); |
||||
// TODO : Extend test.
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,226 @@
@@ -0,0 +1,226 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class VariableDeclarationStatementTests |
||||
{ |
||||
[Test] |
||||
public void VariableDeclarationStatementTest() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int a = 5;"); |
||||
Assert.AreEqual(1, lvd.Variables.Count()); |
||||
/*Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Int32", type.Type); |
||||
Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables[0].Initializer).Value);*/ throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* TODO port unit tests |
||||
[Test] |
||||
public void VoidPointerVariableDeclarationTest() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("void *a;"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Void", type.Type); |
||||
Assert.AreEqual(1, type.PointerNestingLevel); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComplexGenericVariableDeclarationStatementTest() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("Generic<Namespace.Printable, G<Printable[]> > where = new Generic<Namespace.Printable, G<Printable[]>>();"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("where", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("Generic", type.Type); |
||||
Assert.AreEqual(2, type.GenericTypes.Count); |
||||
Assert.AreEqual("Namespace.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); |
||||
|
||||
// TODO: Check initializer
|
||||
} |
||||
|
||||
[Test] |
||||
public void NestedGenericVariableDeclarationStatementTest() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("MyType<string>.InnerClass<int>.InnerInnerClass a;"); |
||||
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 GenericWithArrayVariableDeclarationStatementTest1() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int>[] a;"); |
||||
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 GenericWithArrayVariableDeclarationStatementTest2() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int[]> a;"); |
||||
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(new int[] {0}, type.GenericTypes[0].RankSpecifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericVariableDeclarationStatementTest2() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<G<int> > a;"); |
||||
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 GenericVariableDeclarationStatementTest2WithoutSpace() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<G<int>> a;"); |
||||
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 GenericVariableDeclarationStatementTest() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int> a;"); |
||||
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 SimpleVariableDeclarationStatementTest() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("MyVar var = new MyVar();"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("var", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("MyVar", type.Type); |
||||
// TODO: Check initializer
|
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleVariableDeclarationStatementTest1() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("yield yield = new yield();"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("yield", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("yield", type.Type); |
||||
// TODO: Check initializer
|
||||
} |
||||
|
||||
[Test] |
||||
public void NullableVariableDeclarationStatementTest1() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int? a;"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Nullable", type.Type); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableVariableDeclarationStatementTest2() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime? a;"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Nullable", type.Type); |
||||
Assert.AreEqual("DateTime", type.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableVariableDeclarationStatementTest3() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime?[] a;"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.IsTrue(type.IsArrayType); |
||||
Assert.AreEqual("System.Nullable", type.Type); |
||||
Assert.AreEqual("DateTime", type.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableVariableDeclarationStatementTest4() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("SomeStruct<int?>? a;"); |
||||
Assert.AreEqual(1, lvd.Variables.Count); |
||||
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); |
||||
TypeReference type = lvd.GetTypeForVariable(0); |
||||
Assert.AreEqual("System.Nullable", type.Type); |
||||
Assert.AreEqual("SomeStruct", type.GenericTypes[0].Type); |
||||
Assert.AreEqual("System.Nullable", type.GenericTypes[0].GenericTypes[0].Type); |
||||
Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void PositionTestWithoutModifier() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("\ndouble w = 7;"); |
||||
Assert.AreEqual(2, lvd.StartLocation.Line); |
||||
Assert.AreEqual(1, lvd.StartLocation.Column); |
||||
Assert.AreEqual(2, lvd.EndLocation.Line); |
||||
Assert.AreEqual(14, lvd.EndLocation.Column); |
||||
} |
||||
|
||||
[Test] |
||||
public void PositionTestWithModifier() |
||||
{ |
||||
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("\nconst double w = 7;"); |
||||
Assert.AreEqual(Modifiers.Const, lvd.Modifier); |
||||
Assert.AreEqual(2, lvd.StartLocation.Line); |
||||
Assert.AreEqual(1, lvd.StartLocation.Column); |
||||
Assert.AreEqual(2, lvd.EndLocation.Line); |
||||
Assert.AreEqual(20, lvd.EndLocation.Column); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class WhileStatementTests |
||||
{ |
||||
[Test] |
||||
public void WhileStatementTest() |
||||
{ |
||||
WhileStatement loopStmt = ParseUtilCSharp.ParseStatement<WhileStatement>("while (true) { }"); |
||||
Assert.AreEqual(WhilePosition.Begin, loopStmt.WhilePosition); |
||||
Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); |
||||
Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void DoWhileStatementTest() |
||||
{ |
||||
WhileStatement loopStmt = ParseUtilCSharp.ParseStatement<WhileStatement>("do { } while (true);"); |
||||
Assert.AreEqual(WhilePosition.End, loopStmt.WhilePosition); |
||||
Assert.IsTrue(loopStmt.Condition is PrimitiveExpression); |
||||
Assert.IsTrue(loopStmt.EmbeddedStatement is BlockStatement); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements |
||||
{ |
||||
[TestFixture] |
||||
public class YieldStatementTests |
||||
{ |
||||
[Test] |
||||
public void YieldReturnStatementTest() |
||||
{ |
||||
YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement<YieldStatement>("yield return \"Foo\";"); |
||||
PrimitiveExpression expr = (PrimitiveExpression)yieldStmt.Expression; |
||||
Assert.AreEqual("Foo", expr.Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void YieldBreakStatementTest() |
||||
{ |
||||
YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement<YieldStatement>("yield break;"); |
||||
Assert.IsTrue(yieldStmt.Expression.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void YieldAsVariableTest() |
||||
{ |
||||
ExpressionStatement se = ParseUtilCSharp.ParseStatement<ExpressionStatement>("yield = 3;"); |
||||
AssignmentExpression ae = se.Expression as AssignmentExpression; |
||||
|
||||
Assert.AreEqual(AssignmentOperatorType.Assign, ae.Operator); |
||||
|
||||
Assert.IsTrue(ae.Left is IdentifierExpression); |
||||
Assert.AreEqual("yield", ((IdentifierExpression)ae.Left).Identifier); |
||||
Assert.IsTrue(ae.Right is PrimitiveExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture] |
||||
public class ConstructorDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void ConstructorDeclarationTest1() |
||||
{ |
||||
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() {}"); |
||||
Assert.IsTrue(cd.Initializer.IsNull); |
||||
} |
||||
|
||||
[Test, Ignore("Constructor initializer is broken")] |
||||
public void ConstructorDeclarationTest2() |
||||
{ |
||||
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : this(5) {}"); |
||||
Assert.AreEqual(ConstructorInitializerType.This, cd.Initializer.ConstructorInitializerType); |
||||
Assert.AreEqual(1, cd.Initializer.Arguments.Count()); |
||||
} |
||||
|
||||
[Test, Ignore("Constructor initializer is broken")] |
||||
public void ConstructorDeclarationTest3() |
||||
{ |
||||
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : base(1, 2, 3) {}"); |
||||
Assert.AreEqual(ConstructorInitializerType.Base, cd.Initializer.ConstructorInitializerType); |
||||
Assert.AreEqual(3, cd.Initializer.Arguments.Count()); |
||||
} |
||||
|
||||
[Test] |
||||
public void StaticConstructorDeclarationTest1() |
||||
{ |
||||
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("static MyClass() {}"); |
||||
Assert.IsTrue(cd.Initializer.IsNull); |
||||
Assert.AreEqual(Modifiers.Static, cd.Modifiers); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExternStaticConstructorDeclarationTest() |
||||
{ |
||||
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("extern static MyClass();"); |
||||
Assert.IsTrue(cd.Initializer.IsNull); |
||||
Assert.AreEqual(Modifiers.Static | Modifiers.Extern, cd.Modifiers); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture] |
||||
public class DestructorDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void DestructorDeclarationTest() |
||||
{ |
||||
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("~MyClass() {}"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExternDestructorDeclarationTest() |
||||
{ |
||||
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("extern ~MyClass();"); |
||||
Assert.AreEqual(Modifiers.Extern, dd.Modifiers); |
||||
} |
||||
|
||||
[Test] |
||||
public void UnsafeDestructorDeclarationTest() |
||||
{ |
||||
DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember<DestructorDeclaration>("unsafe ~MyClass() {}"); |
||||
Assert.AreEqual(Modifiers.Unsafe, dd.Modifiers); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class EventDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void SimpleEventDeclarationTest() |
||||
{ |
||||
CustomEventDeclaration ed = ParseUtilCSharp.ParseTypeMember<CustomEventDeclaration>("event System.EventHandler MyEvent;"); |
||||
Assert.AreEqual("MyEvent", ed.Name); |
||||
//Assert.AreEqual("System.EventHandler", ed.TypeReference.Type);
|
||||
Assert.Ignore(); // check type
|
||||
|
||||
Assert.IsTrue(ed.AddAccessor.IsNull); |
||||
Assert.IsTrue(ed.RemoveAccessor.IsNull); |
||||
} |
||||
|
||||
/* TODO Port tests |
||||
[Test] |
||||
public void MultipleEventDeclarationTest() |
||||
{ |
||||
TypeDeclaration t = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("class C { public event EventHandler A, B; }"); |
||||
Assert.AreEqual(2, t.Children.Count); |
||||
|
||||
EventDeclaration ed = (EventDeclaration)t.Children[0]; |
||||
Assert.AreEqual(Modifiers.Public, ed.Modifier); |
||||
Assert.AreEqual("EventHandler", ed.TypeReference.Type); |
||||
Assert.AreEqual("A", ed.Name); |
||||
|
||||
ed = (EventDeclaration)t.Children[1]; |
||||
Assert.AreEqual(Modifiers.Public, ed.Modifier); |
||||
Assert.AreEqual("EventHandler", ed.TypeReference.Type); |
||||
Assert.AreEqual("B", ed.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void EventImplementingInterfaceDeclarationTest() |
||||
{ |
||||
EventDeclaration ed = ParseUtilCSharp.ParseTypeMember<EventDeclaration>("event EventHandler MyInterface.MyEvent;"); |
||||
|
||||
Assert.AreEqual("MyEvent", ed.Name); |
||||
Assert.AreEqual("EventHandler", ed.TypeReference.Type); |
||||
|
||||
Assert.IsFalse(ed.HasAddRegion); |
||||
Assert.IsFalse(ed.HasRemoveRegion); |
||||
|
||||
Assert.AreEqual("MyInterface", ed.InterfaceImplementations[0].InterfaceType.Type); |
||||
Assert.AreEqual("MyEvent", ed.InterfaceImplementations[0].MemberName); |
||||
} |
||||
|
||||
[Test] |
||||
public void EventImplementingGenericInterfaceDeclarationTest() |
||||
{ |
||||
EventDeclaration ed = ParseUtilCSharp.ParseTypeMember<EventDeclaration>("event EventHandler MyInterface<string>.MyEvent;"); |
||||
|
||||
Assert.AreEqual("MyEvent", ed.Name); |
||||
Assert.AreEqual("EventHandler", ed.TypeReference.Type); |
||||
|
||||
Assert.IsFalse(ed.HasAddRegion); |
||||
Assert.IsFalse(ed.HasRemoveRegion); |
||||
|
||||
Assert.AreEqual("MyInterface", ed.InterfaceImplementations[0].InterfaceType.Type); |
||||
Assert.AreEqual("System.String", ed.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type); |
||||
Assert.AreEqual("MyEvent", ed.InterfaceImplementations[0].MemberName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddRemoveEventDeclarationTest() |
||||
{ |
||||
EventDeclaration ed = ParseUtilCSharp.ParseTypeMember<EventDeclaration>("event System.EventHandler MyEvent { add { } remove { } }"); |
||||
Assert.AreEqual("MyEvent", ed.Name); |
||||
Assert.AreEqual("System.EventHandler", ed.TypeReference.Type); |
||||
|
||||
Assert.IsTrue(ed.HasAddRegion); |
||||
Assert.IsTrue(ed.HasRemoveRegion); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture, Ignore] |
||||
public class FieldDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void SimpleFieldDeclarationTest() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
/* |
||||
FieldDeclaration fd = ParseUtilCSharp.ParseTypeMember<FieldDeclaration>("int[,,,] myField;"); |
||||
Assert.AreEqual("System.Int32", fd.TypeReference.Type); |
||||
Assert.AreEqual(new int[] { 3 } , fd.TypeReference.RankSpecifier); |
||||
Assert.AreEqual(1, fd.Fields.Count); |
||||
|
||||
Assert.AreEqual("myField", ((VariableDeclaration)fd.Fields[0]).Name);*/ |
||||
} |
||||
|
||||
// TODO add more tests
|
||||
} |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture] |
||||
public class IndexerDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void IndexerDeclarationTest() |
||||
{ |
||||
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int this[int a, string b] { get { } set { } }"); |
||||
Assert.AreEqual(2, id.Parameters.Count()); |
||||
Assert.IsNotNull(id.Getter, "No get region found!"); |
||||
Assert.IsNotNull(id.Setter, "No set region found!"); |
||||
} |
||||
|
||||
[Test, Ignore("type reference is not yet implemented")] |
||||
public void IndexerImplementingInterfaceTest() |
||||
{ |
||||
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface.this[int a, string b] { get { } set { } }"); |
||||
Assert.AreEqual(2, id.Parameters.Count()); |
||||
Assert.IsNotNull(id.Getter, "No get region found!"); |
||||
Assert.IsNotNull(id.Setter, "No set region found!"); |
||||
|
||||
Assert.AreEqual("MyInterface", id.PrivateImplementationType); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void IndexerImplementingGenericInterfaceTest() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
/* |
||||
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface<string>.this[int a, string b] { get { } set { } }"); |
||||
Assert.AreEqual(2, id.Parameters.Count); |
||||
Assert.IsNotNull(id.GetAccessor, "No get region found!"); |
||||
Assert.IsNotNull(id.SetAccessor, "No set region found!"); |
||||
|
||||
Assert.AreEqual("MyInterface", id.InterfaceImplementations[0].InterfaceType.Type); |
||||
Assert.AreEqual("System.String", id.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);*/ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,303 @@
@@ -0,0 +1,303 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture] |
||||
public class MethodDeclarationTests |
||||
{ |
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void SimpleMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod() {} "); |
||||
Assert.AreEqual("System.Void", md.ReturnType); |
||||
Assert.AreEqual(0, md.Parameters.Count()); |
||||
Assert.IsFalse(md.IsExtensionMethod); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void AbstractMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("abstract void MyMethod();"); |
||||
Assert.AreEqual("System.Void", md.ReturnType); |
||||
Assert.AreEqual(0, md.Parameters.Count()); |
||||
Assert.IsFalse(md.IsExtensionMethod); |
||||
Assert.IsTrue(md.Body.IsNull); |
||||
Assert.AreEqual(Modifiers.Abstract, md.Modifiers); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void DefiningPartialMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("partial void MyMethod();"); |
||||
Assert.AreEqual("System.Void", md.ReturnType); |
||||
Assert.AreEqual(0, md.Parameters.Count()); |
||||
Assert.IsFalse(md.IsExtensionMethod); |
||||
Assert.IsTrue(md.Body.IsNull); |
||||
Assert.AreEqual(Modifiers.Partial, md.Modifiers); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void ImplementingPartialMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("partial void MyMethod() { }"); |
||||
Assert.AreEqual("System.Void", md.ReturnType); |
||||
Assert.AreEqual(0, md.Parameters.Count()); |
||||
Assert.IsFalse(md.IsExtensionMethod); |
||||
Assert.IsFalse(md.Body.IsNull); |
||||
Assert.AreEqual(Modifiers.Partial, md.Modifiers); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleMethodRegionTest() |
||||
{ |
||||
const string program = @"
|
||||
void MyMethod() |
||||
{ |
||||
OtherMethod(); |
||||
} |
||||
";
|
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y"); |
||||
Assert.AreEqual(5, md.EndLocation.Line, "EndLocation.Y"); |
||||
Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X"); |
||||
Assert.AreEqual(4, md.EndLocation.Column, "EndLocation.X"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodWithModifiersRegionTest() |
||||
{ |
||||
const string program = @"
|
||||
public static void MyMethod() |
||||
{ |
||||
OtherMethod(); |
||||
} |
||||
";
|
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program); |
||||
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y"); |
||||
Assert.AreEqual(5, md.EndLocation.Line, "EndLocation.Y"); |
||||
Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodWithUnnamedParameterDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod(int) {} ", true); |
||||
Assert.AreEqual("System.Void", md.ReturnType); |
||||
Assert.AreEqual(1, md.Parameters.Count()); |
||||
//Assert.AreEqual("?", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
|
||||
} |
||||
|
||||
/* TODO: port unit tests |
||||
[Test] |
||||
public void GenericVoidMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod<T>(T a) {} "); |
||||
Assert.AreEqual("System.Void", md.ReturnType); |
||||
Assert.AreEqual(1, md.Parameters.Count()); |
||||
Assert.AreEqual("T", md.Parameters.Single().Type); |
||||
Assert.AreEqual("a", md.Parameters.Single().Name); |
||||
|
||||
Assert.AreEqual(1, md.TypeParameters.Count()); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodDeclarationTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("T MyMethod<T>(T a) {} "); |
||||
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 GenericMethodDeclarationWithConstraintTest() |
||||
{ |
||||
string program = "T MyMethod<T>(T a) where T : ISomeInterface {} "; |
||||
MethodDeclaration md = ParseUtilCSharp.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 GenericMethodInInterface() |
||||
{ |
||||
const string program = @"interface MyInterface {
|
||||
T MyMethod<T>(T a) where T : ISomeInterface; |
||||
} |
||||
";
|
||||
TypeDeclaration td = ParseUtilCSharp.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 GenericVoidMethodInInterface() |
||||
{ |
||||
const string program = @"interface MyInterface {
|
||||
void MyMethod<T>(T a) where T : ISomeInterface; |
||||
} |
||||
";
|
||||
TypeDeclaration td = ParseUtilCSharp.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 ShadowingMethodInInterface() |
||||
{ |
||||
const string program = @"interface MyInterface : IDisposable {
|
||||
new void Dispose(); |
||||
} |
||||
";
|
||||
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); |
||||
MethodDeclaration md = (MethodDeclaration)td.Children[0]; |
||||
Assert.AreEqual("System.Void", md.TypeReference.Type); |
||||
Assert.AreEqual(0, md.Parameters.Count); |
||||
Assert.AreEqual(Modifiers.New, md.Modifier); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodImplementingInterfaceTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("int MyInterface.MyMethod() {} "); |
||||
Assert.AreEqual("System.Int32", md.TypeReference.Type); |
||||
|
||||
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodImplementingGenericInterfaceTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("int MyInterface<string>.MyMethod() {} "); |
||||
Assert.AreEqual("System.Int32", md.TypeReference.Type); |
||||
|
||||
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type); |
||||
Assert.AreEqual("System.String", md.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VoidMethodImplementingInterfaceTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyInterface.MyMethod() {} "); |
||||
Assert.AreEqual("System.Void", md.TypeReference.Type); |
||||
|
||||
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void VoidMethodImplementingGenericInterfaceTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyInterface<string>.MyMethod() {} "); |
||||
Assert.AreEqual("System.Void", md.TypeReference.Type); |
||||
|
||||
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type); |
||||
Assert.AreEqual("System.String", md.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void IncompleteConstraintsTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>( |
||||
"void a<T>() where T { }", true // expect errors
|
||||
); |
||||
Assert.AreEqual("a", md.Name); |
||||
Assert.AreEqual(1, md.Templates.Count); |
||||
Assert.AreEqual("T", md.Templates[0].Name); |
||||
Assert.AreEqual(0, md.Templates[0].Bases.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExtensionMethodTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>( |
||||
"public static int ToInt32(this string s) { return int.Parse(s); }" |
||||
); |
||||
Assert.AreEqual("ToInt32", md.Name); |
||||
Assert.IsTrue(md.IsExtensionMethod); |
||||
Assert.AreEqual("s", md.Parameters[0].ParameterName); |
||||
Assert.AreEqual("System.String", md.Parameters[0].TypeReference.Type); |
||||
} |
||||
*/ |
||||
|
||||
[Test] |
||||
public void VoidExtensionMethodTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>( |
||||
"public static void Print(this string s) { Console.WriteLine(s); }" |
||||
); |
||||
Assert.AreEqual("Print", md.Name); |
||||
Assert.AreEqual("s", md.Parameters.First().Name); |
||||
Assert.AreEqual(ParameterModifier.This, md.Parameters.First().ParameterModifier); |
||||
Assert.AreEqual("string", ((PrimitiveType)md.Parameters.First().Type).Keyword); |
||||
Assert.IsTrue(md.IsExtensionMethod); |
||||
} |
||||
|
||||
/* TODO |
||||
[Test] |
||||
public void MethodWithEmptyAssignmentErrorInBody() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>( |
||||
"void A\n" + |
||||
"{\n" + |
||||
"int a = 3;\n" + |
||||
" = 4;\n" + |
||||
"}", true // expect errors
|
||||
); |
||||
Assert.AreEqual("A", md.Name); |
||||
Assert.AreEqual(new Location(1, 2), md.Body.StartLocation); |
||||
Assert.AreEqual(new Location(2, 5), md.Body.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void OptionalParameterTest() |
||||
{ |
||||
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>( |
||||
"public void Foo(string bar = null, int baz = 0) { }" |
||||
); |
||||
Assert.AreEqual("Foo", md.Name); |
||||
|
||||
Assert.AreEqual("bar", md.Parameters[0].ParameterName); |
||||
Assert.AreEqual("System.String", md.Parameters[0].TypeReference.Type); |
||||
Assert.AreEqual(ParameterModifiers.In | ParameterModifiers.Optional, md.Parameters[0].ParamModifier); |
||||
Assert.IsNull(((PrimitiveExpression)md.Parameters[0].DefaultValue).Value); |
||||
|
||||
Assert.AreEqual("baz", md.Parameters[1].ParameterName); |
||||
Assert.AreEqual("System.Int32", md.Parameters[1].TypeReference.Type); |
||||
Assert.AreEqual(ParameterModifiers.In | ParameterModifiers.Optional, md.Parameters[1].ParamModifier); |
||||
Assert.AreEqual(0, ((PrimitiveExpression)md.Parameters[1].DefaultValue).Value); |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// 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.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture] |
||||
public class OperatorDeclarationTests |
||||
{ |
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void ImplictOperatorDeclarationTest() |
||||
{ |
||||
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static implicit operator double(MyObject f) { return 0.5d; }"); |
||||
Assert.AreEqual(OperatorType.Implicit, od.OperatorType); |
||||
Assert.AreEqual(1, od.Parameters.Count()); |
||||
Assert.AreEqual("System.Double", od.ReturnType); |
||||
Assert.AreEqual("op_Implicit", od.Name); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void ExplicitOperatorDeclarationTest() |
||||
{ |
||||
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static explicit operator double(MyObject f) { return 0.5d; }"); |
||||
Assert.AreEqual(OperatorType.Explicit, od.OperatorType); |
||||
Assert.AreEqual(1, od.Parameters.Count()); |
||||
Assert.AreEqual("System.Double", od.ReturnType); |
||||
Assert.AreEqual("op_Explicit", od.Name); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void BinaryPlusOperatorDeclarationTest() |
||||
{ |
||||
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static MyObject operator +(MyObject a, MyObject b) {}"); |
||||
Assert.AreEqual(OperatorType.Addition, od.OperatorType); |
||||
Assert.AreEqual(2, od.Parameters.Count()); |
||||
Assert.AreEqual("MyObject", od.ReturnType); |
||||
Assert.AreEqual("op_Addition", od.Name); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void UnaryPlusOperatorDeclarationTest() |
||||
{ |
||||
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static MyObject operator +(MyObject a) {}"); |
||||
Assert.AreEqual(OperatorType.UnaryPlus, od.OperatorType); |
||||
Assert.AreEqual(1, od.Parameters.Count()); |
||||
Assert.AreEqual("MyObject", od.ReturnType); |
||||
Assert.AreEqual("op_UnaryPlus", od.Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
// 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.IO; |
||||
using System.Linq; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers |
||||
{ |
||||
[TestFixture] |
||||
public class PropertyDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void SimpleGetSetPropertyDeclarationTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyProperty { get {} set {} } "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.Getter.IsNull); |
||||
Assert.IsFalse(pd.Setter.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetSetPropertyDeclarationWithAccessorModifiers() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyProperty { private get {} protected internal set {} } "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.Getter.IsNull); |
||||
Assert.IsFalse(pd.Setter.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleGetPropertyDeclarationTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyProperty { get {} } "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.Getter.IsNull); |
||||
Assert.IsTrue(pd.Setter.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleSetPropertyDeclarationTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyProperty { set {} } "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsTrue(pd.Getter.IsNull); |
||||
Assert.IsFalse(pd.Setter.IsNull); |
||||
} |
||||
|
||||
[Test] |
||||
public void PropertyRegionTest() |
||||
{ |
||||
const string code = "class T {\n\tint Prop {\n\t\tget { return f; }\n\t\tset { f = value; }\n\t}\n}\n"; |
||||
int line2Pos = code.IndexOf("\tint Prop"); |
||||
int line3Pos = code.IndexOf("\t\tget"); |
||||
int line4Pos = code.IndexOf("\t\tset"); |
||||
|
||||
CSharpParser parser = new CSharpParser(); |
||||
CompilationUnit cu = parser.Parse(new StringReader(code)); |
||||
PropertyDeclaration pd = (PropertyDeclaration)cu.Children.Single().GetChildByRole(TypeDeclaration.MemberRole); |
||||
Assert.AreEqual(new AstLocation(2, code.IndexOf("{\n\t\tget") - line2Pos + 1), pd.GetChildByRole(AstNode.Roles.LBrace).StartLocation); |
||||
Assert.AreEqual(new AstLocation(5, 3), pd.EndLocation); |
||||
Assert.AreEqual(new AstLocation(3, code.IndexOf("{ return") - line3Pos + 1), pd.Getter.Body.StartLocation); |
||||
Assert.AreEqual(new AstLocation(3, code.IndexOf("}\n\t\tset") + 1 - line3Pos + 1), pd.Getter.Body.EndLocation); |
||||
Assert.AreEqual(new AstLocation(4, code.IndexOf("{ f =") - line4Pos + 1), pd.Setter.Body.StartLocation); |
||||
Assert.AreEqual(new AstLocation(4, code.IndexOf("}\n\t}") + 1 - line4Pos + 1), pd.Setter.Body.EndLocation); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void PropertyImplementingInterfaceTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface.MyProperty { get {} } "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.Getter.IsNull); |
||||
Assert.IsTrue(pd.Setter.IsNull); |
||||
|
||||
Assert.AreEqual("MyInterface", pd.PrivateImplementationType); |
||||
} |
||||
|
||||
[Test, Ignore("type references not yet implemented")] |
||||
public void PropertyImplementingGenericInterfaceTest() |
||||
{ |
||||
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface<string>.MyProperty { get {} } "); |
||||
Assert.AreEqual("MyProperty", pd.Name); |
||||
Assert.IsFalse(pd.Getter.IsNull); |
||||
Assert.IsTrue(pd.Setter.IsNull); |
||||
|
||||
throw new NotImplementedException(); |
||||
//Assert.AreEqual("MyInterface", pd.InterfaceImplementations[0].InterfaceType.Type);
|
||||
//Assert.AreEqual("System.String", pd.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// 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.IO; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Parser |
||||
{ |
||||
[TestFixture, Ignore("TypeSystemConvertVisitor is not complete yet")] |
||||
public class TypeSystemConvertVisitorTests : TypeSystemTests |
||||
{ |
||||
ITypeResolveContext ctx = CecilLoaderTests.Mscorlib; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureSetUp() |
||||
{ |
||||
const string fileName = "TypeSystemTests.TestCase.cs"; |
||||
|
||||
CSharpParser parser = new CSharpParser(); |
||||
CompilationUnit cu; |
||||
using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) { |
||||
cu = parser.Parse(s); |
||||
} |
||||
|
||||
testCasePC = new SimpleProjectContent(); |
||||
TypeSystemConvertVisitor visitor = new TypeSystemConvertVisitor(testCasePC, fileName); |
||||
cu.AcceptVisitor(visitor, null); |
||||
ParsedFile parsedFile = visitor.ParsedFile; |
||||
((SimpleProjectContent)testCasePC).UpdateProjectContent(null, parsedFile.TopLevelTypeDefinitions, null, null); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
// 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
[TestFixture, Ignore("DOM for attributes is incomplete")] |
||||
public class AttributeTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void NamespaceInAttributeContext() |
||||
{ |
||||
string program = "using System; [$System.Runtime$.CompilerServices.IndexerName(\"bla\")] class Test { }"; |
||||
NamespaceResolveResult result = Resolve<NamespaceResolveResult>(program); |
||||
Assert.AreEqual("System.Runtime", result.NamespaceName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeWithShortName() |
||||
{ |
||||
string program = "using System; [$Obsolete$] class Test {}"; |
||||
|
||||
TypeResolveResult result = Resolve<TypeResolveResult>(program); |
||||
Assert.AreEqual("System.ObsoleteAttribute", result.Type.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void QualifiedAttributeWithShortName() |
||||
{ |
||||
string program = "using System; [$System.Obsolete$] class Test {}"; |
||||
|
||||
TypeResolveResult result = Resolve<TypeResolveResult>(program); |
||||
Assert.AreEqual("System.ObsoleteAttribute", result.Type.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeConstructor1() |
||||
{ |
||||
string program = "using System; [$LoaderOptimization(3)$] class Test { }"; |
||||
var mrr = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("System.LoaderOptimization.#ctor", mrr.Member.FullName); |
||||
Assert.AreEqual("System.Byte", (mrr.Member as IMethod).Parameters[0].Type.Resolve(context).FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeConstructor2() |
||||
{ |
||||
string program = "using System; [$LoaderOptimization(LoaderOptimization.NotSpecified)$] class Test { }"; |
||||
var mrr = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("System.LoaderOptimization.#ctor", mrr.Member.FullName); |
||||
Assert.AreEqual("System.LoaderOptimization", (mrr.Member as IMethod).Parameters[0].Type.Resolve(context).FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeArgumentInClassContext1() |
||||
{ |
||||
string program = @"using System;
|
||||
[AttributeUsage($XXX$)] class MyAttribute : Attribute { |
||||
public const AttributeTargets XXX = AttributeTargets.All; |
||||
} |
||||
";
|
||||
MemberResolveResult result = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("MyAttribute.XXX", result.Member.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeArgumentInClassContext2() |
||||
{ |
||||
string program = @"using System; namespace MyNamespace {
|
||||
[SomeAttribute($E.A$)] class Test { } |
||||
enum E { A, B } |
||||
} |
||||
";
|
||||
MemberResolveResult result = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("MyNamespace.E.A", result.Member.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void SD_1384() |
||||
{ |
||||
string program = @"using System;
|
||||
class Flags { |
||||
[Flags] |
||||
enum $Test$ { } |
||||
}";
|
||||
TypeResolveResult result = Resolve<TypeResolveResult>(program); |
||||
Assert.AreEqual("Flags.Test", result.Type.FullName); |
||||
|
||||
var rt = result.Type.GetDefinition().Attributes[0].AttributeType.Resolve(context); |
||||
Assert.AreEqual("System.FlagsAttribute", rt.FullName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,392 @@
@@ -0,0 +1,392 @@
|
||||
// Copyright (c) 2010 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
// assign short name to the fake reflection type
|
||||
using dynamic = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Dynamic; |
||||
|
||||
[TestFixture] |
||||
public unsafe class BinaryOperatorTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void Multiplication() |
||||
{ |
||||
AssertType(typeof(int), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Multiply, MakeResult(typeof(int)), MakeResult(typeof(int)))); |
||||
|
||||
AssertType(typeof(float), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Multiply, MakeResult(typeof(int)), MakeConstant(0.0f))); |
||||
|
||||
AssertConstant(3.0f, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Multiply, MakeConstant(1.5f), MakeConstant(2))); |
||||
|
||||
AssertConstant(6, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Multiply, MakeConstant((byte)2), MakeConstant((byte)3))); |
||||
|
||||
AssertType(typeof(long?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Multiply, MakeResult(typeof(uint?)), MakeResult(typeof(int?)))); |
||||
|
||||
AssertError(typeof(decimal), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Multiply, MakeResult(typeof(float)), MakeResult(typeof(decimal)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Addition() |
||||
{ |
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(short)), MakeResult(typeof(byte?)))); |
||||
|
||||
AssertConstant(3.0, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(1.0f), MakeConstant(2.0))); |
||||
|
||||
AssertConstant(StringComparison.Ordinal, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(StringComparison.InvariantCulture), MakeConstant(2))); |
||||
|
||||
AssertConstant(StringComparison.OrdinalIgnoreCase, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant((short)3), MakeConstant(StringComparison.InvariantCulture))); |
||||
|
||||
AssertConstant("Text", resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant("Te"), MakeConstant("xt"))); |
||||
|
||||
AssertConstant("", resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(null), resolver.ResolveCast(ResolveType(typeof(string)), MakeConstant(null)))); |
||||
|
||||
AssertError(typeof(ReflectionHelper.Null), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(null), MakeConstant(null))); |
||||
|
||||
AssertType(typeof(Action), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(Action)), MakeResult(typeof(Action)))); |
||||
|
||||
AssertType(typeof(Action<string>), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(Action<object>)), MakeResult(typeof(Action<string>)))); |
||||
|
||||
Assert.IsTrue(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(Action<int>)), MakeResult(typeof(Action<long>))).IsError); |
||||
|
||||
AssertType(typeof(StringComparison?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(StringComparison?)), MakeResult(typeof(int)))); |
||||
|
||||
AssertType(typeof(StringComparison?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(int?)), MakeResult(typeof(StringComparison)))); |
||||
|
||||
AssertType(typeof(long?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(int?)), MakeResult(typeof(uint?)))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(ushort?)), MakeResult(typeof(ushort?)))); |
||||
|
||||
Assert.IsTrue(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(null), MakeConstant(null)).IsError); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(1), MakeConstant(null))); |
||||
|
||||
AssertType(typeof(int*), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(int*)), MakeConstant(1))); |
||||
|
||||
AssertType(typeof(byte*), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeResult(typeof(long)), MakeResult(typeof(byte*)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void AdditionWithOverflow() |
||||
{ |
||||
resolver.CheckForOverflow = false; |
||||
AssertConstant(int.MinValue, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(int.MaxValue), MakeConstant(1))); |
||||
|
||||
resolver.CheckForOverflow = true; |
||||
AssertError(typeof(int), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Add, MakeConstant(int.MaxValue), MakeConstant(1))); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void Subtraction() |
||||
{ |
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(short)), MakeResult(typeof(byte?)))); |
||||
|
||||
AssertConstant(-1.0, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeConstant(1.0f), MakeConstant(2.0))); |
||||
|
||||
AssertConstant(StringComparison.InvariantCulture, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeConstant(StringComparison.Ordinal), MakeConstant(2))); |
||||
|
||||
AssertConstant(3, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeConstant(StringComparison.OrdinalIgnoreCase), MakeConstant(StringComparison.InvariantCulture))); |
||||
|
||||
Assert.IsTrue(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeConstant("Te"), MakeConstant("xt")).IsError); |
||||
|
||||
AssertType(typeof(Action), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(Action)), MakeResult(typeof(Action)))); |
||||
|
||||
AssertType(typeof(Action<string>), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(Action<object>)), MakeResult(typeof(Action<string>)))); |
||||
|
||||
Assert.IsTrue(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(Action<int>)), MakeResult(typeof(Action<long>))).IsError); |
||||
|
||||
AssertType(typeof(StringComparison?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(StringComparison?)), MakeResult(typeof(int)))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(StringComparison?)), MakeResult(typeof(StringComparison)))); |
||||
|
||||
Assert.IsTrue(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(int?)), MakeResult(typeof(StringComparison))).IsError); |
||||
|
||||
AssertType(typeof(byte*), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(byte*)), MakeResult(typeof(uint)))); |
||||
|
||||
AssertType(typeof(long), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Subtract, MakeResult(typeof(byte*)), MakeResult(typeof(byte*)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShiftTest() |
||||
{ |
||||
AssertConstant(6, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ShiftLeft, MakeConstant(3), MakeConstant(1))); |
||||
|
||||
AssertConstant(ulong.MaxValue >> 2, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ShiftRight, MakeConstant(ulong.MaxValue), MakeConstant(2))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ShiftLeft, MakeResult(typeof(ushort?)), MakeConstant(1))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ShiftLeft, MakeConstant(null), MakeConstant(1))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ShiftLeft, MakeConstant(null), MakeConstant(null))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Equality() |
||||
{ |
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(3), MakeConstant(3))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(3), MakeConstant(3.0))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(2.9), MakeConstant(3))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(double.NaN), MakeConstant(double.NaN))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(float.NaN), MakeConstant(float.NaN))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant("A"), MakeConstant("B"))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant("A"), MakeConstant("A"))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(""), MakeConstant(null))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(null), MakeConstant(null))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(1), MakeConstant(null))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(null), MakeConstant('a'))); |
||||
|
||||
AssertType(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeResult(typeof(int*)), MakeResult(typeof(uint*)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void Inequality() |
||||
{ |
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(3), MakeConstant(3))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(3), MakeConstant(3.0))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(2.9), MakeConstant(3))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(double.NaN), MakeConstant(double.NaN))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(float.NaN), MakeConstant(double.NaN))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(float.NaN), MakeConstant(float.NaN))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant("A"), MakeConstant("B"))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant("A"), MakeConstant("A"))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(""), MakeConstant(null))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(null), MakeConstant(null))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(1), MakeConstant(null))); |
||||
|
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeConstant(null), MakeConstant('a'))); |
||||
|
||||
AssertType(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.InEquality, MakeResult(typeof(int*)), MakeResult(typeof(uint*)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void EqualityEnum() |
||||
{ |
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(0), MakeConstant(StringComparison.Ordinal))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(0), MakeConstant(StringComparison.Ordinal))); |
||||
|
||||
Assert.IsFalse(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.Equality, MakeConstant(StringComparison.Ordinal), MakeConstant(1)).IsCompileTimeConstant); |
||||
} |
||||
|
||||
[Test] |
||||
public void RelationalOperators() |
||||
{ |
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.LessThan, MakeConstant(0), MakeConstant(0))); |
||||
|
||||
AssertType(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.LessThan, MakeResult(typeof(int*)), MakeResult(typeof(uint*)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void RelationalEnum() |
||||
{ |
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.LessThan, MakeConstant(0), MakeConstant(StringComparison.Ordinal))); |
||||
|
||||
AssertError(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.LessThanOrEqual, MakeConstant(1), MakeConstant(StringComparison.Ordinal))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.GreaterThan, MakeConstant(StringComparison.CurrentCultureIgnoreCase), MakeConstant(StringComparison.Ordinal))); |
||||
|
||||
AssertType(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.GreaterThan, MakeResult(typeof(StringComparison?)), MakeResult(typeof(StringComparison?)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitAnd() |
||||
{ |
||||
AssertConstant(5, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeConstant(7), MakeConstant(13))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeConstant(null), MakeConstant((short)13))); |
||||
|
||||
AssertType(typeof(long?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeResult(typeof(uint?)), MakeConstant((short)13))); |
||||
|
||||
AssertType(typeof(uint?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeResult(typeof(uint?)), MakeConstant((int)13))); |
||||
|
||||
AssertType(typeof(ulong?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeResult(typeof(ulong?)), MakeConstant((long)13))); |
||||
|
||||
Assert.IsTrue(resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeResult(typeof(ulong?)), MakeConstant((short)13)).IsError); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitXor() |
||||
{ |
||||
AssertConstant(6L ^ 3, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ExclusiveOr, MakeConstant(6L), MakeConstant(3))); |
||||
|
||||
AssertConstant(6UL ^ 3L, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ExclusiveOr, MakeConstant(6UL), MakeConstant(3L))); |
||||
|
||||
AssertError(typeof(ulong), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ExclusiveOr, MakeConstant(6UL), MakeConstant(-3L))); |
||||
} |
||||
|
||||
[Test] |
||||
public void BitwiseEnum() |
||||
{ |
||||
AssertConstant(AttributeTargets.Field | AttributeTargets.Property, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseOr, MakeConstant(AttributeTargets.Field), MakeConstant(AttributeTargets.Property))); |
||||
|
||||
AssertConstant(AttributeTargets.Field & AttributeTargets.All, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeConstant(AttributeTargets.Field), MakeConstant(AttributeTargets.All))); |
||||
|
||||
AssertConstant(AttributeTargets.Field & 0, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseAnd, MakeConstant(AttributeTargets.Field), MakeConstant(0))); |
||||
|
||||
AssertConstant(0 | AttributeTargets.Field, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.BitwiseOr, MakeConstant(0), MakeConstant(AttributeTargets.Field))); |
||||
} |
||||
|
||||
[Test] |
||||
public void LogicalAnd() |
||||
{ |
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ConditionalAnd, MakeConstant(true), MakeConstant(true))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ConditionalAnd, MakeConstant(false), MakeConstant(true))); |
||||
|
||||
AssertError(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ConditionalAnd, MakeConstant(false), MakeResult(typeof(bool?)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void LogicalOr() |
||||
{ |
||||
AssertConstant(true, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ConditionalOr, MakeConstant(false), MakeConstant(true))); |
||||
|
||||
AssertConstant(false, resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ConditionalOr, MakeConstant(false), MakeConstant(false))); |
||||
|
||||
AssertError(typeof(bool), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.ConditionalOr, MakeConstant(false), MakeResult(typeof(bool?)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullCoalescing() |
||||
{ |
||||
AssertType(typeof(int), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.NullCoalescing, MakeResult(typeof(int?)), MakeResult(typeof(short)))); |
||||
|
||||
AssertType(typeof(int?), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.NullCoalescing, MakeResult(typeof(int?)), MakeResult(typeof(short?)))); |
||||
|
||||
AssertType(typeof(object), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.NullCoalescing, MakeResult(typeof(string)), MakeResult(typeof(object)))); |
||||
|
||||
AssertError(typeof(string), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.NullCoalescing, MakeResult(typeof(string)), MakeResult(typeof(int)))); |
||||
|
||||
AssertType(typeof(dynamic), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.NullCoalescing, MakeResult(typeof(dynamic)), MakeResult(typeof(string)))); |
||||
|
||||
AssertType(typeof(dynamic), resolver.ResolveBinaryOperator( |
||||
BinaryOperatorType.NullCoalescing, MakeResult(typeof(string)), MakeResult(typeof(dynamic)))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2010 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
// assign short name to the fake reflection type
|
||||
using dynamic = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Dynamic; |
||||
|
||||
[TestFixture] |
||||
public class CastTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void SimpleCast() |
||||
{ |
||||
AssertType(typeof(int), resolver.ResolveCast(ResolveType(typeof(int)), MakeResult(typeof(float)))); |
||||
AssertType(typeof(string), resolver.ResolveCast(ResolveType(typeof(string)), MakeResult(typeof(object)))); |
||||
AssertType(typeof(byte), resolver.ResolveCast(ResolveType(typeof(byte)), MakeResult(typeof(dynamic)))); |
||||
AssertType(typeof(dynamic), resolver.ResolveCast(ResolveType(typeof(dynamic)), MakeResult(typeof(double)))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConstantValueCast() |
||||
{ |
||||
AssertConstant("Hello", resolver.ResolveCast(ResolveType(typeof(string)), MakeConstant("Hello"))); |
||||
AssertConstant((byte)1L, resolver.ResolveCast(ResolveType(typeof(byte)), MakeConstant(1L))); |
||||
AssertConstant(3, resolver.ResolveCast(ResolveType(typeof(int)), MakeConstant(3.1415))); |
||||
AssertConstant(3, resolver.ResolveCast(ResolveType(typeof(int)), MakeConstant(3.99))); |
||||
AssertConstant((short)-3, resolver.ResolveCast(ResolveType(typeof(short)), MakeConstant(-3.99f))); |
||||
AssertConstant(-3L, resolver.ResolveCast(ResolveType(typeof(long)), MakeConstant(-3.5))); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverflowingCast() |
||||
{ |
||||
resolver.CheckForOverflow = false; |
||||
AssertConstant(uint.MaxValue, resolver.ResolveCast(ResolveType(typeof(uint)), MakeConstant(-1.6))); |
||||
resolver.CheckForOverflow = true; |
||||
AssertError(typeof(uint), resolver.ResolveCast(ResolveType(typeof(uint)), MakeConstant(-1.6))); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailingStringCast() |
||||
{ |
||||
AssertError(typeof(string), resolver.ResolveCast(ResolveType(typeof(string)), MakeConstant(1))); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverflowingCastToEnum() |
||||
{ |
||||
resolver.CheckForOverflow = true; |
||||
AssertError(typeof(StringComparison), resolver.ResolveCast(ResolveType(typeof(StringComparison)), MakeConstant(long.MaxValue))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,336 @@
@@ -0,0 +1,336 @@
|
||||
// Copyright (c) 2010 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
// assign short names to the fake reflection types
|
||||
using Null = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Null; |
||||
using dynamic = ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.Dynamic; |
||||
|
||||
[TestFixture] |
||||
public unsafe class ConversionsTest |
||||
{ |
||||
IProjectContent mscorlib = CecilLoaderTests.Mscorlib; |
||||
Conversions conversions = new Conversions(CecilLoaderTests.Mscorlib); |
||||
|
||||
bool ImplicitConversion(Type from, Type to) |
||||
{ |
||||
IType from2 = from.ToTypeReference().Resolve(mscorlib); |
||||
IType to2 = to.ToTypeReference().Resolve(mscorlib); |
||||
return conversions.ImplicitConversion(from2, to2); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdentityConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(char), typeof(char))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(string), typeof(string))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(object), typeof(object))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(bool), typeof(char))); |
||||
|
||||
Assert.IsTrue(conversions.ImplicitConversion(SharedTypes.Dynamic, SharedTypes.Dynamic)); |
||||
Assert.IsTrue(conversions.ImplicitConversion(SharedTypes.UnknownType, SharedTypes.UnknownType)); |
||||
Assert.IsTrue(conversions.ImplicitConversion(SharedTypes.Null, SharedTypes.Null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void DynamicIdentityConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(object), typeof(ReflectionHelper.Dynamic))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(ReflectionHelper.Dynamic), typeof(object))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComplexDynamicIdentityConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(List<object>), typeof(List<dynamic>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(List<dynamic>), typeof(List<object>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(List<string>), typeof(List<dynamic>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(List<dynamic>), typeof(List<string>))); |
||||
|
||||
Assert.IsTrue(ImplicitConversion(typeof(List<List<dynamic>[]>), typeof(List<List<object>[]>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(List<List<object>[]>), typeof(List<List<dynamic>[]>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(List<List<object>[,]>), typeof(List<List<dynamic>[]>))); |
||||
} |
||||
|
||||
[Test] |
||||
public void PrimitiveConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(char), typeof(ushort))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(byte), typeof(char))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int), typeof(long))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(long), typeof(int))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int), typeof(float))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(bool), typeof(float))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(float), typeof(double))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(float), typeof(decimal))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(char), typeof(long))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(uint), typeof(long))); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(char), typeof(ushort?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(byte), typeof(char?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int), typeof(long?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(long), typeof(int?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int), typeof(float?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(bool), typeof(float?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(float), typeof(double?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(float), typeof(decimal?))); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullableConversions2() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(char?), typeof(ushort?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(byte?), typeof(char?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int?), typeof(long?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(long?), typeof(int?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int?), typeof(float?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(bool?), typeof(float?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(float?), typeof(double?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(float?), typeof(decimal?))); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullLiteralConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(int?))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(char?))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(Null), typeof(int))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(object))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(dynamic))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(string))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(int[]))); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleReferenceConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(string), typeof(object))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(BitArray), typeof(ICollection))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(IList), typeof(IEnumerable))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(object), typeof(string))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(ICollection), typeof(BitArray))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(IEnumerable), typeof(IList))); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleDynamicConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(string), typeof(dynamic))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(dynamic), typeof(string))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int), typeof(dynamic))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(dynamic), typeof(int))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterizedTypeConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(List<string>), typeof(ICollection<string>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(IList<string>), typeof(ICollection<string>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(List<string>), typeof(ICollection<object>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(IList<string>), typeof(ICollection<object>))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(string[]), typeof(object[]))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(string[,]), typeof(object[,]))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(string[]), typeof(object[,]))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(object[]), typeof(string[]))); |
||||
|
||||
Assert.IsTrue(ImplicitConversion(typeof(string[]), typeof(IList<string>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(string[,]), typeof(IList<string>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(string[]), typeof(IList<object>))); |
||||
|
||||
Assert.IsTrue(ImplicitConversion(typeof(string[]), typeof(Array))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(string[]), typeof(ICloneable))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(Array), typeof(string[]))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(object), typeof(object[]))); |
||||
} |
||||
|
||||
[Test] |
||||
public void VarianceConversions() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(List<string>), typeof(IEnumerable<object>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(List<object>), typeof(IEnumerable<string>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(IEnumerable<string>), typeof(IEnumerable<object>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(ICollection<string>), typeof(ICollection<object>))); |
||||
|
||||
Assert.IsTrue(ImplicitConversion(typeof(Comparer<object>), typeof(IComparer<string>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Comparer<object>), typeof(IComparer<Array>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(Comparer<object>), typeof(Comparer<string>))); |
||||
|
||||
Assert.IsFalse(ImplicitConversion(typeof(List<object>), typeof(IEnumerable<string>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(IEnumerable<string>), typeof(IEnumerable<object>))); |
||||
|
||||
Assert.IsTrue(ImplicitConversion(typeof(Func<ICollection, ICollection>), typeof(Func<IList, IEnumerable>))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(Func<IEnumerable, IList>), typeof(Func<ICollection, ICollection>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(Func<ICollection, ICollection>), typeof(Func<IEnumerable, IList>))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(Func<IList, IEnumerable>), typeof(Func<ICollection, ICollection>))); |
||||
} |
||||
|
||||
[Test] |
||||
public void PointerConversion() |
||||
{ |
||||
Assert.IsTrue(ImplicitConversion(typeof(Null), typeof(int*))); |
||||
Assert.IsTrue(ImplicitConversion(typeof(int*), typeof(void*))); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoConversionFromPointerTypeToObject() |
||||
{ |
||||
Assert.IsFalse(ImplicitConversion(typeof(int*), typeof(object))); |
||||
Assert.IsFalse(ImplicitConversion(typeof(int*), typeof(dynamic))); |
||||
} |
||||
|
||||
[Test, Ignore] |
||||
public void TypeParameterConversions() |
||||
{ |
||||
// TODO: write tests for conversions of type parameters
|
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
bool IntegerLiteralConversion(object value, Type to) |
||||
{ |
||||
IType fromType = value.GetType().ToTypeReference().Resolve(mscorlib); |
||||
ConstantResolveResult crr = new ConstantResolveResult(fromType, value); |
||||
IType to2 = to.ToTypeReference().Resolve(mscorlib); |
||||
return conversions.ImplicitConversion(crr, to2); |
||||
} |
||||
|
||||
[Test] |
||||
public void IntegerLiteralToEnumConversions() |
||||
{ |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(LoaderOptimization))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0L, typeof(LoaderOptimization))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(LoaderOptimization?))); |
||||
Assert.IsFalse(IntegerLiteralConversion(0, typeof(string))); |
||||
Assert.IsFalse(IntegerLiteralConversion(1, typeof(LoaderOptimization))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitConstantExpressionConversion() |
||||
{ |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(int))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(ushort))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(sbyte))); |
||||
|
||||
Assert.IsTrue (IntegerLiteralConversion(-1, typeof(int))); |
||||
Assert.IsFalse(IntegerLiteralConversion(-1, typeof(ushort))); |
||||
Assert.IsTrue (IntegerLiteralConversion(-1, typeof(sbyte))); |
||||
|
||||
Assert.IsTrue (IntegerLiteralConversion(200, typeof(int))); |
||||
Assert.IsTrue (IntegerLiteralConversion(200, typeof(ushort))); |
||||
Assert.IsFalse(IntegerLiteralConversion(200, typeof(sbyte))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitLongConstantExpressionConversion() |
||||
{ |
||||
Assert.IsFalse(IntegerLiteralConversion(0L, typeof(int))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0L, typeof(long))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0L, typeof(ulong))); |
||||
|
||||
Assert.IsTrue(IntegerLiteralConversion(-1L, typeof(long))); |
||||
Assert.IsFalse(IntegerLiteralConversion(-1L, typeof(ulong))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitConstantExpressionConversionToNullable() |
||||
{ |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(uint?))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(short?))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(byte?))); |
||||
|
||||
Assert.IsFalse(IntegerLiteralConversion(-1, typeof(uint?))); |
||||
Assert.IsTrue (IntegerLiteralConversion(-1, typeof(short?))); |
||||
Assert.IsFalse(IntegerLiteralConversion(-1, typeof(byte?))); |
||||
|
||||
Assert.IsTrue(IntegerLiteralConversion(200, typeof(uint?))); |
||||
Assert.IsTrue(IntegerLiteralConversion(200, typeof(short?))); |
||||
Assert.IsTrue(IntegerLiteralConversion(200, typeof(byte?))); |
||||
|
||||
Assert.IsFalse(IntegerLiteralConversion(0L, typeof(uint?))); |
||||
Assert.IsTrue (IntegerLiteralConversion(0L, typeof(long?))); |
||||
Assert.IsTrue (IntegerLiteralConversion(0L, typeof(ulong?))); |
||||
|
||||
Assert.IsTrue(IntegerLiteralConversion(-1L, typeof(long?))); |
||||
Assert.IsFalse(IntegerLiteralConversion(-1L, typeof(ulong?))); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitConstantExpressionConversionNumberInterfaces() |
||||
{ |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(IFormattable))); |
||||
Assert.IsTrue(IntegerLiteralConversion(0, typeof(IComparable<int>))); |
||||
Assert.IsFalse(IntegerLiteralConversion(0, typeof(IComparable<short>))); |
||||
Assert.IsFalse(IntegerLiteralConversion(0, typeof(IComparable<long>))); |
||||
} |
||||
|
||||
int BetterConversion(Type s, Type t1, Type t2) |
||||
{ |
||||
IType sType = s.ToTypeReference().Resolve(mscorlib); |
||||
IType t1Type = t1.ToTypeReference().Resolve(mscorlib); |
||||
IType t2Type = t2.ToTypeReference().Resolve(mscorlib); |
||||
return conversions.BetterConversion(sType, t1Type, t2Type); |
||||
} |
||||
|
||||
int BetterConversion(object value, Type t1, Type t2) |
||||
{ |
||||
IType fromType = value.GetType().ToTypeReference().Resolve(mscorlib); |
||||
ConstantResolveResult crr = new ConstantResolveResult(fromType, value); |
||||
IType t1Type = t1.ToTypeReference().Resolve(mscorlib); |
||||
IType t2Type = t2.ToTypeReference().Resolve(mscorlib); |
||||
return conversions.BetterConversion(crr, t1Type, t2Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void BetterConversion() |
||||
{ |
||||
Assert.AreEqual(1, BetterConversion(typeof(string), typeof(string), typeof(object))); |
||||
Assert.AreEqual(2, BetterConversion(typeof(string), typeof(object), typeof(IComparable<string>))); |
||||
Assert.AreEqual(0, BetterConversion(typeof(string), typeof(IEnumerable<char>), typeof(IComparable<string>))); |
||||
} |
||||
|
||||
[Test] |
||||
public void BetterPrimitiveConversion() |
||||
{ |
||||
Assert.AreEqual(1, BetterConversion(typeof(short), typeof(int), typeof(long))); |
||||
Assert.AreEqual(1, BetterConversion(typeof(short), typeof(int), typeof(uint))); |
||||
Assert.AreEqual(2, BetterConversion(typeof(ushort), typeof(uint), typeof(int))); |
||||
Assert.AreEqual(1, BetterConversion(typeof(char), typeof(short), typeof(int))); |
||||
Assert.AreEqual(1, BetterConversion(typeof(char), typeof(ushort), typeof(int))); |
||||
Assert.AreEqual(1, BetterConversion(typeof(sbyte), typeof(long), typeof(ulong))); |
||||
Assert.AreEqual(2, BetterConversion(typeof(byte), typeof(ushort), typeof(short))); |
||||
|
||||
Assert.AreEqual(1, BetterConversion(1, typeof(sbyte), typeof(byte))); |
||||
Assert.AreEqual(2, BetterConversion(1, typeof(ushort), typeof(sbyte))); |
||||
} |
||||
|
||||
[Test] |
||||
public void BetterNullableConversion() |
||||
{ |
||||
Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(int), typeof(uint?))); |
||||
Assert.AreEqual(0, BetterConversion(typeof(byte?), typeof(int?), typeof(uint?))); |
||||
Assert.AreEqual(1, BetterConversion(typeof(byte), typeof(ushort?), typeof(uint?))); |
||||
Assert.AreEqual(2, BetterConversion(typeof(byte?), typeof(ulong?), typeof(uint?))); |
||||
Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(ushort?), typeof(uint))); |
||||
Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(ushort?), typeof(int))); |
||||
Assert.AreEqual(2, BetterConversion(typeof(byte), typeof(ulong?), typeof(uint))); |
||||
Assert.AreEqual(0, BetterConversion(typeof(byte), typeof(ulong?), typeof(int))); |
||||
Assert.AreEqual(2, BetterConversion(typeof(ushort?), typeof(long?), typeof(int?))); |
||||
Assert.AreEqual(0, BetterConversion(typeof(sbyte), typeof(int?), typeof(uint?))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
// 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
[TestFixture] |
||||
public class ExtensionMethodTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void ExtensionMethodsTest() |
||||
{ |
||||
string program = @"using XN;
|
||||
class TestClass { |
||||
static void Test(A a, B b, C c) { |
||||
$; |
||||
} |
||||
} |
||||
class A { } |
||||
class B { |
||||
public void F(int i) { } |
||||
} |
||||
class C { |
||||
public void F(object obj) { } |
||||
} |
||||
namespace XN { |
||||
public static class XC { |
||||
public static void F(this object obj, int i) { } |
||||
public static void F(this object obj, string s) { } |
||||
} |
||||
} |
||||
";
|
||||
MemberResolveResult mrr; |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$a.F(1)$")); |
||||
Assert.AreEqual("XN.XC.F", mrr.Member.FullName); |
||||
Assert.AreEqual("System.Int32", ((IMethod)mrr.Member).Parameters[1].Type.Resolve(context).FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$a.F(\"text\")$")); |
||||
Assert.AreEqual("XN.XC.F", mrr.Member.FullName); |
||||
Assert.AreEqual("System.String", ((IMethod)mrr.Member).Parameters[1].Type.Resolve(context).FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$b.F(1)$")); |
||||
Assert.AreEqual("B.F", mrr.Member.FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$b.F(\"text\")$")); |
||||
Assert.AreEqual("XN.XC.F", mrr.Member.FullName); |
||||
Assert.AreEqual("System.String", ((IMethod)mrr.Member).Parameters[1].Type.Resolve(context).FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$c.F(1)$")); |
||||
Assert.AreEqual("C.F", mrr.Member.FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$c.F(\"text\")$")); |
||||
Assert.AreEqual("C.F", mrr.Member.FullName); |
||||
} |
||||
|
||||
[Test, Ignore("Test fails due to parser returning incorrect position")] |
||||
public void ExtensionMethodsTest2() |
||||
{ |
||||
string program = @"using System; using System.Collections.Generic;
|
||||
class TestClass { |
||||
static void Test(string[] args) { |
||||
$; |
||||
} |
||||
} |
||||
public static class XC { |
||||
public static int ToInt32(this string s) { return int.Parse(s); } |
||||
public static T[] Slice<T>(this T[] source, int index, int count) { throw new NotImplementedException(); } |
||||
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source, Predicate<T> predicate) { throw new NotImplementedException(); } |
||||
} |
||||
";
|
||||
MemberResolveResult mrr; |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$\"text\".ToInt32()$")); |
||||
Assert.AreEqual("XC.ToInt32", mrr.Member.FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$args.Slice(1, 2)$")); |
||||
Assert.AreEqual("XC.Slice", mrr.Member.FullName); |
||||
Assert.AreEqual("System.String[]", mrr.Type.ReflectionName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("$", "$args.Filter(delegate { return true; })$")); |
||||
Assert.AreEqual("XC.Filter", mrr.Member.FullName); |
||||
Assert.AreEqual("System.Collections.Generic.IEnumerable{System.String}", mrr.Type.ReflectionName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,268 @@
@@ -0,0 +1,268 @@
|
||||
// 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
[TestFixture] |
||||
public class InvocationTests : ResolverTestBase |
||||
{ |
||||
// TODO: do we want to return the MemberResolveResult for the InvocationExpression, or only for it's target?
|
||||
|
||||
[Test] |
||||
public void MethodCallTest() |
||||
{ |
||||
string program = @"class A {
|
||||
void Method() { |
||||
$TargetMethod()$; |
||||
} |
||||
|
||||
int TargetMethod() { |
||||
return 3; |
||||
} |
||||
} |
||||
";
|
||||
MemberResolveResult result = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("A.TargetMethod", result.Member.FullName); |
||||
Assert.AreEqual("System.Int32", result.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidMethodCall() |
||||
{ |
||||
string program = @"class A {
|
||||
void Method(string b) { |
||||
$b.ThisMethodDoesNotExistOnString(b)$; |
||||
} |
||||
} |
||||
";
|
||||
UnknownMethodResolveResult result = Resolve<UnknownMethodResolveResult>(program); |
||||
Assert.AreEqual("ThisMethodDoesNotExistOnString", result.MemberName); |
||||
Assert.AreEqual("System.String", result.TargetType.FullName); |
||||
Assert.AreEqual(1, result.Parameters.Count); |
||||
Assert.AreEqual("b", result.Parameters[0].Name); |
||||
Assert.AreEqual("System.String", result.Parameters[0].Type.Resolve(context).ReflectionName); |
||||
|
||||
Assert.AreSame(SharedTypes.UnknownType, result.Type); |
||||
} |
||||
|
||||
[Test, Ignore("Inheritance not supported in parser")] |
||||
public void OverriddenMethodCall() |
||||
{ |
||||
string program = @"class A {
|
||||
void Method() { |
||||
$new B().GetRandomNumber()$; |
||||
} |
||||
|
||||
public abstract int GetRandomNumber(); |
||||
} |
||||
class B : A { |
||||
public override int GetRandomNumber() { |
||||
return 4; // chosen by fair dice roll.
|
||||
// guaranteed to be random
|
||||
} |
||||
} |
||||
";
|
||||
MemberResolveResult result = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("B.GetRandomNumber", result.Member.FullName); |
||||
} |
||||
|
||||
[Test, Ignore("Inheritance not supported in parser")] |
||||
public void OverriddenMethodCall2() |
||||
{ |
||||
string program = @"class A {
|
||||
void Method() { |
||||
$new B().GetRandomNumber(""x"", this)$; |
||||
} |
||||
|
||||
public abstract int GetRandomNumber(string a, A b); |
||||
} |
||||
class B : A { |
||||
public override int GetRandomNumber(string b, A a) { |
||||
return 4; // chosen by fair dice roll.
|
||||
// guaranteed to be random
|
||||
} |
||||
} |
||||
";
|
||||
MemberResolveResult result = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("B.GetRandomNumber", result.Member.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThisMethodCallTest() |
||||
{ |
||||
string program = @"class A {
|
||||
void Method() { |
||||
$this.TargetMethod()$; |
||||
} |
||||
|
||||
int TargetMethod() { |
||||
return 3; |
||||
} |
||||
} |
||||
";
|
||||
MemberResolveResult result = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("A.TargetMethod", result.Member.FullName); |
||||
Assert.AreEqual("System.Int32", result.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void VoidTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class A { |
||||
void TestMethod() { |
||||
$TestMethod()$; |
||||
} |
||||
} |
||||
";
|
||||
Assert.AreEqual("System.Void", Resolve(program).Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void EventCallTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class A { |
||||
void Method() { |
||||
$TestEvent(this, EventArgs.Empty)$; |
||||
} |
||||
|
||||
public event EventHandler TestEvent; |
||||
} |
||||
";
|
||||
Assert.AreEqual("System.Void", Resolve(program).Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void DelegateCallTest() |
||||
{ |
||||
string program = @"using System; using System.Reflection;
|
||||
class A { |
||||
void Method(ModuleResolveEventHandler eh) { |
||||
$eh(this, new ResolveEventArgs())$; |
||||
} |
||||
} |
||||
";
|
||||
Assert.AreEqual("System.Reflection.Module", Resolve(program).Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void DelegateReturnedFromMethodCallTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class A { |
||||
void Method() { |
||||
$GetHandler()(abc)$; |
||||
} |
||||
abstract Predicate<string> GetHandler(); |
||||
} |
||||
";
|
||||
Assert.AreEqual("System.Boolean", Resolve(program).Type.ReflectionName); |
||||
} |
||||
|
||||
/* TODO |
||||
[Test] |
||||
public void MethodGroupResolveTest() |
||||
{ |
||||
string program = @"class A {
|
||||
void Method() { |
||||
|
||||
} |
||||
|
||||
void TargetMethod(int a) { } |
||||
void TargetMethod<T>(T a) { } |
||||
} |
||||
";
|
||||
MethodGroupResolveResult result = Resolve<MethodGroupResolveResult>(program, "TargetMethod", 3); |
||||
Assert.AreEqual("TargetMethod", result.Name); |
||||
Assert.AreEqual(2, result.Methods.Count); |
||||
|
||||
result = Resolve<MethodGroupResolveResult>(program, "TargetMethod<string>", 3); |
||||
Assert.AreEqual("TargetMethod", result.Name); |
||||
Assert.AreEqual(1, result.Methods[0].Count); |
||||
Assert.AreEqual("System.String", result.GetMethodIfSingleOverload().Parameters[0].ReturnType.FullyQualifiedName); |
||||
} |
||||
*/ |
||||
|
||||
[Test] |
||||
public void TestOverloadingByRef() |
||||
{ |
||||
string program = @"using System;
|
||||
class Program { |
||||
public static void Main() { |
||||
int a = 42; |
||||
T(a); |
||||
T(ref a); |
||||
} |
||||
static void T(int x) {} |
||||
static void T(ref int y) {} |
||||
}";
|
||||
|
||||
MemberResolveResult mrr = Resolve<MemberResolveResult>(program, "T(a)"); |
||||
Assert.IsFalse(((IMethod)mrr.Member).Parameters[0].IsRef); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program, "T(ref a)"); |
||||
Assert.IsTrue(((IMethod)mrr.Member).Parameters[0].IsRef); |
||||
} |
||||
|
||||
[Test, Ignore("Inheritance not supported in parser")] |
||||
public void AddedOverload() |
||||
{ |
||||
string program = @"class BaseClass {
|
||||
static void Main(DerivedClass d) { |
||||
$d.Test(3)$; |
||||
} |
||||
public void Test(int a) { } |
||||
} |
||||
class DerivedClass : BaseClass { |
||||
public void Test(object a) { } |
||||
}";
|
||||
MemberResolveResult mrr = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName); |
||||
} |
||||
|
||||
[Test, Ignore("Inheritance not supported in parser")] |
||||
public void AddedNonApplicableOverload() |
||||
{ |
||||
string program = @"class BaseClass {
|
||||
static void Main(DerivedClass d) { |
||||
$d.Test(3)$; |
||||
} |
||||
public void Test(int a) { } |
||||
} |
||||
class DerivedClass : BaseClass { |
||||
public void Test(string a) { } |
||||
}";
|
||||
MemberResolveResult mrr = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("BaseClass.Test", mrr.Member.FullName); |
||||
|
||||
mrr = Resolve<MemberResolveResult>(program.Replace("(3)", "(\"3\")")); |
||||
Assert.AreEqual("DerivedClass.Test", mrr.Member.FullName); |
||||
} |
||||
|
||||
[Test, Ignore("Inheritance not supported in parser")] |
||||
public void OverrideShadowed() |
||||
{ |
||||
string program = @"using System;
|
||||
class BaseClass { |
||||
static void Main() { |
||||
$new DerivedClass().Test(3)$; |
||||
} |
||||
public virtual void Test(int a) { } |
||||
} |
||||
class MiddleClass : BaseClass { |
||||
public void Test(object a) { } |
||||
} |
||||
class DerivedClass : MiddleClass { |
||||
public override void Test(int a) { } |
||||
}";
|
||||
|
||||
MemberResolveResult mrr = Resolve<MemberResolveResult>(program); |
||||
Assert.AreEqual("MiddleClass.Test", mrr.Member.FullName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,278 @@
@@ -0,0 +1,278 @@
|
||||
// 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 NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
[TestFixture, Ignore("Expression Lambdas not supported by parser")] |
||||
public class LambdaTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void SimpleLambdaTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
Test(i => Console.WriteLine(i)); |
||||
} |
||||
public void Test(Action<int> ac) { ac(42); } |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program.Replace("(i)", "($i$)")); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
|
||||
lrr = Resolve<LocalResolveResult>(program.Replace("i =>", "$i$ =>")); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInConstructorTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
TestClass t = new TestClass(i => Console.WriteLine($i$)); |
||||
} |
||||
public TestClass(Action<int> ac) { ac(42); } |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInGenericConstructorTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
var t = new SomeClass<string>(i => Console.WriteLine($i$)); |
||||
} |
||||
} |
||||
class SomeClass<T> { |
||||
public SomeClass(Action<T> ac) { } |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
#region Lambda In Initializer
|
||||
[Test] |
||||
public void LambdaInCollectionInitializerTest1() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
Converter<int, string>[] arr = { |
||||
i => $i$.ToString() |
||||
}; |
||||
} |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInCollectionInitializerTest2() |
||||
{ |
||||
string program = @"using System; using System.Collections.Generic;
|
||||
class TestClass { |
||||
static void Main() { |
||||
a = new List<Converter<int, string>> { |
||||
i => $i$.ToString() |
||||
}; |
||||
} |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInCollectionInitializerTest3() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
a = new Converter<int, string>[] { |
||||
i => $i$.ToString() |
||||
}; |
||||
} |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInCollectionInitializerTest4() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
Converter<int, string>[] field = new Converter<int, string>[] { |
||||
i => $i$.ToString() |
||||
}; |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInCollectionInitializerTest5() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
Converter<int, string>[] field = { |
||||
i => $i$.ToString() |
||||
}; |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInObjectInitializerTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class X { |
||||
void SomeMethod() { |
||||
Helper h = new Helper { |
||||
F = i => $i$.ToString() |
||||
}; |
||||
} |
||||
} |
||||
class Helper { |
||||
public Converter<int, string> F; |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
#endregion
|
||||
|
||||
[Test] |
||||
public void LambdaExpressionInCastExpression() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static void Main(string[] args) { |
||||
var f = (Func<int, string>) ( i => $i$ ); |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaExpressionInReturnStatement() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static Converter<int, string> GetToString() { |
||||
return i => $i$.ToString(); |
||||
} |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program, "i"); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaExpressionInReturnStatementInStatementLambda() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static void SomeMethod() { |
||||
Func<Func<string, string>> getStringTransformer = () => { |
||||
return s => $s$.ToUpper(); |
||||
}; |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
public delegate R Func<R>(); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaExpressionInReturnStatementInAnonymousMethod() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static void SomeMethod() { |
||||
Func<Func<string, string>> getStringTransformer = delegate { |
||||
return s => $s$.ToUpper(); |
||||
}; |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
public delegate R Func<R>(); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void CurriedLambdaExpressionInCastExpression() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static void Main(string[] args) { |
||||
var f = (Func<char, Func<string, int>>) ( a => b => 0 ); |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program.Replace("a =>", "$a$ =>")); |
||||
Assert.AreEqual("System.Char", lrr.Type.ReflectionName); |
||||
|
||||
lrr = Resolve<LocalResolveResult>(program.Replace("b =>", "$b$ =>")); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaExpressionInVariableInitializer() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static void Main() { |
||||
Func<int, string> f = $i$ => i.ToString(); |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaExpressionInVariableAssignment() |
||||
{ |
||||
string program = @"using System;
|
||||
static class TestClass { |
||||
static void Main() { |
||||
Func<int, string> f; |
||||
f = $i$ => i.ToString(); |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LambdaInDelegateCall() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
Func<Func<int, string>, char> f; |
||||
f($i$ => i.ToString()); |
||||
} |
||||
public delegate R Func<T, R>(T arg); |
||||
}";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,136 @@
@@ -0,0 +1,136 @@
|
||||
// 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
[TestFixture, Ignore("LINQ not yet implemented")] |
||||
public class LinqTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void SimpleLinqTest() |
||||
{ |
||||
string program = @"using System; using System.Linq;
|
||||
class TestClass { |
||||
void Test(string[] input) { |
||||
var r = from e in input |
||||
where e.StartsWith(""/"") |
||||
select e.Trim(); |
||||
r.ToString(); |
||||
} |
||||
} |
||||
";
|
||||
LocalResolveResult lrr = Resolve<LocalResolveResult>(program.Replace("where e", "where $e$")); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
lrr = Resolve<LocalResolveResult>(program.Replace("select e", "select $e$")); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
lrr = Resolve<LocalResolveResult>(program.Replace("from e", "from $e$")); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
|
||||
lrr = Resolve<LocalResolveResult>(program.Replace("r.ToString", "$r$.ToString")); |
||||
Assert.AreEqual("System.Collections.Generic.IEnumerable", lrr.Type.FullName); |
||||
Assert.AreEqual("System.String", ((ParameterizedType)lrr.Type).TypeArguments[0].FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LinqGroupTest() |
||||
{ |
||||
string program = @"using System; using System.Linq;
|
||||
class TestClass { |
||||
void Test(string[] input) { |
||||
var r = from e in input |
||||
group e.ToUpper() by e.Length; |
||||
$r$.ToString(); |
||||
} |
||||
} |
||||
";
|
||||
LocalResolveResult lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Collections.Generic.IEnumerable", lrr.Type.FullName); |
||||
ParameterizedType rt = (ParameterizedType)((ParameterizedType)lrr.Type).TypeArguments[0]; |
||||
Assert.AreEqual("System.Linq.IGrouping", rt.FullName); |
||||
Assert.AreEqual("System.Int32", rt.TypeArguments[0].FullName); |
||||
Assert.AreEqual("System.String", rt.TypeArguments[1].FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LinqQueryableGroupTest() |
||||
{ |
||||
string program = @"using System; using System.Linq;
|
||||
class TestClass { |
||||
void Test(IQueryable<string> input) { |
||||
var r = from e in input |
||||
group e.ToUpper() by e.Length; |
||||
$r$.ToString(); |
||||
} |
||||
} |
||||
";
|
||||
LocalResolveResult lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Linq.IQueryable", lrr.Type.FullName); |
||||
ParameterizedType rt = (ParameterizedType)((ParameterizedType)lrr.Type).TypeArguments[0]; |
||||
Assert.AreEqual("System.Linq.IGrouping", rt.FullName); |
||||
Assert.AreEqual("System.Int32", rt.TypeArguments[0].FullName); |
||||
Assert.AreEqual("System.String", rt.TypeArguments[1].FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParenthesizedLinqTest() |
||||
{ |
||||
string program = @"using System; using System.Linq;
|
||||
class TestClass { |
||||
void Test(string[] input) { |
||||
$(from e in input select e.Length)$.ToArray(); |
||||
} |
||||
} |
||||
";
|
||||
ResolveResult rr = Resolve<ResolveResult>(program); |
||||
Assert.AreEqual("System.Collections.Generic.IEnumerable", rr.Type.FullName); |
||||
Assert.AreEqual("System.Int32", ((ParameterizedType)rr.Type).TypeArguments[0].FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LinqSelectReturnTypeTest() |
||||
{ |
||||
string program = @"using System;
|
||||
class TestClass { static void M() { |
||||
$(from a in new XYZ() select a.ToUpper())$.ToString(); |
||||
}} |
||||
class XYZ { |
||||
public int Select<U>(Func<string, U> f) { return 42; } |
||||
}";
|
||||
ResolveResult rr = Resolve<ResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", rr.Type.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LinqQueryContinuationTest() |
||||
{ |
||||
string program = @"using System; using System.Linq;
|
||||
class TestClass { |
||||
void Test(string[] input) { |
||||
var r = from x in input |
||||
select x.GetHashCode() into x |
||||
where x == 42 |
||||
select x * x; |
||||
r.ToString(); |
||||
} |
||||
} |
||||
";
|
||||
LocalResolveResult lrr = Resolve<LocalResolveResult>(program.Replace("from x", "from $x$")); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
lrr = Resolve<LocalResolveResult>(program.Replace("select x.G", "select $x$.G")); |
||||
Assert.AreEqual("System.String", lrr.Type.ReflectionName); |
||||
lrr = Resolve<LocalResolveResult>(program.Replace("into x", "into $x$")); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
lrr = Resolve<LocalResolveResult>(program.Replace("where x", "where $x$")); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
lrr = Resolve<LocalResolveResult>(program.Replace("select x * x", "select x * $x$")); |
||||
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); |
||||
|
||||
lrr = Resolve<LocalResolveResult>(program.Replace("r.ToString", "$r$.ToString")); |
||||
Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[System.Int32]]", lrr.Type.ReflectionName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// 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 ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
[TestFixture] |
||||
public class LocalTypeInferenceTests : ResolverTestBase |
||||
{ |
||||
[Test] |
||||
public void TypeInferenceTest() |
||||
{ |
||||
string program = @"class TestClass {
|
||||
static void Test() { |
||||
var a = 3; |
||||
$a$.ToString(); |
||||
} |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual("System.Int32", lrr.Type.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeInferenceCycleTest() |
||||
{ |
||||
string program = @"class TestClass {
|
||||
static void Test() { |
||||
var a = a; |
||||
$a$.ToString(); |
||||
} |
||||
} |
||||
";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreSame(SharedTypes.UnknownType, lrr.Type); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidAnonymousTypeDeclaration() |
||||
{ |
||||
// see SD-1393
|
||||
string program = @"using System;
|
||||
class TestClass { |
||||
static void Main() { |
||||
var contact = {id = 54321}; |
||||
$contact$.ToString(); |
||||
} }";
|
||||
var lrr = Resolve<LocalResolveResult>(program); |
||||
Assert.AreEqual(SharedTypes.UnknownType, lrr.Type); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue