5 static void Run (string id
, string stmt
)
7 if (!Evaluator
.Run (stmt
))
8 Console
.WriteLine ("Failed on test {0}", id
);
11 static void Evaluate (string id
, string expr
, object expected
)
14 object res
= Evaluator
.Evaluate (expr
);
15 if (res
== null && expected
== null)
18 if (!expected
.Equals (res
)){
19 Console
.WriteLine ("Failed on test {2} Expecting {0}, got {1}", expected
, res
, id
);
20 throw new Exception ();
23 Console
.WriteLine ("Failed on test {0}", id
);
30 Evaluator
.Init (new string [0]); //new string [] { "-v", "-v" });
32 // This fails because of the grammar issue with the pointer type
33 // Evaluate ("multiply", "1*2;", 2);
35 Run ("1", "System.Console.WriteLine (100);");
36 Run ("Length", "var a = new int [] {1,2,3}; var b = a.Length;");
38 Evaluate ("CompareString", "\"foo\" == \"bar\";", false);
39 Evaluate ("CompareInt", "var a = 1; a+2;", 3);
41 Evaluator
.Run ("using System; using System.Linq;");
42 Run ("LINQ-1", "var a = new int[]{1,2,3};\nfrom x in a select x;");
43 Run ("LINQ-2", "var a = from f in System.IO.Directory.GetFiles (\"/tmp\") where f == \"passwd\" select f;");
45 Evaluator
.ReferenceAssembly (typeof (MyTest
).Assembly
);
46 Evaluate ("assembly reference test", "typeof (MyTest) != null;", true);
48 Run ("LINQ-3", "var first_scope = new int [] {1,2,3};");
49 Run ("LINQ-4", "var second_scope = from x in first_scope select x;");
52 string [] res
= Evaluator
.GetCompletions ("ConsoleK", out prefix
);
53 if (res
[0] != "ey" || res
[1] != "eyInfo"){
54 Console
.WriteLine (res
[0]);
55 Console
.WriteLine (res
[1]);
56 throw new Exception ("Expected two completions ConsoleKey and ConsoleKeyInfo");
59 res
= Evaluator
.GetCompletions ("Converte", out prefix
);
61 throw new Exception ("Expected one completion for Conveter<");
64 res
= Evaluator
.GetCompletions ("Sys", out prefix
);
65 if (res
[0] != "tem"){
66 throw new Exception ("Expected at least a conversion for System");
69 res
= Evaluator
.GetCompletions ("System.Int3", out prefix
);
71 throw new Exception ("Expected completion to System.Int32");
74 res
= Evaluator
.GetCompletions ("new System.Text.StringBuilder () { Ca", out prefix
);
75 if (res
[0] != "pacity"){
76 throw new Exception ("Expected completion to Capacity");
79 res
= Evaluator
.GetCompletions ("new System.Text.StringBuilder () { ", out prefix
);
81 throw new Exception ("Epxected 4 completions (Capacity Chars Length MaxCapacity)");