Allow for typemaps that reduce everything except null.

This commit is contained in:
Juraj Kirchheim
2020-04-24 15:29:24 +02:00
parent 34516086c9
commit e3bac681ce
3 changed files with 53 additions and 15 deletions

1
tests/MyString.hx Normal file
View File

@@ -0,0 +1 @@
typedef MyString = String;

View File

@@ -1,17 +1,17 @@
package;
import haxe.unit.TestCase;
import haxe.macro.Expr;
import tink.macro.TypeMap;
using haxe.macro.Context;
using tink.MacroApi;
class TypeMapTest extends TestCase {
function testMap() {
var t = new TypeMap();
var t1 = (macro [{ foo: [{ bar: '5' }]}]).typeof();
var t2 = (macro [{ foo: [{ bar: 5 }]}]).typeof();
var t1 = (macro [{ foo: [{ bar: '5' }]}]).typeof().sure();
var t2 = (macro [{ foo: [{ bar: 5 }]}]).typeof().sure();
t.set(t1, 0);
assertEquals(Lambda.count(t), 1);
t.set(t2, 1);
@@ -20,11 +20,29 @@ class TypeMapTest extends TestCase {
assertEquals(Lambda.count(t), 2);
t.set(t2, 3);
assertEquals(Lambda.count(t), 2);
assertEquals(t.get(t1), 2);
assertEquals(t.get(t2), 3);
assertTrue(true);
}
function testNormalization() {
for (settings in [
{ count: 4, map: new TypeMap(TypeMap.noFollow)},
{ count: 2, map: new TypeMap(TypeMap.keepNull)},
{ count: 1, map: new TypeMap()},
]) {
function set(ct:ComplexType)
settings.map.set(ct.toType().sure(), ct);
set(macro : String);
set(macro : MyString);
set(macro : Null<String>);
set(macro : Null<MyString>);
assertEquals(settings.count, Lambda.count(settings.map));
}
}
}