Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,44 @@
//
// BuildinCommandsTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class BuildinCommandsTest : EvaluatorFixture
{
[Test]
public void ShowUsing ()
{
// Evaluator.Run ("ShowUsing();");
}
}
}

View File

@ -0,0 +1,78 @@
//
// Completion.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class Completion : EvaluatorFixture
{
[Test]
public void SimpleSystemNamespace ()
{
Evaluator.Run ("using System;");
string prefix;
string[] res;
res = Evaluator.GetCompletions ("ConsoleK", out prefix);
Assert.AreEqual (new string[] { "ey", "eyInfo" }, res, "#1");
res = Evaluator.GetCompletions ("Converte", out prefix);
Assert.AreEqual (new string[] { "r" }, res, "#2");
res = Evaluator.GetCompletions ("Sys", out prefix);
Assert.AreEqual (new string[] { "tem", "temException" }, res, "#3");
res = Evaluator.GetCompletions ("System.Int3", out prefix);
Assert.AreEqual (new string[] { "2" }, res, "#4");
}
[Test]
public void Initializers ()
{
string prefix;
string[] res;
res = Evaluator.GetCompletions ("new System.Text.StringBuilder () { Ca", out prefix);
Assert.AreEqual (new string[] { "pacity" }, res, "#1");
res = Evaluator.GetCompletions ("new System.Text.StringBuilder () { ", out prefix);
Assert.AreEqual (new string[] { "Capacity", "Length", "MaxCapacity" }, res, "#2");
}
[Test]
public void StringLocalVariable ()
{
string prefix;
var res = Evaluator.GetCompletions ("string a.", out prefix);
Assert.IsNull (res);
}
}
}

View File

@ -0,0 +1,53 @@
//
// EvaluatorFixture.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
public class EvaluatorFixture
{
Evaluator evaluator;
protected CompilerSettings settings;
[SetUp]
public void Setup ()
{
settings = new CompilerSettings ();
var ctx = new CompilerContext (settings, new AssertReportPrinter ());
evaluator = new Evaluator (ctx);
}
public Evaluator Evaluator {
get {
return evaluator;
}
}
}
}

View File

@ -0,0 +1,44 @@
//
// EvaluatorTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using Mono.CSharp;
namespace MonoTests.EvaluatorTest
{
public class EvaluatorTest : EvaluatorFixture
{
[Test]
public void SameSettings ()
{
var ctx = new CompilerContext (settings, new AssertReportPrinter ());
var evaluator2 = new Evaluator (ctx);
evaluator2.Run ("int i = 0;");
}
}
}

View File

@ -0,0 +1,170 @@
//
// ExpressionsTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class ExpressionsTest : EvaluatorFixture
{
[Test]
public void StatementExpression_1 ()
{
Evaluator.Run ("System.Console.WriteLine (100)");
}
[Test]
public void StatementExpression_2 ()
{
Evaluator.Run ("var a = new int [] {1,2,3}; var b = a.Length;");
}
[Test]
public void AnonymousType ()
{
Evaluator.Run ("var foo = new { Bar = \"baz\" };");
}
[Test]
public void Simple ()
{
object res;
res = Evaluator.Evaluate ("\"foo\" == \"bar\";");
Assert.AreEqual (false, res, "CompareString");
res = Evaluator.Evaluate ("var a = 1; a+2;");
Assert.AreEqual (3, res, "CompareInt");
res = Evaluator.Evaluate ("2 * 4;");
Assert.AreEqual (8, res, "Multiply");
}
[Test]
public void UsingAfterError ()
{
try {
Evaluator.Evaluate ("File.OpenRead (\"/etc/passwd\");");
Assert.Fail ("#1");
} catch {
}
Evaluator.Run ("using System.IO;");
Evaluator.Evaluate ("File.Exists (\"/etc/passwd\");");
}
[Test]
public void WithTypeBuilders ()
{
object res;
Evaluator.Run ("var a = new { A = 1 };");
res = Evaluator.Evaluate ("a.ToString ();");
Assert.AreEqual ("{ A = 1 }", res, "#1");
}
[Test]
public void LinqExpressions ()
{
Evaluator.Run ("using System; using System.Linq;");
Evaluator.Run ("var a = new int[]{1,2,3};");
object res = Evaluator.Evaluate ("from x in a select x + 1;");
CollectionAssert.AreEqual (new int[] { 2, 3, 4 }, ((IEnumerable<int>) res).ToArray ());
}
[Test]
public void LinqExpressionStatements ()
{
Evaluator.Run ("using System; using System.Linq;");
Evaluator.Run ("var first_scope = new int [] {1,2,3};");
Evaluator.Run ("var second_scope = from x in first_scope select x;");
}
[Test]
public void ReferenceLoading ()
{
Evaluator.ReferenceAssembly (typeof (ExpressionsTest).Assembly);
object res = Evaluator.Evaluate ("typeof (MonoTests.EvaluatorTest.ExpressionsTest) != null;");
Assert.AreEqual (true, res, "#1");
}
[Test]
public void PartialExpression ()
{
object eval_result;
bool result_set;
string sres = Evaluator.Evaluate ("1+", out eval_result, out result_set);
Assert.IsFalse (result_set, "No result should have been set");
Assert.AreEqual ("1+", sres, "The result should have been the input string, since we have a partial input");
}
[Test]
public void GotoWithUnreachableStatement ()
{
Evaluator.Run ("using System;");
string code = "var x = new Action(() => {" +
"Console.WriteLine(\"beforeGoto\");" +
"goto L;" +
"L:" +
"Console.WriteLine(\"afterGoto\");" +
"});";
Assert.IsTrue (Evaluator.Run (code), "#1");
Assert.IsTrue (Evaluator.Run ("x();"), "#2");
}
#if NET_4_0
[Test]
public void DynamicStatement ()
{
Evaluator.Run ("dynamic d = 1;");
Evaluator.Run ("d = 'a';");
Evaluator.Run ("d.GetType ();");
}
#endif
#if NET_4_5
[Test]
public void AwaitExpression ()
{
Evaluator.WaitOnTask = true;
var res = Evaluator.Evaluate("var res = await System.Threading.Tasks.Task.FromResult (1) + await System.Threading.Tasks.Task.FromResult (2);");
res = Evaluator.Evaluate ("res;");
Assert.AreEqual (3, res, "#1");
}
#endif
}
}

View File

@ -0,0 +1,110 @@
//
// TypesTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using Mono.CSharp;
using System.Collections;
namespace MonoTests.EvaluatorTest
{
[TestFixture]
public class TypesTest : EvaluatorFixture
{
[Test]
public void SimpleTypeStaticMethod ()
{
object res;
Evaluator.Run ("class Y { public static int Test () { return 5; }}");
res = Evaluator.Evaluate ("Y.Test ();");
Assert.AreEqual (5, res, "#1");
}
[Test]
public void SameTypeNameRedefinition ()
{
Evaluator.Run ("class X { }");
Evaluator.Run ("class X { public static void Foo () { throw new System.ApplicationException (); } }");
Evaluator.Run ("class X {}");
Evaluator.Run ("class X { public static string Foo () { return \"Test\"; } }");
object res = Evaluator.Evaluate ("X.Foo ();");
Assert.AreEqual ("Test", res, "#1");
Evaluator.Run ("class X { public static int Foo () { return 5; } }");
res = Evaluator.Evaluate ("X.Foo ();");
Assert.AreEqual (5, res, "#2");
}
[Test]
public void SimpleConstructor ()
{
Evaluator.Run ("class Y2 { public int Value; public Y2 (){ Value = 99; } }");
Evaluator.Run ("var a = new Y2 ();");
object res = Evaluator.Evaluate ("a.Value;");
Assert.AreEqual (99, res);
}
[Test]
public void TypeOfType ()
{
Evaluator.Run ("struct Z { }");
object res = Evaluator.Evaluate ("typeof (Z);");
Assert.AreEqual ("Z", res.ToString ());
}
[Test]
public void UsingAfterType ()
{
Evaluator.Run ("struct Z { }");
Evaluator.Run ("using System;");
Evaluator.Run ("struct Z { }");
}
[Test]
public void MoreThanOneType ()
{
Evaluator.Run ("public class D { int x; public int X { get { return x; } set { x = value;} } };");
Evaluator.Run ("public class C { public int Speed{get;set;}};");
}
[Test]
public void StructType ()
{
Evaluator.Run ("class C { }");
Evaluator.Run ("struct B { public string foo; public int bar; }");
Evaluator.Run ("B aStruct = new B { foo = \"foo\", bar = 1 };");
}
[Test]
public void NestedType ()
{
Evaluator.Run ("class A { class B { } }");
Evaluator.Run ("var x = new A ();");
}
}
}