Closed back2dos closed 4 years ago
iirc I did that because i want strings to be wrapped in quotes, so we know it is string.
Yeah, sure. We could still do Assert.stringify((value:String))
for all abstracts that unify with string. But I think that overshoots the goal What I'd propose would be:.
to String
should be printed with quotes, @:to String
probably shouldn'tFor example "john.doe@example.com"
does make sense for an abstract Email(String) to String
but having some 2d point abstract having quotes in "Point(1, 2)"
is noisy at best, misleading at worst.
@:asserts
class StringificationTest {
public function new() {}
public function eq() {
var i = 2;
asserts.assert(i == 2);
var b = true;
asserts.assert(b);
var u = new UnderlyingString('foo');
asserts.assert(u == 'foo');
var c = new CastableToString(1);
asserts.assert(c == 'Value=1');
asserts.assert(c == 1);
return asserts.done();
}
}
abstract Abs(Int) {
public inline function new(v) this = v;
@:op(A==B) static function eq(a:Abs, b:Abs):Bool;
}
abstract UnderlyingString(String) to String {
public inline function new(v) this = v;
}
abstract CastableToString(Int) to Int {
public inline function new(v) this = v;
@:to public inline function stringify():String return 'Value=$this';
}
output this:
- [OK] [tests/RunTests.hx:364] i == 2 (2 == 2)
- [OK] [tests/RunTests.hx:366] b
- [OK] [tests/RunTests.hx:368] u == 'foo' ("foo" == "foo")
- [OK] [tests/RunTests.hx:370] c == 'Value=1' ("Value=1" == "Value=1")
- [OK] [tests/RunTests.hx:371] c == 1 (Value=1 == 1)
Cool, thanks ;)
Currently, abstracts are piped to
Assert.stringify
, which loses the type and just shows the runtime representation.