diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..57331a8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Juraj Kirchheim + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/haxelib.json b/haxelib.json index 3103f4d..08a9831 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,11 +4,11 @@ "license": "MIT", "tags": ["tink", "macro", "utility"], "description": "The macro toolkit ;)", - "version": "0.0.0-alpha.2", + "version": "0.0.0-alpha.3", "releasenote": "Overall refactoring.", "contributors": ["back2dos"], "dependencies": { - "tink_core": "1.0.0-alpha.2" + "tink_core": "1.0.0-beta.1" }, "classPath": "src" } \ No newline at end of file diff --git a/src/tink/macro/Positions.hx b/src/tink/macro/Positions.hx index 969d7b6..b311504 100644 --- a/src/tink/macro/Positions.hx +++ b/src/tink/macro/Positions.hx @@ -3,13 +3,14 @@ package tink.macro; import haxe.macro.Context; import haxe.macro.Expr; import tink.core.Error; + using tink.macro.Positions; using tink.core.Outcome; class Positions { static public function getOutcome(pos:Position, outcome:Outcome):D return - switch (outcome) { + switch outcome { case Success(d): d; case Failure(f): pos.error(f); } diff --git a/tests/Exprs.hx b/tests/Exprs.hx index 365298e..3aa47b4 100644 --- a/tests/Exprs.hx +++ b/tests/Exprs.hx @@ -1,70 +1,70 @@ -package ; - -import haxe.macro.Expr; -using tink.Macro; - -class Exprs extends Base { - function exprEq(e1:Expr, e2:Expr) { - assertEquals(e1.toString(), e2.toString()); - } - function testGet() { - assertEquals('foo', (macro foo).getIdent().sure()); - assertEquals('foo', (macro "foo").getString().sure()); - assertEquals('foo', (macro foo).getName().sure()); - assertEquals('foo', (macro "foo").getName().sure()); - assertEquals(5, (macro 5).getInt().sure()); - - exprEq(macro [a, b, c], (macro function (a, b, c) [a, b, c]).getFunction().sure().expr); - assertEquals('a,b,c', [for (arg in (macro function (a, b, c) [a, b, c]).getFunction().sure().args) arg.name].join(',')); - - assertFalse((macro 'foo').getIdent().isSuccess()); - assertFalse((macro foo).getString().isSuccess()); - assertFalse((macro 5).getName().isSuccess()); - assertFalse((macro 5.1).getInt().isSuccess()); - assertFalse((macro foo).getFunction().isSuccess()); - } - - function testShortcuts() { - assertTrue(true); - } - - function testIterType() { - assertEquals('Int', (macro [1, 2]).getIterType().sure().getID()); - assertEquals('Int', (macro [1, 2].iterator()).getIterType().sure().getID()); - assertEquals('Int', ECheckType(macro null, macro: Arrayish).at().getIterType().sure().getID()); - } - - function testYield() { - function yielder(e) return macro @yield $e; - function test(x:Expr, e:Expr) - exprEq(x, e.yield(yielder)); - - test(macro @yield foo, macro foo); - test(macro @yield (foo), macro (foo)); - test(macro for (_) @yield foo, macro for (_) foo); - test(macro while (_) @yield foo, macro while (_) foo); - test(macro @yield [while (_) foo], macro [while (_) foo]); - } - - function testSubstitute() { - exprEq( - macro foo.call(arg1, arg2), - (macro bar.call(x, y)).substitute({ x: macro arg1, y: macro arg2, bar: macro foo }) - ); - - exprEq( - macro { - var x:Map = new Map(), - y:Array = []; - }, - (macro { - var x:Map = new Map(), - y:C = []; - }).substParams([ - 'A' => macro : Int, - 'B' => macro : String, - 'C' => macro : Array - ]) - ); - } +package ; + +import haxe.macro.Expr; +using tink.Macro; + +class Exprs extends Base { + function exprEq(e1:Expr, e2:Expr) { + assertEquals(e1.toString(), e2.toString()); + } + function testGet() { + assertEquals('foo', (macro foo).getIdent().sure()); + assertEquals('foo', (macro "foo").getString().sure()); + assertEquals('foo', (macro foo).getName().sure()); + assertEquals('foo', (macro "foo").getName().sure()); + assertEquals(5, (macro 5).getInt().sure()); + + exprEq(macro [a, b, c], (macro function (a, b, c) [a, b, c]).getFunction().sure().expr); + assertEquals('a,b,c', [for (arg in (macro function (a, b, c) [a, b, c]).getFunction().sure().args) arg.name].join(',')); + + assertFalse((macro 'foo').getIdent().isSuccess()); + assertFalse((macro foo).getString().isSuccess()); + assertFalse((macro 5).getName().isSuccess()); + assertFalse((macro 5.1).getInt().isSuccess()); + assertFalse((macro foo).getFunction().isSuccess()); + } + + function testShortcuts() { + assertTrue(true); + } + + function testIterType() { + assertEquals('Int', (macro [1, 2]).getIterType().sure().getID()); + assertEquals('Int', (macro [1, 2].iterator()).getIterType().sure().getID()); + assertEquals('Int', ECheckType(macro null, macro: Arrayish).at().getIterType().sure().getID()); + } + + function testYield() { + function yielder(e) return macro @yield $e; + function test(x:Expr, e:Expr) + exprEq(x, e.yield(yielder)); + + test(macro @yield foo, macro foo); + test(macro @yield (foo), macro (foo)); + test(macro for (_) @yield foo, macro for (_) foo); + test(macro while (_) @yield foo, macro while (_) foo); + test(macro @yield [while (_) foo], macro [while (_) foo]); + } + + function testSubstitute() { + exprEq( + macro foo.call(arg1, arg2), + (macro bar.call(x, y)).substitute({ x: macro arg1, y: macro arg2, bar: macro foo }) + ); + + exprEq( + macro { + var x:Map = new Map(), + y:Array = []; + }, + (macro { + var x:Map = new Map(), + y:C = []; + }).substParams([ + 'A' => macro : Int, + 'B' => macro : String, + 'C' => macro : Array + ]) + ); + } } \ No newline at end of file diff --git a/tests/Positions.hx b/tests/Positions.hx index 6e4e5d4..e59196e 100644 --- a/tests/Positions.hx +++ b/tests/Positions.hx @@ -1,23 +1,24 @@ -package ; - -import haxe.macro.Context; -import haxe.macro.Expr; -using tink.Macro; - -class Positions extends Base { - function stringCompare(v1:A, v2:A) - assertEquals(Std.string(v1), Std.string(v2)); - - function testSanitize() { - var p:Position = null; - stringCompare(Context.currentPos(), p.sanitize()); - p = Context.makePosition({ min: 0, max: 10, file: 'foo.txt' }); - stringCompare(p, p); - } - - function testBlank() { - var p:Position = null; - var t = p.makeBlankType(); - stringCompare('TMono()', cast t.toType().sure()); - } +package ; + +import haxe.macro.Context; +import haxe.macro.Expr; + +using tink.Macro; + +class Positions extends Base { + function stringCompare(v1:A, v2:A) + assertEquals(Std.string(v1), Std.string(v2)); + + function testSanitize() { + var p:Position = null; + stringCompare(Context.currentPos(), p.sanitize()); + p = Context.makePosition({ min: 0, max: 10, file: 'foo.txt' }); + stringCompare(p, p); + } + + function testBlank() { + var p:Position = null; + var t = p.makeBlankType(); + stringCompare('TMono()', cast t.toType().sure()); + } } \ No newline at end of file diff --git a/tests/Types.hx b/tests/Types.hx index dd3b777..2d8e11a 100644 --- a/tests/Types.hx +++ b/tests/Types.hx @@ -1,46 +1,46 @@ -package ; - -import haxe.macro.Expr; -import haxe.macro.Context; -using tink.Macro; - -class Types extends Base { - function type(c:ComplexType) - return c.toType().sure(); - - function resolve(type:String) - return Context.getType(type); - - inline function assertSuccess(o:Outcome) - assertTrue(o.isSuccess()); - - inline function assertFailure(o:Outcome) - assertFalse(o.isSuccess()); - - function testIs() { - assertSuccess(resolve('Int').isSubTypeOf(resolve('Float'))); - assertFailure(resolve('Float').isSubTypeOf(resolve('Int'))); - } - - function testFields() { - var iterator = type(macro : haxe.ds.StringMap).getFields(true).sure().filter(function (c) return c.name == 'iterator')[0]; - var expected = type(macro : Void -> Iterator); - - assertSuccess(iterator.type.isSubTypeOf(expected)); - assertSuccess(expected.isSubTypeOf(iterator.type)); - } - - function testConvert() { - assertSuccess((macro : Int).toType()); - assertFailure((macro : Tni).toType()); - function blank() - return type(Macro.pos().makeBlankType()); - - var bool = type(macro : Bool); - assertTrue(blank().isSubTypeOf(bool).isSuccess()); - assertTrue(bool.isSubTypeOf(blank()).isSuccess()); - - Macro.pos().makeBlankType().toString(); - } -} - +package ; + +import haxe.macro.Expr; +import haxe.macro.Context; + +using tink.Macro; + +class Types extends Base { + function type(c:ComplexType) + return c.toType().sure(); + + function resolve(type:String) + return Context.getType(type); + + inline function assertSuccess(o:Outcome) + assertTrue(o.isSuccess()); + + inline function assertFailure(o:Outcome) + assertFalse(o.isSuccess()); + + function testIs() { + assertSuccess(resolve('Int').isSubTypeOf(resolve('Float'))); + assertFailure(resolve('Float').isSubTypeOf(resolve('Int'))); + } + + function testFields() { + var expected = type(macro : Void -> Iterator), + iterator = type(macro : haxe.ds.StringMap).getFields(true).sure().filter(function (c) return c.name == 'iterator')[0]; + + assertSuccess(iterator.type.isSubTypeOf(expected)); + assertSuccess(expected.isSubTypeOf(iterator.type)); + } + + function testConvert() { + assertSuccess((macro : Int).toType()); + assertFailure((macro : Tni).toType()); + function blank() + return type(Macro.pos().makeBlankType()); + + var bool = type(macro : Bool); + assertTrue(blank().isSubTypeOf(bool).isSuccess()); + assertTrue(bool.isSubTypeOf(blank()).isSuccess()); + + Macro.pos().makeBlankType().toString(); + } +} \ No newline at end of file