diff --git a/spriter/definitions/Quadrilateral.hx b/spriter/definitions/Quadrilateral.hx index 5dc12b6..2b229ef 100644 --- a/spriter/definitions/Quadrilateral.hx +++ b/spriter/definitions/Quadrilateral.hx @@ -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 /** diff --git a/spriter/util/SpriterUtil.hx b/spriter/util/SpriterUtil.hx index 4afecca..60158d9 100644 --- a/spriter/util/SpriterUtil.hx +++ b/spriter/util/SpriterUtil.hx @@ -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 } } } \ No newline at end of file diff --git a/test-hl-haxe3.hxml b/test-hl-haxe3.hxml new file mode 100644 index 0000000..23d626d --- /dev/null +++ b/test-hl-haxe3.hxml @@ -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 \ No newline at end of file diff --git a/test-hl-haxe4.hxml b/test-hl-haxe4.hxml new file mode 100644 index 0000000..ca0b0d2 --- /dev/null +++ b/test-hl-haxe4.hxml @@ -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 \ No newline at end of file diff --git a/test/BasicTestCase.hx b/test/BasicTestCase.hx new file mode 100644 index 0000000..ca9995b --- /dev/null +++ b/test/BasicTestCase.hx @@ -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 = [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); + } +} \ No newline at end of file diff --git a/test/Point.hx b/test/Point.hx new file mode 100644 index 0000000..728a4f7 --- /dev/null +++ b/test/Point.hx @@ -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; + } +} \ No newline at end of file diff --git a/test/TestMain.hx b/test/TestMain.hx new file mode 100644 index 0000000..1a0b7af --- /dev/null +++ b/test/TestMain.hx @@ -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(); + } +}