diff --git a/.gitignore b/.gitignore index 2501489..a91478f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ **/bin +build +report diff --git a/.munit b/.munit new file mode 100644 index 0000000..aaa70c9 --- /dev/null +++ b/.munit @@ -0,0 +1,6 @@ +version=2.1.2 +src=test +bin=build +report=report +hxml=test.hxml +classPaths=src diff --git a/test.hxml b/test.hxml new file mode 100644 index 0000000..476546b --- /dev/null +++ b/test.hxml @@ -0,0 +1,31 @@ +## Flash 9+ +#-main TestMain +#-lib munit +#-lib hamcrest +#-cp src + +#-cp test +#-swf-version 11 +#-swf build/as3_test.swf + +#--next + +## JavaScript +#-main TestMain +#-lib munit +#-lib hamcrest +#-cp src + +#-cp test +#-js build/js_test.js + +#--next + +## Neko +-main TestMain +-lib munit +-lib hamcrest +-cp src + +-cp test +-neko build/neko_test.n diff --git a/test/TestMain.hx b/test/TestMain.hx new file mode 100644 index 0000000..f74fb69 --- /dev/null +++ b/test/TestMain.hx @@ -0,0 +1,81 @@ +import massive.munit.client.PrintClient; +import massive.munit.client.RichPrintClient; +import massive.munit.client.HTTPClient; +import massive.munit.client.JUnitReportClient; +import massive.munit.client.SummaryReportClient; +import massive.munit.TestRunner; + +#if js +import js.Lib; +#end + +/** + * Auto generated Test Application. + * Refer to munit command line tool for more information (haxelib run munit) + */ +class TestMain +{ + static function main(){ new TestMain(); } + + public function new() + { + var suites = new Array>(); + suites.push(TestSuite); + + #if MCOVER + var client = new mcover.coverage.munit.client.MCoverPrintClient(); + var httpClient = new HTTPClient(new mcover.coverage.munit.client.MCoverSummaryReportClient()); + #else + var client = new RichPrintClient(); + var httpClient = new HTTPClient(new SummaryReportClient()); + #end + + var runner:TestRunner = new TestRunner(client); + runner.addResultClient(httpClient); + //runner.addResultClient(new HTTPClient(new JUnitReportClient())); + + runner.completionHandler = completionHandler; + + #if js + var seconds = 0; // edit here to add some startup delay + function delayStartup() + { + if (seconds > 0) { + seconds--; + js.Browser.document.getElementById("munit").innerHTML = + "Tests will start in " + seconds + "s..."; + haxe.Timer.delay(delayStartup, 1000); + } + else { + js.Browser.document.getElementById("munit").innerHTML = ""; + runner.run(suites); + } + } + delayStartup(); + #else + runner.run(suites); + #end + } + + /* + updates the background color and closes the current browser + for flash and html targets (useful for continous integration servers) + */ + function completionHandler(successful:Bool):Void + { + try + { + #if flash + flash.external.ExternalInterface.call("testResult", successful); + #elseif js + js.Lib.eval("testResult(" + successful + ");"); + #elseif sys + Sys.exit(0); + #end + } + // if run from outside browser can get error which we can ignore + catch (e:Dynamic) + { + } + } +} diff --git a/test/TestSuite.hx b/test/TestSuite.hx new file mode 100644 index 0000000..f8b2aab --- /dev/null +++ b/test/TestSuite.hx @@ -0,0 +1,19 @@ +import massive.munit.TestSuite; + +import eskimo.EntityTest; + +/** + * Auto generated Test Suite for MassiveUnit. + * Refer to munit command line tool for more information (haxelib run munit) + */ + +class TestSuite extends massive.munit.TestSuite +{ + + public function new() + { + super(); + + add(eskimo.EntityTest); + } +} diff --git a/test/eskimo/EntityTest.hx b/test/eskimo/EntityTest.hx new file mode 100644 index 0000000..6a2aa2e --- /dev/null +++ b/test/eskimo/EntityTest.hx @@ -0,0 +1,89 @@ +package eskimo; + +import massive.munit.Assert; + +@:access(eskimo.Entity) +class EntityTest +{ + @Test + public function constructorSetsContextAndId() + { + var context:Context = new Context(); + var expectedId:Int = 37; + var e:Entity = new Entity(context, expectedId); + Assert.areEqual(context, e.context); + Assert.areEqual(expectedId, e.id); + } + + @Test + public function getGetsLastSetComponent() + { + var context:Context = new Context(); + var e:Entity = context.create(); + + var expected:IntComponent = new IntComponent(261); + e.set(new IntComponent(37)); + e.set(expected); + var actual = e.get(IntComponent); + Assert.areEqual(expected, actual); + Assert.areEqual(expected.value, actual.value); + } + + @Test + public function hasReturnsTrueIfComponentExists() + { + var context:Context = new Context(); + var e:Entity = context.create(); + Assert.isFalse(e.has(StringComponent)); + e.set(new StringComponent("hi!")); + Assert.isTrue(e.has(StringComponent)); + } + + @Test + public function removeRemovesComponent() + { + var context:Context = new Context(); + var e:Entity = context.create(); + + var expected:IntComponent = new IntComponent(987); + e.set(expected); + e.remove(IntComponent); + Assert.isFalse(e.has(IntComponent)); + Assert.isNull(e.get(IntComponent)); + } + + @Test + public function clearClearsAllComponents() + { + var context:Context = new Context(); + var e:Entity = context.create(); + e.set(new IntComponent(121)); + e.set(new StringComponent("hello!")); + Assert.isTrue(e.has(IntComponent)); + Assert.isTrue(e.has(StringComponent)); + + e.clear(); + Assert.isFalse(e.has(IntComponent)); + Assert.isFalse(e.has(StringComponent)); + } +} + +// Helper components + +class StringComponent +{ + public var value:String; + public function new(value:String):Void + { + this.value = value; + } +} + +class IntComponent +{ + public var value:Int; + public function new(value:Int):Void + { + this.value = value; + } +} \ No newline at end of file