Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for HashLink target: SpriterUtil.clearArray can break at runtime #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions spriter/definitions/Quadrilateral.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import flambe.math.Point;
typedef Point = phoenix.Vector;
#elseif heaps
typedef Point = h2d.col.Point;
#elseif test
typedef Point = test.Point;
#end

/**
Expand Down
4 changes: 0 additions & 4 deletions spriter/util/SpriterUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ class SpriterUtil
{
if (array.length > 0)
{
#if cpp
array.splice(0, array.length);//allocates in hxcpp but fastest
#else
untyped array.length = 0;
#end
}
}
}
16 changes: 16 additions & 0 deletions test-hl-haxe3.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Build and run tests
#
-cp .

# Turn off dead code elimination so that all sources are compiled
-dce no

# Specify that we should be using the test definition for Point, etc rather than a type from a specific library
-D test=true

-main test.TestMain
-hl bin/test.hl

# Run the tests (requires HashLink 1.1)
-cmd hl bin/test.hl
22 changes: 22 additions & 0 deletions test-hl-haxe4.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Build and run tests
#
-cp .

# Needed for haxe.unit on Haxe 4
-lib hx3compat

# Turn off dead code elimination so that all sources are compiled
-dce no

# Specify that we should be using the test definition for Point, etc rather than a type from a specific library
-D test=true

# Force Haxe to generate a specific version of the HashLink bytecode
-D hl_ver=1.9.0

-main test.TestMain
-hl bin/test.hl

# Run the tests
-cmd hl bin/test.hl
37 changes: 37 additions & 0 deletions test/BasicTestCase.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package test;

import haxe.unit.TestCase;
import spriter.engine.SpriterEngine;
import spriter.library.AbstractLibrary;
import spriter.util.SpriterUtil;
import spriter.definitions.SpatialInfo;

/**
* Test cases for very common scenarios.
*/
class BasicTestCase extends TestCase
{
public function new()
{
super();
}

public function testConstructEngine():Void
{
var lib:AbstractLibrary = null;
var x:SpriterEngine = new SpriterEngine("", null, lib);

// At least one assert is needed to make the unit test pass
assertTrue(true);
}

public function testSpriterUtilClearArray():Void
{
// Construct an array that results in an ArrayDyn in HashLink
var array:Array<Dynamic> = [1, 2];

// The original version set the length property, which fails when the underlying type is an ArrayDyn.
SpriterUtil.clearArray(array);
assertTrue(array.length == 0);
}
}
16 changes: 16 additions & 0 deletions test/Point.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test;

/**
* A point implementation to satisfy test code
*/
class Point
{
public var x:Float;
public var y:Float;

public function new(x:Float, y:Float)
{
this.x = x;
this.y = y;
}
}
13 changes: 13 additions & 0 deletions test/TestMain.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test;

import haxe.unit.TestRunner;

class TestMain
{
public static function main():Void
{
var runner = new TestRunner();
runner.add(new BasicTestCase());
runner.run();
}
}