BadScript 2
Loading...
Searching...
No Matches
BadScript2.Tests.BadInteropTests Class Reference

Public Member Functions

void Unwrap ()
 Tests the Unwrap Functions of the Runtime.
 
void UnwrapGeneric ()
 Tests the Generic 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.
 

Detailed Description

Definition at line 13 of file BadInteropTests.cs.

Member Function Documentation

◆ Enumerable()

void BadScript2.Tests.BadInteropTests.Enumerable ( )

Tests the Enumerable/Enumerator Interop.

Definition at line 72 of file BadInteropTests.cs.

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 }
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.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements a Class Prototype for the BadScript Language.

◆ GetExtensions()

void BadScript2.Tests.BadInteropTests.GetExtensions ( )

Tests the Extension Provider Functions.

Definition at line 59 of file BadInteropTests.cs.

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 }
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.
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28

◆ Reflection()

void BadScript2.Tests.BadInteropTests.Reflection ( )

Tests the Reflection Subsystem.

Definition at line 95 of file BadInteropTests.cs.

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 }
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 function that can be called from the script.

◆ Unwrap()

void BadScript2.Tests.BadInteropTests.Unwrap ( )

Tests the Unwrap Functions of the Runtime.

Definition at line 19 of file BadInteropTests.cs.

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 }
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
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14

◆ UnwrapGeneric()

void BadScript2.Tests.BadInteropTests.UnwrapGeneric ( )

Tests the Generic Unwrap Functions of the Runtime.

Definition at line 38 of file BadInteropTests.cs.

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 }

The documentation for this class was generated from the following file: