SPRNET-467

This commit is contained in:
eeichinger
2009-07-27 16:03:21 +00:00
parent 5a2e7c6c26
commit 231e096fac
29 changed files with 1433 additions and 716 deletions

View File

@@ -64,11 +64,9 @@ namespace Spring.Expressions
[Test]
public void CanCreatePublicInstance()
{
ConstructorNode ctorNode = new ConstructorNode();
ctorNode.Text=typeof(PublicTestClass).FullName;
StringLiteralNode sNode = new StringLiteralNode();
sNode.Text = "theValue";
ctorNode.addChild(sNode);
ConstructorNode ctorNode = new ConstructorNode(typeof(PublicTestClass));
StringLiteralNode sNode = new StringLiteralNode("theValue");
ctorNode.AddArgument(sNode);
PublicTestClass instance = (PublicTestClass) ((IExpression)ctorNode).GetValue();
Assert.AreEqual( sNode.Text, instance._s );

View File

@@ -272,11 +272,18 @@ namespace Spring.Expressions
#endregion Serialization Tests
[Test]
public void TestBitwiseXOR()
{
object value = ExpressionEvaluator.GetValue(null, "'123' + 1");
Assert.AreEqual("1231", value);
}
[Test]
public void TestMixedAddition()
{
object value = ExpressionEvaluator.GetValue(null, "'123' + 1");
Console.WriteLine(value);
Assert.AreEqual("1231", value);
}
[Test(Description="SPRNET-944")]
@@ -942,6 +949,16 @@ namespace Spring.Expressions
Assert.IsTrue((bool)ExpressionEvaluator.GetValue(ieee, expression));
}
/// <summary>
/// Tests bitwise OR operator
/// </summary>
[Test]
public void TestBitwiseOrOperator()
{
Assert.AreEqual( 1 | 2, ExpressionEvaluator.GetValue(null, "1 or 2"));
Assert.AreEqual( 1 | -2, ExpressionEvaluator.GetValue(null, "1 or -2"));
}
/// <summary>
/// Tests logical AND operator
/// </summary>
@@ -956,6 +973,16 @@ namespace Spring.Expressions
Assert.IsTrue((bool)ExpressionEvaluator.GetValue(ieee, expression));
}
/// <summary>
/// Tests bitwise OR operator
/// </summary>
[Test]
public void TestBitwiseAndOperator()
{
Assert.AreEqual(1 & 3, ExpressionEvaluator.GetValue(null, "1 and 3"));
Assert.AreEqual(1 & -1, ExpressionEvaluator.GetValue(null, "1 and -1"));
}
/// <summary>
/// Tests logical NOT operator
/// </summary>
@@ -968,6 +995,18 @@ namespace Spring.Expressions
Assert.IsFalse((bool)ExpressionEvaluator.GetValue(ieee, expression));
}
/// <summary>
/// Tests bitwise OR operator
/// </summary>
[Test]
public void TestXorOperator()
{
Assert.AreEqual(1 ^ 3, ExpressionEvaluator.GetValue(null, "1 xor 3"));
Assert.AreEqual(1 ^ -1, ExpressionEvaluator.GetValue(null, "1 xor -1"));
Assert.AreEqual(true ^ false, ExpressionEvaluator.GetValue(null, "true xor false"));
Assert.AreEqual(true ^ true, ExpressionEvaluator.GetValue(null, "true xor true"));
}
/// <summary>
/// Tests logical operator presedance
/// </summary>

View File

@@ -0,0 +1,51 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpADDTests
{
[Test]
public void CanAddStrings()
{
OpADD add = new OpADD();
add.addChild( new StringLiteralNode("20"));
add.addChild( new StringLiteralNode("30"));
object result = add.GetValue(null, null);
Assert.AreEqual("2030", result);
}
[Test]
public void CanAddNumbers()
{
OpADD add = new OpADD();
add.addChild( new IntLiteralNode("20"));
add.addChild( new IntLiteralNode("30"));
object result = add.GetValue(null, null);
Assert.AreEqual(50, result);
}
}
}

View File

@@ -0,0 +1,38 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpANDTests
{
[Test]
public void AndsNumbers()
{
OpAND band = new OpAND(new IntLiteralNode("2"), new IntLiteralNode("3"));
Assert.AreEqual( 2 & 3, band.GetValue(null,null) );
}
}
}

View File

@@ -0,0 +1,46 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpORTests
{
[Test]
public void OrsNumbers()
{
OpOR bor = new OpOR(new IntLiteralNode("2"), new IntLiteralNode("3"));
Assert.AreEqual(2 | 3, bor.GetValue(null, null));
}
[Test]
public void OrsBooleans()
{
OpOR bor = new OpOR(new BooleanLiteralNode("false"), new BooleanLiteralNode("true"));
Assert.AreEqual(false || true , bor.GetValue(null, null));
}
}
}

View File

@@ -0,0 +1,40 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpXORTests
{
[Test]
public void XorsNumbers()
{
OpXOR bxor = new OpXOR(new IntLiteralNode("2"), new IntLiteralNode("3"));
Assert.AreEqual(2 ^ 3, bxor.GetValue(null, null));
bxor = new OpXOR(new BooleanLiteralNode("true"), new BooleanLiteralNode("false"));
Assert.AreEqual(true ^ false, bxor.GetValue(null, null));
}
}
}

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -285,6 +285,10 @@
</Compile>
<Compile Include="Expressions\FunctionNodeTests.cs" />
<Compile Include="Expressions\MethodNodeTests.cs" />
<Compile Include="Expressions\OpADDTests.cs" />
<Compile Include="Expressions\OpANDTests.cs" />
<Compile Include="Expressions\OpORTests.cs" />
<Compile Include="Expressions\OpXORTests.cs" />
<Compile Include="Expressions\Processors\ConversionProcessorTests.cs" />
<Compile Include="Expressions\Processors\OrderByProcessorTests.cs" />
<Compile Include="Expressions\PropertyOrFieldNodeTests.cs" />

View File

@@ -98,5 +98,119 @@ namespace Spring.Util
{
Assert.AreEqual(-10, NumberUtils.Negate(10));
}
[Test]
public void CoercesTypes()
{
object x = (int)1;
object y = (double)2;
NumberUtils.CoerceTypes(ref x, ref y);
Assert.AreEqual(typeof(double), x.GetType());
}
[Test]
public void Add()
{
Assert.AreEqual(5, NumberUtils.Add(2, 3));
try
{
NumberUtils.Add(2, "3");
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseNot()
{
Assert.AreEqual( ~((Byte)2), NumberUtils.BitwiseNot((Byte)2) );
Assert.AreEqual(~((SByte)2), NumberUtils.BitwiseNot((SByte)2));
Assert.AreEqual(~((Int16)2), NumberUtils.BitwiseNot((Int16)2));
Assert.AreEqual(~((UInt16)2), NumberUtils.BitwiseNot((UInt16)2));
Assert.AreEqual(~((Int32)2), NumberUtils.BitwiseNot((Int32)2));
Assert.AreEqual(~((UInt32)2), NumberUtils.BitwiseNot((UInt32)2));
Assert.AreEqual(~((Int64)2), NumberUtils.BitwiseNot((Int64)2));
Assert.AreEqual(~((UInt64)2), NumberUtils.BitwiseNot((UInt64)2));
Assert.AreEqual( false, NumberUtils.BitwiseNot(true) );
try
{
NumberUtils.BitwiseNot((double)2.0);
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseAnd()
{
Assert.AreEqual( ((Byte)2)&((Byte)3), NumberUtils.BitwiseAnd((Byte)2, (Byte)3));
Assert.AreEqual(((SByte)2) & ((SByte)3), NumberUtils.BitwiseAnd((SByte)2, (SByte)3));
Assert.AreEqual(((Int16)2) & ((Int16)3), NumberUtils.BitwiseAnd((Int16)2, (Int16)3));
Assert.AreEqual(((UInt16)2) & ((UInt16)3), NumberUtils.BitwiseAnd((UInt16)2, (UInt16)3));
Assert.AreEqual(((Int32)2) & ((Int32)3), NumberUtils.BitwiseAnd((Int32)2, (Int32)3));
Assert.AreEqual(((UInt32)2) & ((UInt32)3), NumberUtils.BitwiseAnd((UInt32)2, (UInt32)3));
Assert.AreEqual(((Int64)2) & ((Int64)3), NumberUtils.BitwiseAnd((Int64)2, (Int64)3));
Assert.AreEqual(((UInt64)2) & ((UInt64)3), NumberUtils.BitwiseAnd((UInt64)2, (UInt64)3));
Assert.AreEqual(((UInt64)2) & ((Byte)3), NumberUtils.BitwiseAnd((UInt64)2, (Byte)3));
Assert.AreEqual(true, NumberUtils.BitwiseAnd(true, true));
Assert.AreEqual( false, NumberUtils.BitwiseAnd(false, true) );
try
{
NumberUtils.BitwiseAnd((double)2.0, 3);
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseOr()
{
Assert.AreEqual( ((Byte)2) | ((Byte)3), NumberUtils.BitwiseOr((Byte)2, (Byte)3));
Assert.AreEqual(((SByte)2) | ((SByte)3), NumberUtils.BitwiseOr((SByte)2, (SByte)3));
Assert.AreEqual(((Int16)2) | ((Int16)3), NumberUtils.BitwiseOr((Int16)2, (Int16)3));
Assert.AreEqual(((UInt16)2) | ((UInt16)3), NumberUtils.BitwiseOr((UInt16)2, (UInt16)3));
Assert.AreEqual(((Int32)2) | ((Int32)3), NumberUtils.BitwiseOr((Int32)2, (Int32)3));
Assert.AreEqual(((UInt32)2) | ((UInt32)3), NumberUtils.BitwiseOr((UInt32)2, (UInt32)3));
Assert.AreEqual(((Int64)2) | ((Int64)3), NumberUtils.BitwiseOr((Int64)2, (Int64)3));
Assert.AreEqual(((UInt64)2) | ((UInt64)3), NumberUtils.BitwiseOr((UInt64)2, (UInt64)3));
Assert.AreEqual(((UInt64)2) | ((Byte)3), NumberUtils.BitwiseOr((UInt64)2, (Byte)3));
Assert.AreEqual(false, NumberUtils.BitwiseOr(false, false));
Assert.AreEqual(true, NumberUtils.BitwiseOr(false, true));
try
{
NumberUtils.BitwiseAnd((double)2.0, 3);
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseXor()
{
Assert.AreEqual( ((Byte)2) ^ ((Byte)3), NumberUtils.BitwiseXor((Byte)2, (Byte)3));
Assert.AreEqual(((SByte)2) ^ ((SByte)3), NumberUtils.BitwiseXor((SByte)2, (SByte)3));
Assert.AreEqual(((Int16)2) ^ ((Int16)3), NumberUtils.BitwiseXor((Int16)2, (Int16)3));
Assert.AreEqual(((UInt16)2) ^ ((UInt16)3), NumberUtils.BitwiseXor((UInt16)2, (UInt16)3));
Assert.AreEqual(((Int32)2) ^ ((Int32)3), NumberUtils.BitwiseXor((Int32)2, (Int32)3));
Assert.AreEqual(((UInt32)2) ^ ((UInt32)3), NumberUtils.BitwiseXor((UInt32)2, (UInt32)3));
Assert.AreEqual(((Int64)2) ^ ((Int64)3), NumberUtils.BitwiseXor((Int64)2, (Int64)3));
Assert.AreEqual(((UInt64)2) ^ ((UInt64)3), NumberUtils.BitwiseXor((UInt64)2, (UInt64)3));
Assert.AreEqual(((UInt64)2) ^ ((Byte)3), NumberUtils.BitwiseXor((UInt64)2, (Byte)3));
Assert.AreEqual(false, NumberUtils.BitwiseXor(false, false));
Assert.AreEqual(false, NumberUtils.BitwiseXor(true, true));
Assert.AreEqual(true, NumberUtils.BitwiseXor(false, true));
Assert.AreEqual(true, NumberUtils.BitwiseXor(true, false));
try
{
NumberUtils.BitwiseAnd((double)2.0, 3);
Assert.Fail();
}
catch(ArgumentException)
{}
}
}
}