BadScript 2
Loading...
Searching...
No Matches
BadInteropTests.cs
Go to the documentation of this file.
10
12
13public class BadInteropTests
14{
18 [Test]
19 public void Unwrap()
20 {
21 BadObject num = 10;
22 BadObject table = new BadTable();
23 Assert.Multiple(
24 () =>
25 {
26 Assert.That(num.CanUnwrap(), Is.True);
27 Assert.That(table.CanUnwrap(), Is.False);
28 Assert.That(num.Unwrap(), Is.EqualTo((decimal)10));
29 Assert.That(() => table.Unwrap(), Throws.InstanceOf<BadRuntimeException>());
30 }
31 );
32 }
33
37 [Test]
38 public void UnwrapGeneric()
39 {
40 BadObject num = 10;
41 BadObject table = new BadTable();
42 Version v = new Version();
43 BadObject nativeTest = new BadNative<Version>(v);
44 Assert.That(num.Unwrap<decimal>(), Is.EqualTo(10));
45 Assert.That(() => table.Unwrap<decimal>(), Throws.InstanceOf<BadRuntimeException>());
46 Assert.Multiple(
47 () =>
48 {
49 Assert.That(table.Unwrap<BadTable>(), Is.EqualTo(table));
50 Assert.That(nativeTest.Unwrap<Version>(), Is.EqualTo(v));
51 }
52 );
53 }
54
58 [Test]
59 public void GetExtensions()
60 {
62 provider.RegisterGlobal("Test", BadObject.Null);
63 Assert.That(provider.GetExtensionNames(), Contains.Item((BadObject)"Test"));
64 provider.RegisterObject<decimal>("Test1", _ => BadObject.Null);
65 Assert.That(provider.GetExtensionNames(10), Contains.Item((BadObject)"Test1"));
66 }
67
71 [Test]
72 public void Enumerable()
73 {
75 new BadInteropEnumerable(System.Linq.Enumerable.Range(0, 10).Select(x => (BadObject)x));
76 Assert.Multiple(
77 () =>
78 {
79 Assert.That(e.GetPrototype(), Is.InstanceOf<BadClassPrototype>());
80 Assert.That(e.HasProperty("GetEnumerator"), Is.True);
81 }
82 );
83 BadObject getEnumerator = e.GetProperty("GetEnumerator").Dereference();
84 Assert.That(getEnumerator, Is.InstanceOf<BadDynamicInteropFunction>());
85 BadObject enumerator = ((BadDynamicInteropFunction)getEnumerator)
87 .Last();
88 Assert.That(enumerator, Is.InstanceOf<BadInteropEnumerator>());
89 }
90
94 [Test]
95 public void Reflection()
96 {
97 Version v = new Version();
99 Assert.Multiple(
100 () =>
101 {
102 Assert.That(obj.GetPrototype(), Is.InstanceOf<BadClassPrototype>());
103 Assert.That(obj.HasProperty("Major"), Is.True);
104 Assert.That(obj.GetProperty("Major").Dereference(), Is.EqualTo((BadObject)0));
105 }
106 );
107 BadFunction toString = (BadFunction)obj.GetProperty("ToString").Dereference();
108 Assert.That(
109 toString
111 .Last(),
112 Is.EqualTo((BadObject)"0.0")
113 );
114 }
115}
The Execution Context. Every execution of a script needs a context the script is running in....
static BadExecutionContext Create(BadInteropExtensionProvider provider)
Creates a new Execution Context with an empty scope.
Implements an Interop Enumerable Object.
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
override bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Implements a simple wrapper for C# IEnumerators to be used in BS2.
void RegisterObject(Type t, string propName, BadObject obj)
Registers the specified extension for the specified type.
void RegisterGlobal(string propName, Func< BadObject, BadObject > func)
Registers the specified extension for all objects.
BadObject[] GetExtensionNames()
Returns all Global Extension names.
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
override bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject True
The True Value for the BadScript Language.
Definition BadObject.cs:33
static readonly BadObject False
The False Value for the BadScript Language.
Definition BadObject.cs:38
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Implements a function that can be called from the script.
Implements a Class Prototype for the BadScript Language.
void Unwrap()
Tests the Unwrap Functions of the Runtime.
void GetExtensions()
Tests the Extension Provider Functions.
void Enumerable()
Tests the Enumerable/Enumerator Interop.
void Reflection()
Tests the Reflection Subsystem.
void UnwrapGeneric()
Tests the Generic Unwrap Functions of the Runtime.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes for the BadScript2 Language.
Contains the Classes for Reflection Objects.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.