Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
08249260f9 | ||
![]() |
e24941880a | ||
![]() |
bdf78197db | ||
![]() |
635e64ebf1 | ||
![]() |
990096cfd5 | ||
![]() |
1df0dd6d6c | ||
![]() |
6b8be33832 | ||
![]() |
8b769e5938 | ||
![]() |
0ca2e371d4 | ||
![]() |
472916f2af | ||
![]() |
2471637905 | ||
![]() |
c400f5af51 | ||
![]() |
32d711cd71 | ||
![]() |
0947d1b916 | ||
![]() |
aa186a1ec2 | ||
![]() |
40d7c2fbde | ||
![]() |
f1010a518f | ||
![]() |
54f592f14c | ||
![]() |
e01bf6912a |
95
.github/workflows/ci.yml
vendored
Normal file
95
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
haxe-version:
|
||||||
|
- stable
|
||||||
|
- nightly
|
||||||
|
target:
|
||||||
|
- node
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repo
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Get yarn cache directory path
|
||||||
|
id: yarn-cache-dir-path
|
||||||
|
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||||
|
|
||||||
|
- name: Cache Yarn
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-yarn-
|
||||||
|
|
||||||
|
- name: Cache Haxe
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/haxe
|
||||||
|
key: haxe
|
||||||
|
|
||||||
|
- name: Install Lix
|
||||||
|
uses: lix-pm/setup-lix@master
|
||||||
|
|
||||||
|
- name: Install Haxe
|
||||||
|
run: lix install haxe ${{ matrix.haxe-version }}
|
||||||
|
|
||||||
|
- name: Install Haxe Libraries
|
||||||
|
run: lix download
|
||||||
|
|
||||||
|
- name: Run Test
|
||||||
|
run: lix run travix ${{ matrix.target }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
if: startsWith(github.ref, 'refs/tags/') # consider using the "release" event. see: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repo
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Get yarn cache directory path
|
||||||
|
id: yarn-cache-dir-path
|
||||||
|
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||||
|
|
||||||
|
- name: Cache Yarn
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-yarn-
|
||||||
|
|
||||||
|
- name: Cache Haxe
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/haxe
|
||||||
|
key: haxe
|
||||||
|
|
||||||
|
- name: Install Lix
|
||||||
|
uses: lix-pm/setup-lix@master
|
||||||
|
|
||||||
|
- name: Install Haxe
|
||||||
|
run: lix install haxe stable
|
||||||
|
|
||||||
|
- name: Install Haxe Libraries
|
||||||
|
run: lix download
|
||||||
|
|
||||||
|
- name: Release to Haxelib
|
||||||
|
run: lix run travix release
|
||||||
|
env:
|
||||||
|
HAXELIB_AUTH: ${{ secrets.HAXELIB_AUTH }}
|
||||||
|
|
2
.haxerc
2
.haxerc
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"version": "4.0.5",
|
"version": "4.2.1",
|
||||||
"resolveLibs": "scoped"
|
"resolveLibs": "scoped"
|
||||||
}
|
}
|
17
.vscode/tasks.json
vendored
17
.vscode/tasks.json
vendored
@@ -1,6 +1,19 @@
|
|||||||
{
|
{
|
||||||
"version": "0.1.0",
|
"version": "2.0.0",
|
||||||
"command": "haxelib",
|
"command": "haxelib",
|
||||||
"args": ["run", "travix", "node"],
|
"args": ["run", "travix", "node"],
|
||||||
"problemMatcher": "$haxe"
|
"problemMatcher": "$haxe",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "haxelib",
|
||||||
|
"command": "haxelib",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"travix",
|
||||||
|
"node"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$haxe",
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
# Tinkerbell Macro Library
|
# Tinkerbell Macro Library
|
||||||
|
|
||||||
[](https://travis-ci.org/haxetink/tink_macro)
|
[](https://github.com/haxetink/tink_macro/actions)
|
||||||
[](https://gitter.im/haxetink/public)
|
[](https://gitter.im/haxetink/public)
|
||||||
|
[](https://discord.com/channels/162395145352904705/579634919576436736)
|
||||||
|
|
||||||
|
|
||||||
Explained in current marketing speak, `tink_macro` is *the* macro toolkit ;)
|
Explained in current marketing speak, `tink_macro` is *the* macro toolkit ;)
|
||||||
|
|
||||||
|
3
haxe_libraries/tink_chunk.hxml
Normal file
3
haxe_libraries/tink_chunk.hxml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# @install: lix --silent download "gh://github.com/haxetink/tink_chunk#f095072a029f1f50ce5f2cc0a690c3e834298d96" into tink_chunk/0.3.1/github/f095072a029f1f50ce5f2cc0a690c3e834298d96
|
||||||
|
-cp ${HAXE_LIBCACHE}/tink_chunk/0.3.1/github/f095072a029f1f50ce5f2cc0a690c3e834298d96/src
|
||||||
|
-D tink_chunk=0.3.1
|
@@ -1,8 +1,8 @@
|
|||||||
-D tink_cli=0.3.1
|
# @install: lix --silent download "gh://github.com/haxetink/tink_cli#1278ad2a34fd5e2403e414aefe09bb938d0c8825" into tink_cli/0.5.1/github/1278ad2a34fd5e2403e414aefe09bb938d0c8825
|
||||||
# @install: lix --silent download "haxelib:/tink_cli#0.3.1" into tink_cli/0.3.1/haxelib
|
|
||||||
-lib tink_io
|
-lib tink_io
|
||||||
-lib tink_stringly
|
|
||||||
-lib tink_macro
|
-lib tink_macro
|
||||||
-cp ${HAXE_LIBCACHE}/tink_cli/0.3.1/haxelib/src
|
-lib tink_stringly
|
||||||
|
-cp ${HAXE_LIBCACHE}/tink_cli/0.5.1/github/1278ad2a34fd5e2403e414aefe09bb938d0c8825/src
|
||||||
|
-D tink_cli=0.5.1
|
||||||
# Make sure docs are generated
|
# Make sure docs are generated
|
||||||
-D use-rtti-doc
|
-D use-rtti-doc
|
@@ -1,3 +1,3 @@
|
|||||||
-D tink_core=1.24.0
|
# @install: lix --silent download "haxelib:/tink_core#2.1.0" into tink_core/2.1.0/haxelib
|
||||||
# @install: lix --silent download "haxelib:/tink_core#1.24.0" into tink_core/1.24.0/haxelib
|
-cp ${HAXE_LIBCACHE}/tink_core/2.1.0/haxelib/src
|
||||||
-cp ${HAXE_LIBCACHE}/tink_core/1.24.0/haxelib/src
|
-D tink_core=2.1.0
|
@@ -1,5 +1,5 @@
|
|||||||
-D tink_io=0.5.0
|
# @install: lix --silent download "gh://github.com/haxetink/tink_io#e4a92421865adfd7037474937cffacaa1abd4338" into tink_io/0.8.0/github/e4a92421865adfd7037474937cffacaa1abd4338
|
||||||
# @install: lix --silent download "haxelib:/tink_io#0.5.0" into tink_io/0.5.0/haxelib
|
-lib tink_chunk
|
||||||
-lib tink_streams
|
-lib tink_streams
|
||||||
-lib tink_core
|
-cp ${HAXE_LIBCACHE}/tink_io/0.8.0/github/e4a92421865adfd7037474937cffacaa1abd4338/src
|
||||||
-cp ${HAXE_LIBCACHE}/tink_io/0.5.0/haxelib/src
|
-D tink_io=0.8.0
|
@@ -1,4 +1,6 @@
|
|||||||
-D tink_streams=0.2.1
|
# @install: lix --silent download "gh://github.com/haxetink/tink_streams#aa006c354e742164c4f7bc8ec4532bc9154fb0d0" into tink_streams/0.3.3/github/aa006c354e742164c4f7bc8ec4532bc9154fb0d0
|
||||||
# @install: lix --silent download "haxelib:/tink_streams#0.2.1" into tink_streams/0.2.1/haxelib
|
|
||||||
-lib tink_core
|
-lib tink_core
|
||||||
-cp ${HAXE_LIBCACHE}/tink_streams/0.2.1/haxelib/src
|
-cp ${HAXE_LIBCACHE}/tink_streams/0.3.3/github/aa006c354e742164c4f7bc8ec4532bc9154fb0d0/src
|
||||||
|
-D tink_streams=0.3.3
|
||||||
|
# temp for development, delete this file when pure branch merged
|
||||||
|
-D pure
|
@@ -1,6 +1,7 @@
|
|||||||
-D travix=0.12.2
|
# @install: lix --silent download "haxelib:/travix#0.15.3" into travix/0.15.3/haxelib
|
||||||
# @install: lix --silent download "gh://github.com/back2dos/travix#7da3bf96717b52bf3c7e5d2273bf927a8cd7aeb5" into travix/0.12.2/github/7da3bf96717b52bf3c7e5d2273bf927a8cd7aeb5
|
# @post-install: cd ${HAXE_LIBCACHE}/travix/0.15.3/haxelib && haxe -cp src --run travix.PostDownload
|
||||||
# @post-install: cd ${HAXE_LIBCACHE}/travix/0.12.2/github/7da3bf96717b52bf3c7e5d2273bf927a8cd7aeb5 && haxe -cp src --run travix.PostDownload
|
# @run: haxelib run-dir travix "${HAXE_LIBCACHE}/travix/0.15.3/haxelib"
|
||||||
# @run: haxelib run-dir travix ${HAXE_LIBCACHE}/travix/0.12.2/github/7da3bf96717b52bf3c7e5d2273bf927a8cd7aeb5
|
|
||||||
-lib tink_cli
|
-lib tink_cli
|
||||||
-cp ${HAXE_LIBCACHE}/travix/0.12.2/github/7da3bf96717b52bf3c7e5d2273bf927a8cd7aeb5/src
|
-cp ${HAXE_LIBCACHE}/travix/0.15.3/haxelib/src
|
||||||
|
-D travix=0.15.3
|
||||||
|
--macro travix.Macro.setup()
|
@@ -9,8 +9,8 @@
|
|||||||
"contributors": [
|
"contributors": [
|
||||||
"back2dos"
|
"back2dos"
|
||||||
],
|
],
|
||||||
"version": "0.23.0",
|
"version": "1.0.4",
|
||||||
"releasenote": "Make TypeMap work exacly with anons.",
|
"releasenote": "Haxe 5 compat",
|
||||||
"tags": [
|
"tags": [
|
||||||
"tink",
|
"tink",
|
||||||
"macro",
|
"macro",
|
||||||
|
@@ -21,7 +21,7 @@ typedef TypeMap<T> = tink.macro.TypeMap<T>;
|
|||||||
|
|
||||||
//TODO: consider adding stuff from haxe.macro.Expr here
|
//TODO: consider adding stuff from haxe.macro.Expr here
|
||||||
typedef MacroOutcome<D, F> = tink.core.Outcome<D, F>;
|
typedef MacroOutcome<D, F> = tink.core.Outcome<D, F>;
|
||||||
typedef MacroOutcomeTools = tink.OutcomeTools;
|
typedef MacroOutcomeTools = tink.core.Outcome.OutcomeTools;
|
||||||
|
|
||||||
typedef Member = tink.macro.Member;
|
typedef Member = tink.macro.Member;
|
||||||
typedef Constructor = tink.macro.Constructor;
|
typedef Constructor = tink.macro.Constructor;
|
||||||
@@ -33,15 +33,22 @@ class MacroApi {
|
|||||||
|
|
||||||
static var MAIN_CANDIDATES = ['-main', '-x', '--run'];
|
static var MAIN_CANDIDATES = ['-main', '-x', '--run'];
|
||||||
static public function getMainClass():Option<String> {
|
static public function getMainClass():Option<String> {
|
||||||
var args = Sys.args();
|
#if (haxe_ver >= 4.3)
|
||||||
|
return switch haxe.macro.Compiler.getConfiguration().mainClass {
|
||||||
for (c in MAIN_CANDIDATES)
|
case null: None;
|
||||||
switch args.indexOf(c) {
|
case p: Some(p.pack.concat([p.name]).join('.'));
|
||||||
case -1:
|
|
||||||
case v: return Some(args[v+1]);
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
var args = Sys.args();
|
||||||
|
|
||||||
return None;
|
for (c in MAIN_CANDIDATES)
|
||||||
|
switch args.indexOf(c) {
|
||||||
|
case -1:
|
||||||
|
case v: return Some(args[v+1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return None;
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
@:persistent static var idCounter = 0;
|
@:persistent static var idCounter = 0;
|
||||||
|
@@ -3,7 +3,7 @@ package tink.macro;
|
|||||||
#if macro
|
#if macro
|
||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
|
|
||||||
using tink.macro.Positions;
|
using tink.macro.Positions;
|
||||||
using tink.macro.Exprs;
|
using tink.macro.Exprs;
|
||||||
#end
|
#end
|
||||||
@@ -15,7 +15,7 @@ package tink.macro;
|
|||||||
static public function bounceExpr(e:Expr, transform:Expr->Expr) {
|
static public function bounceExpr(e:Expr, transform:Expr->Expr) {
|
||||||
var id = idCounter++,
|
var id = idCounter++,
|
||||||
pos = e.pos;
|
pos = e.pos;
|
||||||
outerMap.set(id, transform);
|
outerMap.set(id, transform);
|
||||||
return macro @:pos(e.pos) tink.macro.Bouncer.catchBounceExpr($e, $v{id});
|
return macro @:pos(e.pos) tink.macro.Bouncer.catchBounceExpr($e, $v{id});
|
||||||
}
|
}
|
||||||
static public function bounce(f:Void->Expr, ?pos:Position) {
|
static public function bounce(f:Void->Expr, ?pos:Position) {
|
||||||
@@ -29,35 +29,41 @@ package tink.macro;
|
|||||||
pos = e.pos;
|
pos = e.pos;
|
||||||
outerMap.set(id, transform);
|
outerMap.set(id, transform);
|
||||||
return macro @:pos(e.pos) tink.macro.Bouncer.makeOuter($e).andBounce($v{id});
|
return macro @:pos(e.pos) tink.macro.Bouncer.makeOuter($e).andBounce($v{id});
|
||||||
}
|
}
|
||||||
static function doOuter(id:Int, e:Expr) {
|
static function doOuter(id:Int, e:Expr) {
|
||||||
return
|
return
|
||||||
if (outerMap.exists(id))
|
if (outerMap.exists(id))
|
||||||
outerMap.get(id)(e);
|
outerMap.get(id)(e);
|
||||||
else
|
else
|
||||||
Context.currentPos().error('unknown id ' + id);
|
Context.currentPos().error('unknown id ' + id);
|
||||||
}
|
}
|
||||||
static function doBounce(id:Int) {
|
static function doBounce(id:Int) {
|
||||||
return
|
return
|
||||||
if (bounceMap.exists(id))
|
if (bounceMap.exists(id))
|
||||||
bounceMap.get(id)();
|
bounceMap.get(id)();
|
||||||
else
|
else
|
||||||
Context.currentPos().error('unknown id ' + id);
|
Context.currentPos().error('unknown id ' + id);
|
||||||
}
|
}
|
||||||
|
static public var lastEvaled(default, null):Dynamic;
|
||||||
#else
|
#else
|
||||||
@:noUsing static public function makeOuter<A>(a:A):Bouncer
|
@:noUsing static public function makeOuter<A>(a:A):Bouncer
|
||||||
return null;
|
return null;
|
||||||
#end
|
#end
|
||||||
@:noUsing macro public function andBounce(ethis:Expr, id:Int)
|
@:noUsing macro public function andBounce(ethis:Expr, id:Int)
|
||||||
return
|
return
|
||||||
switch (ethis.expr) {
|
switch (ethis.expr) {
|
||||||
case ECall(_, params): doOuter(id, params[0]);
|
case ECall(_, params): doOuter(id, params[0]);
|
||||||
default: ethis.reject();
|
default: ethis.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function catchBounce(id:Int)
|
@:noUsing static public macro function eval(f:Void->Dynamic) {
|
||||||
|
lastEvaled = f();
|
||||||
|
return macro null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:noUsing macro static public function catchBounce(id:Int)
|
||||||
return doBounce(id);
|
return doBounce(id);
|
||||||
|
|
||||||
@:noUsing macro static public function catchBounceExpr(e:Expr, id:Int)
|
@:noUsing macro static public function catchBounceExpr(e:Expr, id:Int)
|
||||||
return doOuter(id, e);
|
return doOuter(id, e);
|
||||||
}
|
}
|
@@ -48,6 +48,11 @@ class Exprs {
|
|||||||
static public inline function as(e:Expr, c:ComplexType)
|
static public inline function as(e:Expr, c:ComplexType)
|
||||||
return ECheckType(e, c).at(e.pos);
|
return ECheckType(e, c).at(e.pos);
|
||||||
|
|
||||||
|
static public function eval(e:Expr):Dynamic {
|
||||||
|
Context.typeof(macro tink.macro.Bouncer.eval(function () return $e));
|
||||||
|
return Bouncer.lastEvaled;
|
||||||
|
}
|
||||||
|
|
||||||
static public function finalize(e:Expr, ?nuPos:Position, ?rules:Dict<String>, ?skipFields = false, ?callPos:PosInfos) {
|
static public function finalize(e:Expr, ?nuPos:Position, ?rules:Dict<String>, ?skipFields = false, ?callPos:PosInfos) {
|
||||||
if (nuPos == null)
|
if (nuPos == null)
|
||||||
nuPos = Context.currentPos();
|
nuPos = Context.currentPos();
|
||||||
@@ -352,7 +357,7 @@ class Exprs {
|
|||||||
expr = [EVars(locals).at(expr.pos), expr].toMBlock(expr.pos);
|
expr = [EVars(locals).at(expr.pos), expr].toMBlock(expr.pos);
|
||||||
Success(Context.typeof(expr));
|
Success(Context.typeof(expr));
|
||||||
}
|
}
|
||||||
catch (e:haxe.macro.Error) {
|
catch (e:haxe.macro.Expr.Error) {
|
||||||
e.pos.makeFailure(e.message);
|
e.pos.makeFailure(e.message);
|
||||||
}
|
}
|
||||||
catch (e:Dynamic) {
|
catch (e:Dynamic) {
|
||||||
|
@@ -98,6 +98,15 @@ abstract Member(Field) from Field to Field {
|
|||||||
return
|
return
|
||||||
if (this.meta == null) [];
|
if (this.meta == null) [];
|
||||||
else [for (tag in this.meta) if (tag.name == name) tag];
|
else [for (tag in this.meta) if (tag.name == name) tag];
|
||||||
|
|
||||||
|
public function hasMeta(name)
|
||||||
|
return switch this.meta {
|
||||||
|
case null | []: false;
|
||||||
|
case meta:
|
||||||
|
for (m in meta)
|
||||||
|
if (m.name == name) return true;
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
public inline function asField():Field return this;
|
public inline function asField():Field return this;
|
||||||
public function publish()
|
public function publish()
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package tink.macro;
|
package tink.macro;
|
||||||
|
|
||||||
|
import haxe.macro.Context;
|
||||||
import haxe.macro.Type;
|
import haxe.macro.Type;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
using haxe.macro.Tools;
|
using haxe.macro.Tools;
|
||||||
@@ -31,6 +32,9 @@ class TypedExprs {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function eval(t:TypedExpr)
|
||||||
|
return Exprs.eval(Context.storeTypedExpr(t));
|
||||||
|
|
||||||
static public function isThis(t:TypedExpr):Bool
|
static public function isThis(t:TypedExpr):Bool
|
||||||
return switch t {
|
return switch t {
|
||||||
case null: false;
|
case null: false;
|
||||||
|
@@ -41,9 +41,10 @@ class Types {
|
|||||||
static public function accessToName(v:VarAccess, ?read = true)
|
static public function accessToName(v:VarAccess, ?read = true)
|
||||||
return
|
return
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case AccNormal, AccInline: 'default';
|
case AccNormal: 'default';
|
||||||
|
case AccInline: if (read) 'default' else 'never';
|
||||||
case AccNo: 'null';
|
case AccNo: 'null';
|
||||||
case AccNever: 'never';
|
case AccNever #if haxe4 | AccCtor #end: 'never';
|
||||||
case AccCall: if (read) 'get' else 'set';
|
case AccCall: if (read) 'get' else 'set';
|
||||||
default:
|
default:
|
||||||
throw 'not implemented';
|
throw 'not implemented';
|
||||||
@@ -213,7 +214,7 @@ class Types {
|
|||||||
static public function deduceCommonType(types:Array<Type>):Outcome<Type, Error> {
|
static public function deduceCommonType(types:Array<Type>):Outcome<Type, Error> {
|
||||||
var exprs = types.map(function(t) {
|
var exprs = types.map(function(t) {
|
||||||
var ct = t.toComplex();
|
var ct = t.toComplex();
|
||||||
return macro (null:$ct);
|
return macro (cast null:$ct);
|
||||||
});
|
});
|
||||||
|
|
||||||
return switch (macro $a{exprs}).typeof() {
|
return switch (macro $a{exprs}).typeof() {
|
||||||
|
@@ -29,7 +29,9 @@ abstract PhysicalType<T>(Either<Class<T>, Enum<T>>) {
|
|||||||
}
|
}
|
||||||
//TODO: this helper should go somewhere
|
//TODO: this helper should go somewhere
|
||||||
class Base extends TestCase {
|
class Base extends TestCase {
|
||||||
|
function stringCompare<A>(v1:A, v2:A, ?pos)
|
||||||
|
assertEquals(Std.string(v1), Std.string(v2), pos);
|
||||||
|
|
||||||
function fail(msg:String, ?c : PosInfos) {
|
function fail(msg:String, ?c : PosInfos) {
|
||||||
currentTest.done = true;
|
currentTest.done = true;
|
||||||
currentTest.success = false;
|
currentTest.success = false;
|
||||||
|
@@ -16,38 +16,47 @@ class Exprs extends Base {
|
|||||||
assertTrue(id.length <= 3);
|
assertTrue(id.length <= 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testEval() {
|
||||||
|
var expr = macro (untyped {foo:[{bar:234},'bar']});
|
||||||
|
var str = Std.string(untyped {foo:[{bar:234},'bar']});
|
||||||
|
assertEquals(Std.string(expr.eval()), Std.string(untyped {foo:[{bar:234},'bar']}));
|
||||||
|
|
||||||
|
// This doesn't work in Haxe 4.3, which is correct, because typeExpr types an expression into target context, rather than macro context
|
||||||
|
// assertEquals(Std.string(Context.typeExpr(expr).eval()), Std.string(untyped {foo:[{bar:234},'bar']}));
|
||||||
|
}
|
||||||
function testGet() {
|
function testGet() {
|
||||||
assertEquals('foo', (macro foo).getIdent().sure());
|
assertEquals('foo', (macro foo).getIdent().sure());
|
||||||
assertEquals('foo', (macro "foo").getString().sure());
|
assertEquals('foo', (macro "foo").getString().sure());
|
||||||
assertEquals('foo', (macro foo).getName().sure());
|
assertEquals('foo', (macro foo).getName().sure());
|
||||||
assertEquals('foo', (macro "foo").getName().sure());
|
assertEquals('foo', (macro "foo").getName().sure());
|
||||||
assertEquals(5, (macro 5).getInt().sure());
|
assertEquals(5, (macro 5).getInt().sure());
|
||||||
|
|
||||||
exprEq(macro [a, b, c], (macro function (a, b, c) [a, b, c]).getFunction().sure().expr);
|
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(','));
|
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').getIdent().isSuccess());
|
||||||
assertFalse((macro foo).getString().isSuccess());
|
assertFalse((macro foo).getString().isSuccess());
|
||||||
assertFalse((macro 5).getName().isSuccess());
|
assertFalse((macro 5).getName().isSuccess());
|
||||||
assertFalse((macro 5.1).getInt().isSuccess());
|
assertFalse((macro 5.1).getInt().isSuccess());
|
||||||
assertFalse((macro foo).getFunction().isSuccess());
|
assertFalse((macro foo).getFunction().isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testShortcuts() {
|
function testShortcuts() {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testIterType() {
|
function testIterType() {
|
||||||
assertEquals('Int', (macro [1, 2]).getIterType().sure().getID());
|
assertEquals('Int', (macro [1, 2]).getIterType().sure().getID());
|
||||||
assertEquals('Int', (macro [1, 2].iterator()).getIterType().sure().getID());
|
assertEquals('Int', (macro [1, 2].iterator()).getIterType().sure().getID());
|
||||||
assertEquals('Int', ECheckType(macro null, macro: Arrayish).at().getIterType().sure().getID());
|
assertEquals('Int', ECheckType(macro null, macro: Arrayish).at().getIterType().sure().getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testYield() {
|
function testYield() {
|
||||||
function yielder(e) return macro @yield $e;
|
function yielder(e) return macro @yield $e;
|
||||||
function test(x:Expr, e:Expr, ?options)
|
function test(x:Expr, e:Expr, ?options)
|
||||||
exprEq(x, e.yield(yielder, options));
|
exprEq(x, e.yield(yielder, options));
|
||||||
|
|
||||||
test(macro @yield foo, macro foo);
|
test(macro @yield foo, macro foo);
|
||||||
test(macro @yield (foo), macro (foo));
|
test(macro @yield (foo), macro (foo));
|
||||||
test(macro for (_) @yield foo, macro for (_) foo);
|
test(macro for (_) @yield foo, macro for (_) foo);
|
||||||
@@ -57,10 +66,10 @@ class Exprs extends Base {
|
|||||||
}
|
}
|
||||||
function testSubstitute() {
|
function testSubstitute() {
|
||||||
exprEq(
|
exprEq(
|
||||||
macro foo.call(arg1, arg2),
|
macro foo.call(arg1, arg2),
|
||||||
(macro bar.call(x, y)).substitute({ x: macro arg1, y: macro arg2, bar: macro foo })
|
(macro bar.call(x, y)).substitute({ x: macro arg1, y: macro arg2, bar: macro foo })
|
||||||
);
|
);
|
||||||
|
|
||||||
exprEq(
|
exprEq(
|
||||||
macro {
|
macro {
|
||||||
var x:Map<Int, String> = new Map(),
|
var x:Map<Int, String> = new Map(),
|
||||||
@@ -89,7 +98,7 @@ class Exprs extends Base {
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testConcat() {
|
function testConcat() {
|
||||||
exprEq(macro {a; b;}, (macro a).concat(macro b));
|
exprEq(macro {a; b;}, (macro a).concat(macro b));
|
||||||
exprEq(macro {a; b; c;}, (macro {a; b;}).concat(macro c));
|
exprEq(macro {a; b; c;}, (macro {a; b;}).concat(macro c));
|
||||||
|
@@ -6,8 +6,6 @@ import haxe.macro.Expr;
|
|||||||
using tink.MacroApi;
|
using tink.MacroApi;
|
||||||
|
|
||||||
class Positions extends Base {
|
class Positions extends Base {
|
||||||
function stringCompare<A>(v1:A, v2:A)
|
|
||||||
assertEquals(Std.string(v1), Std.string(v2));
|
|
||||||
|
|
||||||
function testSanitize() {
|
function testSanitize() {
|
||||||
var p:Position = null;
|
var p:Position = null;
|
||||||
@@ -19,6 +17,6 @@ class Positions extends Base {
|
|||||||
function testBlank() {
|
function testBlank() {
|
||||||
var p:Position = null;
|
var p:Position = null;
|
||||||
var t = p.makeBlankType();
|
var t = p.makeBlankType();
|
||||||
stringCompare('TMono(<mono>)', cast t.toType().sure());
|
stringCompare('TMono(<mono>)', cast t.toType().sure().reduce());
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user