Created
January 12, 2021 22:08
-
-
Save Jannis/5c0998a6a8e75565b06f319b30c184d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The entry file of your WebAssembly module. | |
class ExpectTo<T> { | |
value: T | |
constructor(value: T) { | |
this.value = value | |
} | |
equal(other: T): void { | |
// use `log.fatal('{} !== {}', [this.value.toString(), other.toString()])` instead | |
assert( | |
this.value == other, | |
this.value.toString() + ' !== ' + other.toString() | |
) | |
} | |
} | |
class Expect<T> { | |
value: T | |
constructor(value: T) { | |
this.value = value | |
} | |
get to(): ExpectTo<T> { | |
return new ExpectTo(this.value) | |
} | |
} | |
function expect<T>(value: T): Expect<T> { | |
return new Expect(value) | |
} | |
class Foo { | |
value: i32 | |
constructor(value: i32) { | |
this.value = value | |
} | |
// Required for every type used with `expect` | |
toString(): string { | |
return 'Foo { value: ' + this.value.toString() + ' }' | |
} | |
} | |
export function add(a: i32, b: i32): i32 { | |
expect(new Foo(a)).to.equal(new Foo(b)) | |
expect(a).to.equal(b) | |
return a + b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment