Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/hx/cppia/Cppia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4805,6 +4805,8 @@ struct DataVal : public CppiaExprWithValue
}
const char *getName() HXCPP_OVERRIDE { return "DataVal"; }

bool isBoolInt() HXCPP_OVERRIDE { return ExprTypeIsBool<T>::value; }

ExprType getType() HXCPP_OVERRIDE { return (ExprType)ExprTypeOf<T>::value; }

void runVoid(CppiaCtx *ctx) HXCPP_OVERRIDE { }
Expand Down
17 changes: 17 additions & 0 deletions test/cppia/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ class ClientFoo implements IFoo {
}
}

class ClientBoolConst {

public static function constToDynamic():String {
var d:Dynamic = true;

return Std.string(d);
}

public static function anyArrayWithConsts():Array<Any> {
return [true, false];
}

public static function anyArrayWithComparison(i:Int):Array<Any> {
return [i > 1];
}
}

class Client
{
public static var clientBool0 = true;
Expand Down
37 changes: 37 additions & 0 deletions test/cppia/cases/TestCommon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,43 @@ class TestCommon extends Test {
Assert.equals(2, Common.callbackSet, 'Bad cppia closure');
}

function callBoolConst(name:String, args:Array<Dynamic>):Dynamic {
final cls = Type.resolveClass('ClientBoolConst');

if (!Assert.notNull(cls, 'Unable to resolve ClientBoolConst')) {
return null;
}

return Reflect.callMethod(null, Reflect.field(cls, name), args);
}

@:depends(testStatus)
function testBoolConstToDynamic() {
Assert.equals('true', callBoolConst('constToDynamic', []),
'Bool constant boxed as a number');
}

@:depends(testStatus)
function testBoolConstInAnyArray() {
final arr:Array<Any> = callBoolConst('anyArrayWithConsts', []);

if (Assert.notNull(arr, 'No array returned')) {
Assert.isTrue(Std.isOfType(arr[0], Bool), 'Bool constant did not store as a Bool');
Assert.isTrue(Std.isOfType(arr[1], Bool), 'Bool constant did not store as a Bool');
Assert.equals('true', Std.string(arr[0]), 'Bool constant stored in an Any array as a number');
Assert.equals('false', Std.string(arr[1]), 'Bool constant stored in an Any array as a number');
}
}

@:depends(testStatus)
function testBoolComparisonInAnyArray() {
final arr:Array<Any> = callBoolConst('anyArrayWithComparison', [3]);

if (Assert.notNull(arr, 'No array returned')) {
Assert.equals('true', Std.string(arr[0]), 'Bool comparison stored in an Any array as a number');
}
}

@:depends(testStatus)
function testInterfaceCalling() {
final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []);
Expand Down