add ISafeSerializationData
[mcs.git] / tests / gtest-repl-01.cs
blob1092456a52e0bed51ce2310b4a1da33bce90f82c
1 // Compiler options: -r:Mono.CSharp.dll
3 using System;
4 using Mono.CSharp;
6 public class MyTest {
7 static void Run (string id, string stmt)
9 if (!Evaluator.Run (stmt))
10 Console.WriteLine ("Failed on test {0}", id);
13 static void Evaluate (string id, string expr, object expected)
15 try {
16 object res = Evaluator.Evaluate (expr);
17 if (res == null && expected == null)
18 return;
20 if (!expected.Equals (res)){
21 Console.WriteLine ("Failed on test {2} Expecting {0}, got {1}", expected, res, id);
22 throw new Exception ();
24 } catch {
25 Console.WriteLine ("Failed on test {0}", id);
26 throw;
30 static void Main ()
32 Evaluator.Init (new string [0]); //new string [] { "-v", "-v" });
34 // This fails because of the grammar issue with the pointer type
35 // Evaluate ("multiply", "1*2;", 2);
37 Run ("1", "System.Console.WriteLine (100);");
38 Run ("Length", "var a = new int [] {1,2,3}; var b = a.Length;");
40 Evaluate ("CompareString", "\"foo\" == \"bar\";", false);
41 Evaluate ("CompareInt", "var a = 1; a+2;", 3);
43 Evaluator.Run ("using System; using System.Linq;");
44 Run ("LINQ-1", "var a = new int[]{1,2,3};\nfrom x in a select x;");
45 Run ("LINQ-2", "var a = from f in System.IO.Directory.GetFiles (\"/tmp\") where f == \"passwd\" select f;");
47 Evaluator.ReferenceAssembly (typeof (MyTest).Assembly);
48 Evaluate ("assembly reference test", "typeof (MyTest) != null;", true);
50 Run ("LINQ-3", "var first_scope = new int [] {1,2,3};");
51 Run ("LINQ-4", "var second_scope = from x in first_scope select x;");
53 string prefix = "";
54 string [] res = Evaluator.GetCompletions ("ConsoleK", out prefix);
55 if (res [0] != "ey" || res [1] != "eyInfo"){
56 Console.WriteLine (res [0]);
57 Console.WriteLine (res [1]);
58 throw new Exception ("Expected two completions ConsoleKey and ConsoleKeyInfo");
61 res = Evaluator.GetCompletions ("Converte", out prefix);
62 if (res [0] != "r"){
63 throw new Exception ("Expected one completion for Converter");
66 res = Evaluator.GetCompletions ("Sys", out prefix);
67 if (res [0] != "tem"){
68 throw new Exception ("Expected at least a conversion for System");
71 res = Evaluator.GetCompletions ("System.Int3", out prefix);
72 if (res [0] != "2"){
73 throw new Exception ("Expected completion to System.Int32");
76 res = Evaluator.GetCompletions ("new System.Text.StringBuilder () { Ca", out prefix);
77 if (res [0] != "pacity"){
78 throw new Exception ("Expected completion to Capacity");
81 res = Evaluator.GetCompletions ("new System.Text.StringBuilder () { ", out prefix);
82 if (res.Length != 3){
83 throw new Exception ("Epxected 4 completions (Capacity Chars Length MaxCapacity)");
86 // These should return "partial"
87 object eval_result;
88 bool result_set;
89 string sres = Evaluator.Evaluate ("1+", out eval_result, out result_set);
90 if (result_set)
91 throw new Exception ("No result should have been set");
92 if (sres != "1+")
93 throw new Exception ("The result should have been the input string, since we have a partial input");