34 changed files with 2052 additions and 14 deletions
@ -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 CSharpGlobalReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpGlobalTypeDeclaration() |
||||||
|
{ |
||||||
|
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,56 @@ |
|||||||
|
// 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.Children.Count()); |
||||||
|
Assert.IsFalse(ame.HasParameterList); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AnonymousMethodAfterCast() |
||||||
|
{ |
||||||
|
CastExpression c = ParseUtilCSharp.ParseExpression<CastExpression>("(ThreadStart)delegate {}"); |
||||||
|
Assert.AreEqual("ThreadStart", c.CastTo); |
||||||
|
AnonymousMethodExpression ame = (AnonymousMethodExpression)c.Expression; |
||||||
|
Assert.AreEqual(0, ame.Parameters.Count()); |
||||||
|
Assert.AreEqual(0, ame.Body.Children.Count()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EmptyAnonymousMethod() |
||||||
|
{ |
||||||
|
AnonymousMethodExpression ame = Parse("delegate() {}"); |
||||||
|
Assert.AreEqual(0, ame.Parameters.Count()); |
||||||
|
Assert.AreEqual(0, ame.Body.Children.Count()); |
||||||
|
Assert.IsTrue(ame.HasParameterList); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
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.Children.Count()); |
||||||
|
Assert.IsTrue(ame.Body.Children.First() is ReturnStatement); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 CSharpArrayCreateExpressionTest1() |
||||||
|
{ |
||||||
|
/* |
||||||
|
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 CSharpImplicitlyTypedArrayCreateExpression() |
||||||
|
{ |
||||||
|
/* |
||||||
|
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 @@ |
|||||||
|
// 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 CSharpTestAssignmentExpression(string program, AssignmentOperatorType op) |
||||||
|
{ |
||||||
|
AssignmentExpression ae = ParseUtilCSharp.ParseExpression<AssignmentExpression>(program); |
||||||
|
|
||||||
|
Assert.AreEqual(op, ae.AssignmentOperatorType); |
||||||
|
|
||||||
|
Assert.IsTrue(ae.Left is IdentifierExpression); |
||||||
|
Assert.IsTrue(ae.Right is IdentifierExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpAssignTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a = b", AssignmentOperatorType.Assign); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpAddTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a += b", AssignmentOperatorType.Add); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpSubtractTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a -= b", AssignmentOperatorType.Subtract); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpMultiplyTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a *= b", AssignmentOperatorType.Multiply); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpDivideTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a /= b", AssignmentOperatorType.Divide); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpModulusTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a %= b", AssignmentOperatorType.Modulus); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpShiftLeftTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a <<= b", AssignmentOperatorType.ShiftLeft); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpShiftRightTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a >>= b", AssignmentOperatorType.ShiftRight); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpBitwiseAndTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a &= b", AssignmentOperatorType.BitwiseAnd); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpBitwiseOrTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a |= b", AssignmentOperatorType.BitwiseOr); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpExclusiveOrTest() |
||||||
|
{ |
||||||
|
CSharpTestAssignmentExpression("a ^= b", AssignmentOperatorType.ExclusiveOr); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 CSharpBaseReferenceExpressionTest1() |
||||||
|
{ |
||||||
|
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("base.myField"); |
||||||
|
Assert.IsTrue(fre.Target is BaseReferenceExpression); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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.BinaryOperatorType); |
||||||
|
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||||
|
boe = (BinaryOperatorExpression)boe.Right; |
||||||
|
Assert.AreEqual(strongOperatorType, boe.BinaryOperatorType); |
||||||
|
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.BinaryOperatorType); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
boe = (BinaryOperatorExpression)boe.Left; |
||||||
|
Assert.AreEqual(strongOperatorType, boe.BinaryOperatorType); |
||||||
|
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.BinaryOperatorType); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
boe = (BinaryOperatorExpression)boe.Left; |
||||||
|
Assert.AreEqual(secondOperatorType, boe.BinaryOperatorType); |
||||||
|
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.BinaryOperatorType); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
boe = (BinaryOperatorExpression)boe.Left; |
||||||
|
Assert.AreEqual(firstOperatorType, boe.BinaryOperatorType); |
||||||
|
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpOperatorPrecedenceTest() |
||||||
|
{ |
||||||
|
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.LogicalAnd, false); |
||||||
|
OperatorPrecedenceTest("&&", BinaryOperatorType.LogicalAnd, "||", BinaryOperatorType.LogicalOr, false); |
||||||
|
OperatorPrecedenceTest("||", BinaryOperatorType.LogicalOr, "??", BinaryOperatorType.NullCoalescing, false); |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
void CSharpTestBinaryOperatorExpressionTest(string program, BinaryOperatorType op) |
||||||
|
{ |
||||||
|
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program); |
||||||
|
Assert.AreEqual(op, boe.BinaryOperatorType); |
||||||
|
|
||||||
|
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpSubtractionLeftToRight() |
||||||
|
{ |
||||||
|
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("a - b - c"); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
Assert.IsTrue(boe.Left is BinaryOperatorExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpNullCoalescingRightToLeft() |
||||||
|
{ |
||||||
|
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("a ?? b ?? c"); |
||||||
|
Assert.IsTrue(boe.Left is IdentifierExpression); |
||||||
|
Assert.IsTrue(boe.Right is BinaryOperatorExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpBitwiseAndTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a & b", BinaryOperatorType.BitwiseAnd); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpBitwiseOrTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a | b", BinaryOperatorType.BitwiseOr); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpLogicalAndTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a && b", BinaryOperatorType.LogicalAnd); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpLogicalOrTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a || b", BinaryOperatorType.LogicalOr); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpExclusiveOrTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a ^ b", BinaryOperatorType.ExclusiveOr); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpGreaterThanTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a > b", BinaryOperatorType.GreaterThan); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpGreaterThanOrEqualTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a >= b", BinaryOperatorType.GreaterThanOrEqual); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpEqualityTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a == b", BinaryOperatorType.Equality); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpInEqualityTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a != b", BinaryOperatorType.InEquality); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpLessThanTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a < b", BinaryOperatorType.LessThan); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpLessThanOrEqualTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a <= b", BinaryOperatorType.LessThanOrEqual); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpAddTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a + b", BinaryOperatorType.Add); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpSubtractTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a - b", BinaryOperatorType.Subtract); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpMultiplyTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a * b", BinaryOperatorType.Multiply); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpDivideTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a / b", BinaryOperatorType.Divide); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpModulusTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a % b", BinaryOperatorType.Modulus); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpShiftLeftTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a << b", BinaryOperatorType.ShiftLeft); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpShiftRightTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a >> b", BinaryOperatorType.ShiftRight); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpNullCoalescingTest() |
||||||
|
{ |
||||||
|
CSharpTestBinaryOperatorExpressionTest("a ?? b", BinaryOperatorType.NullCoalescing); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpLessThanOrGreaterTest() |
||||||
|
{ |
||||||
|
const string expr = "i1 < 0 || i1 > (Count - 1)"; |
||||||
|
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(expr); |
||||||
|
Assert.AreEqual(BinaryOperatorType.LogicalOr, boe.BinaryOperatorType); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 CSharpSimpleCastExpression() |
||||||
|
{ |
||||||
|
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 CSharpArrayCastExpression() |
||||||
|
{ |
||||||
|
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 CSharpCastMemberReferenceOnParenthesizedExpression() |
||||||
|
{ |
||||||
|
// 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 CSharpTryCastParenthesizedExpression() |
||||||
|
{ |
||||||
|
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 CSharpCastNegation() |
||||||
|
{ |
||||||
|
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 CSharpSubtractionIsNotCast() |
||||||
|
{ |
||||||
|
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("(BigInt)-negativeValue"); |
||||||
|
Assert.IsTrue(boe.Left is ParenthesizedExpression); |
||||||
|
Assert.IsTrue(boe.Right is IdentifierExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpIntMaxValueToBigInt() |
||||||
|
{ |
||||||
|
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(BigInt)int.MaxValue"); |
||||||
|
Assert.AreEqual("BigInt", ce.CastTo.ToString()); |
||||||
|
Assert.IsTrue(ce.Expression is MemberReferenceExpression); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 CSharpCheckedExpressionTest() |
||||||
|
{ |
||||||
|
CheckedExpression ce = ParseUtilCSharp.ParseExpression<CheckedExpression>("checked(a)"); |
||||||
|
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpUncheckedExpressionTest() |
||||||
|
{ |
||||||
|
UncheckedExpression ce = ParseUtilCSharp.ParseExpression<UncheckedExpression>("unchecked(a)"); |
||||||
|
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 CSharpConditionalExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpConditionalIsExpressionTest() |
||||||
|
{ |
||||||
|
// (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] |
||||||
|
public void CSharpConditionalIsWithNullableExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpConditionalIsExpressionTest2() |
||||||
|
{ |
||||||
|
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 CSharpConditionalExpressionNegativeValue() |
||||||
|
{ |
||||||
|
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 CSharpConditionalIsWithNegativeValue() |
||||||
|
{ |
||||||
|
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 CSharpConditionalIsWithExplicitPositiveValue() |
||||||
|
{ |
||||||
|
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 CSharpRepeatedConditionalExpr() |
||||||
|
{ |
||||||
|
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 CSharpNestedConditionalExpr() |
||||||
|
{ |
||||||
|
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 @@ |
|||||||
|
// 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 CSharpSimpleDefaultValue() |
||||||
|
{ |
||||||
|
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(T)"); |
||||||
|
Assert.AreEqual("T", toe.TypeReference.Identifier.Name); |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
[Test] |
||||||
|
public void CSharpFullQualifiedDefaultValue() |
||||||
|
{ |
||||||
|
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 CSharpGenericDefaultValue() |
||||||
|
{ |
||||||
|
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 CSharpDefaultValueAsIntializer() |
||||||
|
{ |
||||||
|
// 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 CSharpDefaultValueInReturnStatement() |
||||||
|
{ |
||||||
|
ReturnStatement rs = ParseUtilCSharp.ParseStatement<ReturnStatement>("return default(T);"); |
||||||
|
DefaultValueExpression dve = (DefaultValueExpression)rs.Expression; |
||||||
|
Assert.AreEqual("T", dve.TypeReference.Type); |
||||||
|
}*/ |
||||||
|
} |
||||||
|
} |
||||||
@ -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.Name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestIdentifier() |
||||||
|
{ |
||||||
|
CheckIdentifier("a_Bc05", "a_Bc05"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestIdentifierStartingWithUnderscore() |
||||||
|
{ |
||||||
|
CheckIdentifier("_Bc05", "_Bc05"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestIdentifierStartingWithEscapeSequence() |
||||||
|
{ |
||||||
|
CheckIdentifier(@"\u006cexer", "lexer"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestIdentifierContainingEscapeSequence() |
||||||
|
{ |
||||||
|
CheckIdentifier(@"l\U00000065xer", "lexer"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestKeyWordAsIdentifier() |
||||||
|
{ |
||||||
|
CheckIdentifier("@int", "int"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestKeywordWithEscapeSequenceIsIdentifier() |
||||||
|
{ |
||||||
|
CheckIdentifier(@"i\u006et", "int"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestKeyWordAsIdentifierStartingWithUnderscore() |
||||||
|
{ |
||||||
|
CheckIdentifier("@_int", "_int"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test, Ignore] |
||||||
|
public void CSharpGenericMethodReference() |
||||||
|
{ |
||||||
|
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 CSharpGenericMethodReference2() |
||||||
|
{ |
||||||
|
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 @@ |
|||||||
|
// 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 CSharpIndexerExpressionTest() |
||||||
|
{ |
||||||
|
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 @@ |
|||||||
|
// 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 CSharpSimpleInvocationExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpGenericInvocationExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpGenericInvocation2ExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpAmbiguousGrammarGenericMethodCall() |
||||||
|
{ |
||||||
|
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 CSharpAmbiguousGrammarNotAGenericMethodCall() |
||||||
|
{ |
||||||
|
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 CSharpInvalidNestedInvocationExpressionTest() |
||||||
|
{ |
||||||
|
// 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,44 @@ |
|||||||
|
// 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 IsExpressionTests |
||||||
|
{ |
||||||
|
/* TODO |
||||||
|
[Test] |
||||||
|
public void GenericArrayIsExpression() |
||||||
|
{ |
||||||
|
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() |
||||||
|
{ |
||||||
|
TypeOfIsExpression ce = ParseUtilCSharp.ParseExpression<TypeOfIsExpression>("o is int?"); |
||||||
|
Assert.AreEqual("System.Nullable", ce.TypeReference.Type); |
||||||
|
Assert.AreEqual("System.Int32", ce.TypeReference.GenericTypes[0].Type); |
||||||
|
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NullableIsExpressionInBinaryOperatorExpression() |
||||||
|
{ |
||||||
|
BinaryOperatorExpression boe; |
||||||
|
boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("o is int? == true"); |
||||||
|
TypeOfIsExpression ce = (TypeOfIsExpression)boe.Left; |
||||||
|
Assert.AreEqual("System.Nullable", ce.TypeReference.Type); |
||||||
|
Assert.AreEqual("System.Int32", ce.TypeReference.GenericTypes[0].Type); |
||||||
|
Assert.IsTrue(ce.Expression is IdentifierExpression); |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
} |
||||||
@ -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 @@ |
|||||||
|
// 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 CSharpSimpleFieldReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpGenericFieldReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpFullNamespaceGenericFieldReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpGlobalFullNamespaceGenericFieldReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpNestedGenericFieldReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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 @@ |
|||||||
|
// 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 CSharpPrimitiveParenthesizedExpression() |
||||||
|
{ |
||||||
|
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 @@ |
|||||||
|
// 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 CSharpPointerReferenceExpressionTest() |
||||||
|
{ |
||||||
|
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,195 @@ |
|||||||
|
// 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 CSharpHexIntegerTest1() |
||||||
|
{ |
||||||
|
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.Identifier); |
||||||
|
|
||||||
|
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 CSharpDoubleTest1() |
||||||
|
{ |
||||||
|
CheckLiteral(".5e-06", .5e-06); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpCharTest1() |
||||||
|
{ |
||||||
|
CheckLiteral("'\\u0356'", '\u0356'); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IntMinValueTest() |
||||||
|
{ |
||||||
|
CheckLiteral("-2147483648", -2147483648); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IntMaxValueTest() |
||||||
|
{ |
||||||
|
CheckLiteral("2147483647", 2147483647); // int
|
||||||
|
CheckLiteral("2147483648", 2147483648); // uint
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void LongMinValueTest() |
||||||
|
{ |
||||||
|
CheckLiteral("-9223372036854775808", -9223372036854775808); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void LongMaxValueTest() |
||||||
|
{ |
||||||
|
CheckLiteral("9223372036854775807", 9223372036854775807); // long
|
||||||
|
CheckLiteral("9223372036854775808", 9223372036854775808); // ulong
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpStringTest1() |
||||||
|
{ |
||||||
|
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
|
||||||
|
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 @@ |
|||||||
|
// 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 @@ |
|||||||
|
// 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] |
||||||
|
public void CSharpSizeOfExpressionTest() |
||||||
|
{ |
||||||
|
SizeOfExpression soe = ParseUtilCSharp.ParseExpression<SizeOfExpression>("sizeof(MyType)"); |
||||||
|
Assert.AreEqual("MyType", soe.Type.Identifier.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 CSharpStackAllocExpressionTest() |
||||||
|
{ |
||||||
|
var sae = ParseUtilCSharp.ParseExpression<StackAllocExpression>("stackalloc int[100]"); |
||||||
|
throw new NotImplementedException(); // TODO: verify type + length expression
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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,90 @@ |
|||||||
|
// 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 |
||||||
|
{ |
||||||
|
/* TODO |
||||||
|
[Test] |
||||||
|
public void CSharpSimpleTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyNamespace.N1.MyType)"); |
||||||
|
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpGlobalTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(global::System.Console)"); |
||||||
|
Assert.AreEqual("System.Console", toe.TypeReference.Type); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpPrimitiveTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(int)"); |
||||||
|
Assert.AreEqual("System.Int32", toe.TypeReference.Type); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpVoidTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(void)"); |
||||||
|
Assert.AreEqual("System.Void", toe.TypeReference.Type); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpArrayTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType[])"); |
||||||
|
Assert.AreEqual("MyType", toe.TypeReference.Type); |
||||||
|
Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpGenericTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpNestedGenericTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpNullableTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
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 CSharpUnboundTypeOfExpressionTest() |
||||||
|
{ |
||||||
|
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,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, Ignore] |
||||||
|
public class TypeReferenceExpressionTests |
||||||
|
{ |
||||||
|
/* TODO |
||||||
|
[Test] |
||||||
|
public void GlobalTypeReferenceExpression() |
||||||
|
{ |
||||||
|
TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::System"); |
||||||
|
Assert.AreEqual("System", tr.TypeReference.Type); |
||||||
|
Assert.IsTrue(tr.TypeReference.IsGlobal); |
||||||
|
} |
||||||
|
|
||||||
|
[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 @@ |
|||||||
|
// 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 CSharpTestUnaryOperatorExpressionTest(string program, UnaryOperatorType op) |
||||||
|
{ |
||||||
|
UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression<UnaryOperatorExpression>(program); |
||||||
|
Assert.AreEqual(op, uoe.UnaryOperatorType); |
||||||
|
|
||||||
|
Assert.IsTrue(uoe.Expression is IdentifierExpression); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpNotTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("!a", UnaryOperatorType.Not); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpBitNotTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("~a", UnaryOperatorType.BitNot); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpMinusTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("-a", UnaryOperatorType.Minus); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpPlusTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("+a", UnaryOperatorType.Plus); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpIncrementTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("++a", UnaryOperatorType.Increment); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpDecrementTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("--a", UnaryOperatorType.Decrement); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpPostIncrementTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("a++", UnaryOperatorType.PostIncrement); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpPostDecrementTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("a--", UnaryOperatorType.PostDecrement); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpStarTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("*a", UnaryOperatorType.Dereference); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpBitWiseAndTest() |
||||||
|
{ |
||||||
|
CSharpTestUnaryOperatorExpressionTest("&a", UnaryOperatorType.AddressOf); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CSharpDereferenceAfterCast() |
||||||
|
{ |
||||||
|
UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression<UnaryOperatorExpression>("*((SomeType*) &w)"); |
||||||
|
Assert.AreEqual(UnaryOperatorType.Dereference, uoe.UnaryOperatorType); |
||||||
|
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.UnaryOperatorType); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
// 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 ParseStatement<T>(string stmt, bool expectErrors = false) where T : INode |
||||||
|
{ |
||||||
|
Assert.Ignore("ParseExpression not yet implemented"); |
||||||
|
|
||||||
|
CSharpParser parser = new CSharpParser(); |
||||||
|
BlockStatement parsedBlock = parser.ParseBlock(new StringReader(stmt)); |
||||||
|
|
||||||
|
// TODO check for parser errors
|
||||||
|
/*if (expectErrors) |
||||||
|
Assert.IsTrue(parser.Errors.ErrorOutput.Length > 0, "There were errors expected, but parser finished without errors."); |
||||||
|
else |
||||||
|
Assert.AreEqual("", parser.Errors.ErrorOutput);*/ |
||||||
|
|
||||||
|
Assert.AreEqual(1, parsedBlock.Children.Count()); |
||||||
|
INode statement = parsedBlock.Children.First(); |
||||||
|
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 : INode |
||||||
|
{ |
||||||
|
Assert.Ignore("ParseExpression not yet implemented"); |
||||||
|
|
||||||
|
CSharpParser parser = new CSharpParser(); |
||||||
|
INode parsedExpression = parser.ParseExpression(new StringReader(expr)); |
||||||
|
|
||||||
|
// TODO check for parser errors
|
||||||
|
/*if (expectErrors) |
||||||
|
Assert.IsTrue(parser.Errors.ErrorOutput.Length > 0, "There were errors expected, but parser finished without errors."); |
||||||
|
else |
||||||
|
Assert.AreEqual("", parser.Errors.ErrorOutput);*/ |
||||||
|
|
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue