Testing class instance dot access
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package hank;
|
||||
|
||||
using Reflect;
|
||||
import Type;
|
||||
|
||||
import hscript.Parser;
|
||||
import hscript.Interp;
|
||||
@@ -28,18 +29,20 @@ class HInterface {
|
||||
if (variables.exists(name)) {
|
||||
return variables[name];
|
||||
} else {
|
||||
trace(Type.typeof(container)) ;
|
||||
trace(Type.typeof(container).getName()) ;
|
||||
if (Type.typeof(container).getName() == 'StoryNode') {
|
||||
var node: StoryNode = cast(container, StoryNode);
|
||||
switch (node.resolve(name)) {
|
||||
case Some(node):
|
||||
return viewCounts[node];
|
||||
case None:
|
||||
throw 'Cannot resolve ${name}';
|
||||
}
|
||||
} else {
|
||||
return container.field(name);
|
||||
// If the variable is a StoryNode, don't return the node, return its viewCount
|
||||
var type = Type.typeof(container);
|
||||
switch (type) {
|
||||
case TClass(c):
|
||||
trace(c);
|
||||
var node: StoryNode = cast(container, StoryNode);
|
||||
switch (node.resolve(name)) {
|
||||
case Some(node):
|
||||
return viewCounts[node];
|
||||
case None:
|
||||
throw 'Cannot resolve ${name}';
|
||||
}
|
||||
default:
|
||||
return container.field(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@ import hank.HInterface;
|
||||
import hank.StoryTree;
|
||||
import hank.Parser;
|
||||
|
||||
class TestObject {
|
||||
public var i: Int;
|
||||
public var o: TestObject;
|
||||
public function new(i: Int, o: TestObject) {
|
||||
this.i = i;
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class HInterfaceTest extends utest.Test {
|
||||
|
||||
var hInterface: HInterface;
|
||||
@@ -18,6 +28,7 @@ class HInterfaceTest extends utest.Test {
|
||||
var viewCounts = storyTree.createViewCounts();
|
||||
|
||||
viewCounts[storyTree.resolve("start").unwrap()] = 5;
|
||||
viewCounts[storyTree.resolve("start").unwrap().resolve("one").unwrap()] = 2;
|
||||
|
||||
hInterface = new HInterface(storyTree, viewCounts);
|
||||
}
|
||||
@@ -28,6 +39,21 @@ class HInterfaceTest extends utest.Test {
|
||||
|
||||
function testViewCount() {
|
||||
assertExpr('start', 5);
|
||||
//assertExpr('start.one', 5);
|
||||
}
|
||||
|
||||
function testClassInstanceDotAccess() {
|
||||
hInterface.addVariable('test1', new TestObject(0, new TestObject(1, new TestObject(2, null))));
|
||||
assertExpr('test1.i', 0);
|
||||
assertExpr('test1.o.i', 1);
|
||||
assertExpr('test1.o.o.i', 2);
|
||||
}
|
||||
|
||||
function testAnonymousDotAccess() {
|
||||
hInterface.runEmbeddedHaxe('var obj = {x: 5, y: "hey", z: { b: 9}};');
|
||||
assertExpr('obj.x', 5);
|
||||
assertExpr('obj.y', 'hey');
|
||||
assertExpr('obj.z.b', 9);
|
||||
}
|
||||
|
||||
public function testVarDeclaration() {
|
||||
|
||||
Reference in New Issue
Block a user