Update tests
[mono.git] / mcs / tests / eval-test.cs
1 using System;
2 using Mono.CSharp;
3
4 public class MyTest {
5         static void Run (string id, string stmt)
6         {
7                 try {
8                         Evaluator.Run (stmt);
9                 } catch {
10                         Console.WriteLine ("Failed on test {0}", id);
11                         throw;
12                 }
13         }
14
15         static void Evaluate (string id, string expr, object expected)
16         {
17                 try {
18                         object res = Evaluator.Evaluate (expr);
19                         if (res == null && expected == null)
20                                 return;
21
22                         if (!expected.Equals (res)){
23                                 Console.WriteLine ("Failed on test {2} Expecting {0}, got {1}", expected, res, id);
24                                 throw new Exception ();
25                         }
26                 } catch {
27                         Console.WriteLine ("Failed on test {0}", id);
28                         throw;
29                 }
30         }
31         
32         static void Main ()
33         {
34                 Run ("1",      "System.Console.WriteLine (100);");
35                 Run ("Length", "var a = new int [] {1,2,3}; var b = a.Length");
36                 
37                 Evaluate ("CompareString", "\"foo\" == \"bar\";", false);
38                 Evaluate ("CompareInt", "var a = 1; a+2;", 3);
39
40                 Evaluator.Run ("using System; using System.Linq;");
41                 Run ("LINQ-1", "var a = new int[]{1,2,3};\nfrom x in a select x;");
42                 Run ("LINQ-2", "var a = from f in System.IO.Directory.GetFiles (\"/tmp\") where f == \"passwd\" select f;");
43
44                 Evaluator.ReferenceAssembly (typeof (MyTest).Assembly);
45                 Evaluate ("assembly reference test", "typeof (MyTest) != null;", true);
46
47                 Run ("LINQ-3", "var first_scope = new int [] {1,2,3};");
48                 Run ("LINQ-4", "var second_scope = from x in first_scope select x;");
49         }
50         
51 }