Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Expressions
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv19112
Modified Files:
ExpressionEvaluatorTests.cs
Log Message:
fixed SPRNET-709
Index: ExpressionEvaluatorTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs,v
retrieving revision 1.64
retrieving revision 1.65
diff -C2 -d -r1.64 -r1.65
*** ExpressionEvaluatorTests.cs 23 Aug 2007 14:31:18 -0000 1.64
--- ExpressionEvaluatorTests.cs 23 Aug 2007 23:31:06 -0000 1.65
***************
*** 32,35 ****
--- 32,36 ----
using System.Threading;
using System.Web.Services;
+ using antlr.collections;
using NUnit.Framework;
using Spring.Collections;
***************
*** 1529,1536 ****
// function invoked within projection expression
! IList upperNames =
! (IList)
! ExpressionEvaluator.GetValue(ieee.Members, "(#upper = {|txt| $txt.ToUpper() }; !{ #upper(#this.Name) })",
! new Hashtable());
Assert.AreEqual("NIKOLA TESLA", upperNames[0]);
Assert.AreEqual("MIHAJLO PUPIN", upperNames[1]);
--- 1530,1535 ----
// function invoked within projection expression
! string expr = "(#upper = {|txt| $txt.ToUpper() }; !{ #upper(Name) })";
! IList upperNames = (IList)ExpressionEvaluator.GetValue(ieee.Members, expr, new Hashtable());
Assert.AreEqual("NIKOLA TESLA", upperNames[0]);
Assert.AreEqual("MIHAJLO PUPIN", upperNames[1]);
***************
*** 1540,1544 ****
Expression.RegisterFunction("sqrt", "{|n| Math.Sqrt($n)}", vars);
Expression.RegisterFunction("fact", "{|n| $n <= 1 ? 1 : $n * #fact($n-1)}", vars);
! string expr =
@"(
#delegate = {|f,n| $f($n) };
--- 1539,1543 ----
Expression.RegisterFunction("sqrt", "{|n| Math.Sqrt($n)}", vars);
Expression.RegisterFunction("fact", "{|n| $n <= 1 ? 1 : $n * #fact($n-1)}", vars);
! string expr2 =
@"(
#delegate = {|f,n| $f($n) };
***************
*** 1547,1551 ****
#result = { #delegate(#sqrt, 4), #d(#fact, 5), #delegate({|n| $n ^ 2 }, 5) }
)";
! IList results = (IList) ExpressionEvaluator.GetValue(null, expr, vars);
Assert.AreEqual(2, results[0]);
Assert.AreEqual(120, results[1]);
--- 1546,1550 ----
#result = { #delegate(#sqrt, 4), #d(#fact, 5), #delegate({|n| $n ^ 2 }, 5) }
)";
! IList results = (IList) ExpressionEvaluator.GetValue(null, expr2, vars);
Assert.AreEqual(2, results[0]);
Assert.AreEqual(120, results[1]);
***************
*** 2238,2265 ****
}
! #region TestSPRNET709 Classes
!
! private class TestSPRNET709Class
{
! public string SelectedValue = "100";
! }
!
! #endregion
! [Test]
! [Ignore("to clarify, recorded as SPRNET-709")]
! public void TestSPRNET709()
! {
! // this line fails with
! // Spring.Core.InvalidPropertyException :
! // 'roomtype_dropdownlist' node cannot be resolved for the specified context [System.Int64].
! IExpression exp = Expression.Parse("long.Parse(SelectedValue)");
! // this line works:
! // IExpression exp = Expression.Parse("long.Parse(#root.SelectedValue))");
! TestSPRNET709Class root = new TestSPRNET709Class();
! object result = exp.GetValue(root);
! Assert.AreSame( (long)100, result );
}
--- 2237,2261 ----
}
! [Test]
! public void TestMethodArgumentNodesResolveAgainstThisContext()
{
! IExpression exp;
! // case #root == #this - ToString() will be applied to #this
! exp = Expression.Parse("long.Parse(ToString())");
! object result = exp.GetValue(100);
! Assert.AreEqual((long)100, result);
! // case #root != #this in Projection - ToString() will be applied to #this
! exp = Expression.Parse("(#noop ={|val| $val}; !{#noop(ToString()) } )");
! result = exp.GetValue(new int[] { 100, 200 }, new Hashtable());
! Assert.AreEqual(new string[] { "100", "200" }, result);
! // case #root != #this in Selection - ToString() will be applied to #this
! exp = Expression.Parse("(#noop ={|val| $val}; ?{#noop(ToString()=='100')} )");
! result = exp.GetValue(new int[] { 100, 200 }, new Hashtable());
! IList list = new ArrayList();
! list.Add(100);
! Assert.AreEqual(list, result);
}
***************
*** 2555,2558 ****
--- 2551,2569 ----
#endregion
+ private static void DumpNode(AST rootNode, int level)
+ {
+ Trace.WriteLine(new string(' ', level) + rootNode.ToString());
+
+ int numberOfChildren = rootNode.getNumberOfChildren();
+ if (numberOfChildren > 0)
+ {
+ AST node = rootNode.getFirstChild();
+ while (node != null)
+ {
+ DumpNode(node, level + 2);
+ node = node.getNextSibling();
+ }
+ }
+ }
}
|