Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Expressions
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4517/test/Spring/Spring.Core.Tests/Expressions
Modified Files:
ExpressionEvaluatorTests.cs MethodNodeTests.cs
Added Files:
FunctionNodeTests.cs
Log Message:
SPRNET-898
Index: MethodNodeTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Expressions/MethodNodeTests.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MethodNodeTests.cs 20 Mar 2008 09:07:52 -0000 1.1
--- MethodNodeTests.cs 20 Mar 2008 23:58:16 -0000 1.2
***************
*** 22,26 ****
--- 22,28 ----
using System;
+ using System.Collections;
using NUnit.Framework;
+ using Spring.Expressions.Processors;
#endregion
***************
*** 36,83 ****
public class MethodNodeTests
{
! #region StopWatch
!
! private class StopWatch
{
! private DateTime _startTime;
! private TimeSpan _elapsed;
!
! private class Stopper : IDisposable
! {
! private readonly StopWatch _owner;
! private readonly string _format;
! public Stopper(StopWatch owner, string format) { _owner = owner; _format = format; }
! public void Dispose() { _owner.Stop(_format); GC.SuppressFinalize(this); }
! }
!
! public IDisposable Start(string outputFormat)
{
! Stopper stopper = new Stopper(this, outputFormat);
! _startTime = DateTime.Now;
! return stopper;
}
! private void Stop(string outputFormat)
! {
! _elapsed = DateTime.Now.Subtract(_startTime);
! if (outputFormat != null)
! {
! Console.WriteLine(outputFormat, _elapsed);
! }
! }
! public DateTime StartTime
! {
! get { return _startTime; }
! }
! public TimeSpan Elapsed
! {
! get { return _elapsed; }
! }
}
- #endregion
-
[Test, Explicit]
public void PerformanceOfMethodEvaluationOnDifferentContextTypes()
--- 38,63 ----
public class MethodNodeTests
{
! private class MyTestCollectionProcessor : ICollectionProcessor
{
! public object Process(ICollection source, object[] args)
{
! return source;
}
+ }
! [Test]
! public void CallCustomCollectionProcessor()
! {
! Hashtable vars = new Hashtable();
! vars["myCollProc"] = new MyTestCollectionProcessor();
! MethodNode mn = new MethodNode();
! mn.Text = "myCollProc";
! IExpression exp = mn;
! int[] input = new int[] {1, 2, 3};
! Assert.AreSame(input, exp.GetValue(input, vars));
}
[Test, Explicit]
public void PerformanceOfMethodEvaluationOnDifferentContextTypes()
***************
*** 91,95 ****
PropertyOrFieldNode pn = new PropertyOrFieldNode();
pn.Text = "InvariantCulture";
!
Expression exp = new Expression();
--- 71,75 ----
PropertyOrFieldNode pn = new PropertyOrFieldNode();
pn.Text = "InvariantCulture";
!
Expression exp = new Expression();
***************
*** 111,115 ****
using (watch.Start("Duration: {0}"))
{
! for (int i = 0; i < runs; i++ )
{
mnExp.GetValue(0m, null);
--- 91,95 ----
using (watch.Start("Duration: {0}"))
{
! for (int i = 0; i < runs; i++)
{
mnExp.GetValue(0m, null);
***************
*** 117,120 ****
--- 97,144 ----
}
}
+
+ #region StopWatch
+
+ private class StopWatch
+ {
+ private DateTime _startTime;
+ private TimeSpan _elapsed;
+
+ private class Stopper : IDisposable
+ {
+ private readonly StopWatch _owner;
+ private readonly string _format;
+ public Stopper(StopWatch owner, string format) { _owner = owner; _format = format; }
+ public void Dispose() { _owner.Stop(_format); GC.SuppressFinalize(this); }
+ }
+
+ public IDisposable Start(string outputFormat)
+ {
+ Stopper stopper = new Stopper(this, outputFormat);
+ _startTime = DateTime.Now;
+ return stopper;
+ }
+
+ private void Stop(string outputFormat)
+ {
+ _elapsed = DateTime.Now.Subtract(_startTime);
+ if (outputFormat != null)
+ {
+ Console.WriteLine(outputFormat, _elapsed);
+ }
+ }
+
+ public DateTime StartTime
+ {
+ get { return _startTime; }
+ }
+
+ public TimeSpan Elapsed
+ {
+ get { return _elapsed; }
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
--- NEW FILE: FunctionNodeTests.cs ---
(This appears to be a binary file; contents omitted.)
Index: ExpressionEvaluatorTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs,v
retrieving revision 1.71
retrieving revision 1.72
diff -C2 -d -r1.71 -r1.72
*** ExpressionEvaluatorTests.cs 6 Mar 2008 20:20:37 -0000 1.71
--- ExpressionEvaluatorTests.cs 20 Mar 2008 23:58:16 -0000 1.72
***************
*** 1738,1741 ****
--- 1738,1743 ----
int[] arr = new int[] { 24, 8, 14, 6 };
Assert.AreEqual(new int[] { 6, 8, 14, 24 }, ExpressionEvaluator.GetValue(arr, "sort()"));
+ Assert.AreEqual(new int[] { 6, 8, 14, 24 }, ExpressionEvaluator.GetValue(arr, "sort(true)"));
+ Assert.AreEqual(new int[] { 24, 14, 8, 6 }, ExpressionEvaluator.GetValue(arr, "sort(false)"));
string[] arr2 = new string[] { "abc", "xyz", "stuv", "efg", "dcb" };
***************
*** 1754,1760 ****
}
! [Test]
! [ExpectedException(typeof(ArgumentException))]
! public void TestSortProcessorWithUnsupportedCollectionType()
{
Stack stack = new Stack(new int[] { 24, 8, 14, 6 });
--- 1756,1761 ----
}
! [Test(Description="sort supports any ICollection containing elements of uniform type")]
! public void TestSortProcessorWithSimpleICollectionType()
{
Stack stack = new Stack(new int[] { 24, 8, 14, 6 });
***************
*** 1803,1806 ****
--- 1804,1827 ----
}
+ [Test]
+ public void TestConversionProcessor()
+ {
+ object[] arr = new object[] { "0", 1, 1.1m, "1.1", 1.1f };
+ decimal[] result = (decimal[]) ExpressionEvaluator.GetValue(arr, "convert(decimal)");
+ Assert.AreEqual( 0.0m, result[0] );
+ Assert.AreEqual(1.0m, result[1]);
+ Assert.AreEqual(1.1m, result[2]);
+ Assert.AreEqual(1.1m, result[3]);
+ Assert.AreEqual(1.1m, result[4]);
+ }
+
+ [Test]
+ public void TestReverseProcessor()
+ {
+ object[] arr = new object[] { "0", 1, 2.1m, "3", 4.1f };
+ object[] result = new ArrayList( (ICollection) ExpressionEvaluator.GetValue(arr, "reverse()") ).ToArray();
+ Assert.AreEqual(new object[] { 4.1f, "3", 2.1m, 1, "0" }, result);
+ }
+
#endregion
|