mirror of https://github.com/icsharpcode/ILSpy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
95 lines
2.4 KiB
// 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); |
|
} |
|
} |
|
}
|
|
|