Skip to content

Instantly share code, notes, and snippets.

@Jannis
Created January 12, 2021 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jannis/5c0998a6a8e75565b06f319b30c184d2 to your computer and use it in GitHub Desktop.
Save Jannis/5c0998a6a8e75565b06f319b30c184d2 to your computer and use it in GitHub Desktop.
// 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