Fix indenting.

This commit is contained in:
Juraj Kirchheim
2016-04-14 13:54:26 +02:00
parent df01d82300
commit c0b562af31
17 changed files with 1387 additions and 1387 deletions

View File

@@ -1,5 +1,5 @@
package ;
class Arrayish implements ArrayAccess<Int> {
public var length:Int;
public var length:Int;
}

View File

@@ -7,44 +7,44 @@ import haxe.unit.TestStatus;
import tink.core.Either;
abstract PhysicalType<T>(Either<Class<T>, Enum<T>>) {
function new(v) this = v;
public function toString()
return
switch this {
case Left(c): Type.getClassName(c);
case Right(e): Type.getEnumName(e);
}
public function check(v:T)
return
Std.is(v, this.getParameters()[0]);
@:from static function ofClass<C>(c:Class<C>)
return new PhysicalType(Left(c));
@:from static function ofEnum<E>(e:Enum<E>)
return new PhysicalType(Right(e));
function new(v) this = v;
public function toString()
return
switch this {
case Left(c): Type.getClassName(c);
case Right(e): Type.getEnumName(e);
}
public function check(v:T)
return
Std.is(v, this.getParameters()[0]);
@:from static function ofClass<C>(c:Class<C>)
return new PhysicalType(Left(c));
@:from static function ofEnum<E>(e:Enum<E>)
return new PhysicalType(Right(e));
}
//TODO: this helper should go somewhere
class Base extends TestCase {
function fail(msg:String, ?c : PosInfos) {
currentTest.done = true;
currentTest.success = false;
currentTest.error = msg;
currentTest.posInfos = c;
throw currentTest;
}
function throws<A>(f:Void->Void, ?t:PhysicalType<A>, ?check:A->Bool, ?pos:PosInfos):Void {
try f()
catch (e:Dynamic) {
if (t != null && !t.check(e)) fail('Exception $e not of type $t', pos);
if (check != null && !check(e)) fail('Exception $e does not satisfy condition', pos);
assertTrue(true);
return;
}
fail('no exception thrown', pos);
}
function fail(msg:String, ?c : PosInfos) {
currentTest.done = true;
currentTest.success = false;
currentTest.error = msg;
currentTest.posInfos = c;
throw currentTest;
}
function throws<A>(f:Void->Void, ?t:PhysicalType<A>, ?check:A->Bool, ?pos:PosInfos):Void {
try f()
catch (e:Dynamic) {
if (t != null && !t.check(e)) fail('Exception $e not of type $t', pos);
if (check != null && !check(e)) fail('Exception $e does not satisfy condition', pos);
assertTrue(true);
return;
}
fail('no exception thrown', pos);
}
}

View File

@@ -4,80 +4,80 @@ import haxe.macro.Expr;
using tink.MacroApi;
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, ?options)
exprEq(x, e.yield(yielder, options));
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, { leaveLoops: true });
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<Int, String> = new Map(),
y:Array<Float> = [];
},
(macro {
var x:Map<A, B> = new Map(),
y:C = [];
}).substParams([
'A' => macro : Int,
'B' => macro : String,
'C' => macro : Array<Float>
])
);
exprEq(
macro {
new Foo<Bar>(1, 2, 3);
Bar.foo();
},
(macro {
new X(1, 2, 3);
Y.foo();
}).substParams([
'X' => macro : Foo<Bar>,
'Y' => macro : Bar
])
);
}
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, ?options)
exprEq(x, e.yield(yielder, options));
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, { leaveLoops: true });
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<Int, String> = new Map(),
y:Array<Float> = [];
},
(macro {
var x:Map<A, B> = new Map(),
y:C = [];
}).substParams([
'A' => macro : Int,
'B' => macro : String,
'C' => macro : Array<Float>
])
);
exprEq(
macro {
new Foo<Bar>(1, 2, 3);
Bar.foo();
},
(macro {
new X(1, 2, 3);
Y.foo();
}).substParams([
'X' => macro : Foo<Bar>,
'Y' => macro : Bar
])
);
}
}

View File

@@ -6,19 +6,19 @@ import haxe.macro.Expr;
using tink.MacroApi;
class Positions extends Base {
function stringCompare<A>(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(<mono>)', cast t.toType().sure());
}
function stringCompare<A>(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(<mono>)', cast t.toType().sure());
}
}

View File

@@ -3,27 +3,27 @@ package ;
import haxe.unit.*;
class Run {
#if !macro
static function main()
test();//It compiles ...
#else
static var cases:Array<TestCase> = [
new Exprs(),
new Types(),
new Positions(),
];
#end
macro static function test() {
var runner = new TestRunner();
tink.macro.ClassBuilder;
for (c in cases)
runner.add(c);
runner.run();
if (!runner.result.success)
haxe.macro.Context.error(runner.result.toString(), haxe.macro.Context.currentPos());
return macro {
trace('Let\'s ship it!');
}
}
#if !macro
static function main()
test();//It compiles ...
#else
static var cases:Array<TestCase> = [
new Exprs(),
new Types(),
new Positions(),
];
#end
macro static function test() {
var runner = new TestRunner();
tink.macro.ClassBuilder;
for (c in cases)
runner.add(c);
runner.run();
if (!runner.result.success)
haxe.macro.Context.error(runner.result.toString(), haxe.macro.Context.currentPos());
return macro {
trace('Let\'s ship it!');
}
}
}

View File

@@ -7,41 +7,41 @@ using tink.CoreApi;
using tink.MacroApi;
class Types extends Base {
function type(c:ComplexType)
return c.toType().sure();
function resolve(type:String)
return Context.getType(type);
inline function assertSuccess<S, F>(o:Outcome<S, F>)
assertTrue(o.isSuccess());
inline function assertFailure<S, F>(o:Outcome<S, F>)
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<Arrayish>),
iterator = type(macro : haxe.ds.StringMap<Arrayish>).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(MacroApi.pos().makeBlankType());
var bool = type(macro : Bool);
assertTrue(blank().isSubTypeOf(bool).isSuccess());
assertTrue(bool.isSubTypeOf(blank()).isSuccess());
MacroApi.pos().makeBlankType().toString();
}
function type(c:ComplexType)
return c.toType().sure();
function resolve(type:String)
return Context.getType(type);
inline function assertSuccess<S, F>(o:Outcome<S, F>)
assertTrue(o.isSuccess());
inline function assertFailure<S, F>(o:Outcome<S, F>)
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<Arrayish>),
iterator = type(macro : haxe.ds.StringMap<Arrayish>).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(MacroApi.pos().makeBlankType());
var bool = type(macro : Bool);
assertTrue(blank().isSubTypeOf(bool).isSuccess());
assertTrue(bool.isSubTypeOf(blank()).isSuccess());
MacroApi.pos().makeBlankType().toString();
}
}