Author: olivier
Date: 2007-09-07 12:16:09 -0400 (Fri, 07 Sep 2007)
New Revision: 85487
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/ChangeLog
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/RowanGeneratorTest.cs
Log:
2007-09-07 Olivier Dufour <[EMAIL PROTECTED]>
* RowanGeneratorTest.cs: add a lot of unit test for rowan generator
about 50% is test now but still a lot to do in that way
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/ChangeLog
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/ChangeLog
2007-09-07 16:14:42 UTC (rev 85486)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/ChangeLog
2007-09-07 16:16:09 UTC (rev 85487)
@@ -1,3 +1,7 @@
+2007-09-07 Olivier Dufour <[EMAIL PROTECTED]>
+
+ * RowanGeneratorTest.cs: add a lot of unit test for rowan generator
about 50% is test now but still a lot to do in that way
+
2007-09-06 Olivier Dufour <[EMAIL PROTECTED]>
* TokenizerCategorizerTest.cs: finished full test of ReadToken
Modified:
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/RowanGeneratorTest.cs
===================================================================
---
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/RowanGeneratorTest.cs
2007-09-07 16:14:42 UTC (rev 85486)
+++
trunk/olive/class/Microsoft.JScript.Compiler/Test/Microsoft.JScript.Compiler/RowanGeneratorTest.cs
2007-09-07 16:16:09 UTC (rev 85487)
@@ -15,16 +15,18 @@
{
RowanGenerator gen;
IdentifierTable idtable;
+ IdentifierMappingTable maptable;
[SetUp]
public void init ()
{
idtable = new IdentifierTable ();
- gen = new RowanGenerator (new IdentifierMappingTable (),
+ maptable = new IdentifierMappingTable ();
+ gen = new RowanGenerator (maptable,
idtable.InsertIdentifier ("this"),
idtable.InsertIdentifier ("_"),
-
idtable.InsertIdentifier ("Arguments"),
-
idtable.InsertIdentifier ("Eval"));
+
idtable.InsertIdentifier ("arguments"),
+
idtable.InsertIdentifier ("eval"));
}
[Test]
@@ -36,13 +38,19 @@
[Test]
public void ConvertToObject ()
{
- MSIA.Expression val = new MSIA.ConstantExpression (0);
+ MSIA.ConstantExpression val = new
MSIA.ConstantExpression (0);
MSIA.Expression expr = gen.ConvertToObject (new
MSIA.ConstantExpression (0));
Assert.IsInstanceOfType (typeof
(MSIA.MethodCallExpression), expr, "#1");
MSIA.MethodCallExpression result =
((MSIA.MethodCallExpression)expr);
Assert.AreEqual (2, result.Arguments.Count, "#2");
Assert.IsInstanceOfType (typeof
(MSIA.CodeContextExpression), result.Arguments[0], "#3");
+ //Console.WriteLine (val.Value);
+ //Console.WriteLine
(((MSIA.ConstantExpression)result.Arguments[1]).Value);
+ //Console.WriteLine (val.ExpressionType);
+ //Console.WriteLine
(((MSIA.ConstantExpression)result.Arguments[1]).ExpressionType);
+ //Console.WriteLine (val.Span);
+ //Console.WriteLine
(((MSIA.ConstantExpression)result.Arguments[1]).Span);
//Assert.AreEqual (val, result.Arguments[1], "#4");
//bug here whereas is equal
Assert.IsNull (result.Instance, "#5");
Assert.AreEqual (typeof (MJR.Convert).GetMethod
("ToObject"), result.Method, "#6");
@@ -95,6 +103,7 @@
MSIA.Expression expr = call.Arguments[0];
}
+ #region statement
[Test]
public void GenerateBlockStatement ()
@@ -128,7 +137,215 @@
//((MSIA.BoundAssignment)exp).Operator;
}
+ #endregion
+
+ #region expression
+
[Test]
+ public void GenerateSyntaxError ()
+ {
+ MJCP.Expression input = new MJCP.Expression
(MJCP.Expression.Operation.SyntaxError, new TextSpan (0,0,0,0,0,0));
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ Assert.IsNull (gen.Generate (input), "#1");
+ }
+
+ [Test]
+ public void Generatethis ()
+ {
+ MJCP.Expression input = new MJCP.Expression ([EMAIL
PROTECTED], new TextSpan (0,0,0,0,0,0));
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.MethodCallExpression), exp, "#1");
+ //here strange so must detect that there is no parent
function
+ Assert.AreEqual ("GetGlobalObject",
((MSIA.MethodCallExpression)exp).Method.Name, "#2");
+ Assert.IsNull (
((MSIA.MethodCallExpression)exp).Instance, "#3");
+ Assert.AreEqual
(1,((MSIA.MethodCallExpression)exp).Arguments.Count, "#4");
+ Assert.IsInstanceOfType (typeof
(MSIA.CodeContextExpression), ((MSIA.MethodCallExpression)exp).Arguments[0],
"#5");
+
+ // 2cd pass with a parent function to have a real this
+ Parser parser = new Parser ("function foo () { var bar;
this.bar=5;}".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ input = parser.ParseExpression (ref comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ exp = gen.Generate (input);
+ IList<MSIA.Statement> statements =
((MSIA.BlockStatement)((MSIA.CodeBlockExpression)((MSIA.MethodCallExpression)((MSIA.BoundAssignment)exp).Value).Arguments[3]).Block.Body).Statements;
+ exp =
((MSIA.ExpressionStatement)statements[0]).Expression;//the this
+ Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment),
exp, "#6");
+ //((MSIA.BoundAssignment)exp).Reference.Name.
+ //maptable.
+
+ }
+
+ [Test]
+ public void GenerateFalse ()
+ {
+ Parser parser = new Parser ("false;".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ConstantExpression), exp, "#1");
+ Assert.AreEqual (false,
((MSIA.ConstantExpression)exp).Value, "#2");
+ }
+
+ [Test]
+ public void GenerateTrue()
+ {
+ Parser parser = new Parser ("true;".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ConstantExpression), exp, "#1");
+ Assert.AreEqual (true,
((MSIA.ConstantExpression)exp).Value, "#2");
+ }
+
+ //TODO : fix this test
+ [Test]
+ public void GenerateIdentifier ()
+ {
+ Parser parser = new Parser ("foo;".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof (MSIA.BoundExpression),
exp, "#1");
+ Assert.AreEqual (maptable.GetRowanID
(idtable.InsertIdentifier("foo")), ((MSIA.BoundExpression)exp).Reference.Name,
"#2");
+ }
+
+ [Test]
+ public void GenerateNumeric ()
+ {
+ Parser parser = new Parser ("5;".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ConstantExpression), exp, "#1");
+ Assert.AreEqual (5,
((MSIA.ConstantExpression)exp).Value, "#2");
+ }
+
+ [Test]
+ public void GenerateHex ()
+ {
+ Parser parser = new Parser ("0x15;".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ConstantExpression), exp, "#1");
+ Assert.AreEqual (21,
((MSIA.ConstantExpression)exp).Value, "#2");
+ }
+
+ [Test]
+ public void GenerateOctal ()
+ {
+ Parser parser = new Parser ("015;".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ConstantExpression), exp, "#1");
+ Assert.AreEqual (13,
((MSIA.ConstantExpression)exp).Value, "#2");
+ }
+
+ [Test]
+ public void GenerateString ()
+ {
+ Parser parser = new Parser ("\"bar\";".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ConstantExpression), exp, "#1");
+ Assert.AreEqual ("bar",
((MSIA.ConstantExpression)exp).Value, "#2");
+ }
+
+ [Test]
+ public void GenerateArray ()
+ {
+ Parser parser = new Parser ("[3, 2, 1];".ToCharArray
());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.MethodCallExpression), exp, "#1");
+ Assert.AreEqual (typeof
(MJR.JSCompilerHelpers).GetMethod ("ConstructArrayFromArrayLiteral"),
((MSIA.MethodCallExpression)exp).Method, "#2");
+ }
+
+ [Test]
+ public void GenerateParenthesized ()
+ {
+ Parser parser = new Parser ("(47);".ToCharArray ());
+ List<Comment> comms = new List<Comment> ();
+ MJCP.Expression input = parser.ParseExpression (ref
comms);
+ gen.SetGlobals (new MSIA.CodeBlock ("", new
List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
+ MSIA.Expression exp = gen.Generate (input);
+ Assert.IsInstanceOfType (typeof
(MSIA.ParenthesisExpression), exp, "#1");
+ }
+
+
+ /*
+ case MJCP.Expression.Operation.RegularExpressionLiteral :
+ case MJCP.Expression.Operation.Invocation :
+ case MJCP.Expression.Operation.Subscript :
+ case MJCP.Expression.Operation.Qualified :
+ case [EMAIL PROTECTED] :
+ case MJCP.Expression.Operation.Function :
+ case MJCP.Expression.Operation.delete :
+ case [EMAIL PROTECTED] :
+ case [EMAIL PROTECTED] :
+ case MJCP.Expression.Operation.PrefixPlusPlus :
+ case MJCP.Expression.Operation.PrefixMinusMinus :
+ case MJCP.Expression.Operation.PrefixPlus :
+ case MJCP.Expression.Operation.PrefixMinus :
+ case MJCP.Expression.Operation.Tilda :
+ case MJCP.Expression.Operation.Bang :
+ case MJCP.Expression.Operation.PostfixPlusPlus :
+ case MJCP.Expression.Operation.PostfixMinusMinus :
+ case MJCP.Expression.Operation.Comma :
+ case MJCP.Expression.Operation.Equal :
+ case MJCP.Expression.Operation.StarEqual :
+ case MJCP.Expression.Operation.DivideEqual :
+ case MJCP.Expression.Operation.PercentEqual :
+ case MJCP.Expression.Operation.PlusEqual :
+ case MJCP.Expression.Operation.MinusEqual :
+ case MJCP.Expression.Operation.LessLessEqual :
+ case MJCP.Expression.Operation.GreaterGreaterEqual :
+ case MJCP.Expression.Operation.GreaterGreaterGreaterEqual :
+ case MJCP.Expression.Operation.AmpersandEqual :
+ case MJCP.Expression.Operation.CircumflexEqual :
+ case MJCP.Expression.Operation.BarEqual :
+ case MJCP.Expression.Operation.BarBar :
+ case MJCP.Expression.Operation.AmpersandAmpersand :
+ case MJCP.Expression.Operation.Bar :
+ case MJCP.Expression.Operation.Circumflex :
+ case MJCP.Expression.Operation.Ampersand :
+ case MJCP.Expression.Operation.EqualEqual :
+ case MJCP.Expression.Operation.BangEqual :
+ case MJCP.Expression.Operation.EqualEqualEqual :
+ case MJCP.Expression.Operation.BangEqualEqual :
+ case MJCP.Expression.Operation.Less :
+ case MJCP.Expression.Operation.Greater :
+ case MJCP.Expression.Operation.LessEqual :
+ case MJCP.Expression.Operation.GreaterEqual :
+ case MJCP.Expression.Operation.instanceof :
+ case [EMAIL PROTECTED] :
+ case MJCP.Expression.Operation.LessLess :
+ case MJCP.Expression.Operation.GreaterGreater :
+ case MJCP.Expression.Operation.GreaterGreaterGreater :
+ case MJCP.Expression.Operation.Plus :
+ case MJCP.Expression.Operation.Minus :
+ case MJCP.Expression.Operation.Star :
+ case MJCP.Expression.Operation.Divide :
+ case MJCP.Expression.Operation.Percent :
+ case MJCP.Expression.Operation.Question :
+ case [EMAIL PROTECTED]:
+ */
+
+ #endregion
+
+ [Test]
public void SetGlobals ()
{
//gen.SetGlobals();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches