|
@@ -1,6 +1,7 @@
|
|
package unit;
|
|
package unit;
|
|
import haxe.ds.Option;
|
|
import haxe.ds.Option;
|
|
import haxe.macro.Expr;
|
|
import haxe.macro.Expr;
|
|
|
|
+import unit.HelperMacros.getErrorMessage;
|
|
|
|
|
|
using unit.TestMatch;
|
|
using unit.TestMatch;
|
|
|
|
|
|
@@ -33,16 +34,6 @@ typedef MiniRef<T> = {
|
|
public function get():T;
|
|
public function get():T;
|
|
}
|
|
}
|
|
|
|
|
|
-class TestMatchMacro {
|
|
|
|
- static public macro function getErrorMessage(e:Expr) {
|
|
|
|
- var result = try {
|
|
|
|
- haxe.macro.Context.typeof(e);
|
|
|
|
- "no error";
|
|
|
|
- } catch (e:Dynamic) Std.string(e.message);
|
|
|
|
- return macro $v{result};
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
class TestMatch extends Test {
|
|
class TestMatch extends Test {
|
|
|
|
|
|
static function switchNormal(e:Expr):String {
|
|
static function switchNormal(e:Expr):String {
|
|
@@ -329,58 +320,58 @@ class TestMatch extends Test {
|
|
}
|
|
}
|
|
|
|
|
|
function testNonExhaustiveness() {
|
|
function testNonExhaustiveness() {
|
|
- eq("Unmatched patterns: false", TestMatchMacro.getErrorMessage(switch(true) {
|
|
|
|
|
|
+ eq("Unmatched patterns: false", getErrorMessage(switch(true) {
|
|
case true:
|
|
case true:
|
|
}));
|
|
}));
|
|
- eq("Unmatched patterns: OpNeg | OpNegBits", TestMatchMacro.getErrorMessage(switch(OpIncrement) {
|
|
|
|
|
|
+ eq("Unmatched patterns: OpNeg | OpNegBits", getErrorMessage(switch(OpIncrement) {
|
|
case OpIncrement:
|
|
case OpIncrement:
|
|
case OpDecrement:
|
|
case OpDecrement:
|
|
case OpNot:
|
|
case OpNot:
|
|
}));
|
|
}));
|
|
- eq("Unmatched patterns: Node(Node, _)", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Unmatched patterns: Node(Node, _)", getErrorMessage(switch(Leaf("foo")) {
|
|
case Node(Leaf("foo"), _):
|
|
case Node(Leaf("foo"), _):
|
|
case Leaf(_):
|
|
case Leaf(_):
|
|
}));
|
|
}));
|
|
- eq("Unmatched patterns: Leaf", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Unmatched patterns: Leaf", getErrorMessage(switch(Leaf("foo")) {
|
|
case Node(_, _):
|
|
case Node(_, _):
|
|
case Leaf(_) if (false):
|
|
case Leaf(_) if (false):
|
|
}));
|
|
}));
|
|
- eq("Unmatched patterns: Leaf(_)", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Unmatched patterns: Leaf(_)", getErrorMessage(switch(Leaf("foo")) {
|
|
case Node(_, _):
|
|
case Node(_, _):
|
|
case Leaf("foo"):
|
|
case Leaf("foo"):
|
|
}));
|
|
}));
|
|
- eq("Unmatched patterns: false", TestMatchMacro.getErrorMessage(switch [1, true, "foo"] {
|
|
|
|
|
|
+ eq("Unmatched patterns: false", getErrorMessage(switch [1, true, "foo"] {
|
|
case [_, true, _]:
|
|
case [_, true, _]:
|
|
}));
|
|
}));
|
|
//var x:Null<Bool> = true;
|
|
//var x:Null<Bool> = true;
|
|
- //eq("Unmatched patterns: null", TestMatchMacro.getErrorMessage(switch x {
|
|
|
|
|
|
+ //eq("Unmatched patterns: null", getErrorMessage(switch x {
|
|
//case true:
|
|
//case true:
|
|
//case false:
|
|
//case false:
|
|
//}));
|
|
//}));
|
|
//var t:Null<Tree<String>> = null;
|
|
//var t:Null<Tree<String>> = null;
|
|
- //eq("Unmatched patterns: null", TestMatchMacro.getErrorMessage(switch t {
|
|
|
|
|
|
+ //eq("Unmatched patterns: null", getErrorMessage(switch t {
|
|
//case Leaf(_):
|
|
//case Leaf(_):
|
|
//case Node(_):
|
|
//case Node(_):
|
|
//}));
|
|
//}));
|
|
}
|
|
}
|
|
|
|
|
|
function testInvalidBinding() {
|
|
function testInvalidBinding() {
|
|
- eq("Variable y must appear exactly once in each sub-pattern", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Variable y must appear exactly once in each sub-pattern", getErrorMessage(switch(Leaf("foo")) {
|
|
case Leaf(x) | Leaf(y):
|
|
case Leaf(x) | Leaf(y):
|
|
}));
|
|
}));
|
|
- eq("Variable y must appear exactly once in each sub-pattern", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Variable y must appear exactly once in each sub-pattern", getErrorMessage(switch(Leaf("foo")) {
|
|
case Leaf(x) | Leaf(x) | Leaf(y):
|
|
case Leaf(x) | Leaf(x) | Leaf(y):
|
|
}));
|
|
}));
|
|
- eq("Variable x must appear exactly once in each sub-pattern", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Variable x must appear exactly once in each sub-pattern", getErrorMessage(switch(Leaf("foo")) {
|
|
case Leaf(x) | Leaf(x) | Leaf(_):
|
|
case Leaf(x) | Leaf(x) | Leaf(_):
|
|
}));
|
|
}));
|
|
- eq("Variable l must appear exactly once in each sub-pattern", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Variable l must appear exactly once in each sub-pattern", getErrorMessage(switch(Leaf("foo")) {
|
|
case Node(l = Leaf(x),_) | Node(Leaf(x), _):
|
|
case Node(l = Leaf(x),_) | Node(Leaf(x), _):
|
|
}));
|
|
}));
|
|
- eq("Variable l is bound multiple times", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("Variable l is bound multiple times", getErrorMessage(switch(Leaf("foo")) {
|
|
case Node(l = Leaf(l), _):
|
|
case Node(l = Leaf(l), _):
|
|
}));
|
|
}));
|
|
- eq("String should be unit.Tree<String>", TestMatchMacro.getErrorMessage(switch(Leaf("foo")) {
|
|
|
|
|
|
+ eq("String should be unit.Tree<String>", getErrorMessage(switch(Leaf("foo")) {
|
|
case Node(l = Leaf(_), _) | Leaf(l):
|
|
case Node(l = Leaf(_), _) | Leaf(l):
|
|
case _:
|
|
case _:
|
|
}));
|
|
}));
|
|
@@ -453,7 +444,7 @@ class TestMatch extends Test {
|
|
}
|
|
}
|
|
eq(r, 1);
|
|
eq(r, 1);
|
|
|
|
|
|
- eq("Unmatched patterns: MethodNotAllowed", TestMatchMacro.getErrorMessage(switch(a) {
|
|
|
|
|
|
+ eq("Unmatched patterns: MethodNotAllowed", getErrorMessage(switch(a) {
|
|
case NotFound:
|
|
case NotFound:
|
|
}));
|
|
}));
|
|
#end
|
|
#end
|