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