Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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