2009-02-15 Jonathan Chambers <joncham@gmail.com>
[mcs.git] / tests / eval-test.cs
blob6b75bb837aabe96444d84fbdd4a133a579ef53bf
1 using System;
2 using Mono.CSharp;
4 public class MyTest {
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)
13 try {
14 object res = Evaluator.Evaluate (expr);
15 if (res == null && expected == null)
16 return;
18 if (!expected.Equals (res)){
19 Console.WriteLine ("Failed on test {2} Expecting {0}, got {1}", expected, res, id);
20 throw new Exception ();
22 } catch {
23 Console.WriteLine ("Failed on test {0}", id);
24 throw;
28 static void Main ()
30 Run ("1", "System.Console.WriteLine (100);");
31 Run ("Length", "var a = new int [] {1,2,3}; var b = a.Length;");
33 Evaluate ("CompareString", "\"foo\" == \"bar\";", false);
34 Evaluate ("CompareInt", "var a = 1; a+2;", 3);
36 Evaluator.Run ("using System; using System.Linq;");
37 Run ("LINQ-1", "var a = new int[]{1,2,3};\nfrom x in a select x;");
38 Run ("LINQ-2", "var a = from f in System.IO.Directory.GetFiles (\"/tmp\") where f == \"passwd\" select f;");
40 Evaluator.ReferenceAssembly (typeof (MyTest).Assembly);
41 Evaluate ("assembly reference test", "typeof (MyTest) != null;", true);
43 Run ("LINQ-3", "var first_scope = new int [] {1,2,3};");
44 Run ("LINQ-4", "var second_scope = from x in first_scope select x;");