Skip to content

Commit c784ed1

Browse files
committed
user-defined errors
1 parent d81826f commit c784ed1

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

.github/workflows/nodejs.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Node.js CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout the repository
12+
uses: actions/checkout@v4
13+
14+
- name: Install Wasmtime
15+
uses: jcbhmr/setup-wasmtime@v2
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v2
19+
20+
- name: Install dependencies
21+
if: steps.node-cache.outputs.cache-hit != 'true'
22+
run: yarn
23+
24+
- name: Build tests
25+
run: yarn run build:test
26+
27+
- name: Perform tests
28+
run: yarn run test:wasmtime

assembly/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { rainbow } from "as-rainbow";
22
import { TestGroup } from "./src/group";
33
import { Expectation } from "./src/expectation";
4-
import { colorText, formatTime } from "./util";
4+
import { formatTime } from "./util";
55
import { stringify } from "as-console/assembly";
66

77
/**

assembly/src/expectation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Verdict } from "..";
55

66
export class Expectation<T> extends Node {
77
public verdict: Verdict = Verdict.Unreachable;
8-
public left: T;
8+
private left: T;
99
private _left: string | null = null;
10-
public right: u64 = 0;
10+
private right: u64 = 0;
1111
private _right: string | null = null;
1212
private _not: boolean = false;
1313
private op: string = "=";
@@ -44,7 +44,7 @@ export class Expectation<T> extends Node {
4444
* @returns - void
4545
*/
4646
toBeGreaterThan(value: T): void {
47-
if (!isInteger<T>() && !isFloat<T>()) throw new Error("toBeGreaterThan() can only be used on number types. Received " + nameof<T>() + " instead!");
47+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeGreaterThan() can only be used on number types!");
4848

4949
this.verdict = this.left > value ? Verdict.Ok : Verdict.Fail;
5050
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
@@ -63,7 +63,7 @@ export class Expectation<T> extends Node {
6363
* @returns - void
6464
*/
6565
toBeGreaterOrEqualTo(value: T): void {
66-
if (!isInteger<T>() && !isFloat<T>()) throw new Error("toBeGreaterOrEqualTo() can only be used on number types. Received " + nameof<T>() + " instead!");
66+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeGreaterOrEqualTo() can only be used on number types!");
6767

6868
this.verdict = this.left >= value ? Verdict.Ok : Verdict.Fail;
6969
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
@@ -82,7 +82,7 @@ export class Expectation<T> extends Node {
8282
* @returns - void
8383
*/
8484
toBeLessThan(value: T): void {
85-
if (!isInteger<T>() && !isFloat<T>()) throw new Error("toBeLessThan() can only be used on number types. Received " + nameof<T>() + " instead!");
85+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeLessThan() can only be used on number types!");
8686

8787
this.verdict = this.left < value ? Verdict.Ok : Verdict.Fail;
8888
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
@@ -101,7 +101,7 @@ export class Expectation<T> extends Node {
101101
* @returns - void
102102
*/
103103
toBeLessThanOrEqualTo(value: T): void {
104-
if (!isInteger<T>() && !isFloat<T>()) throw new Error("toBeLessThanOrEqualTo() can only be used on number types. Received " + nameof<T>() + " instead!");
104+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeLessThanOrEqualTo() can only be used on number types!");
105105

106106
this.verdict = this.left <= value ? Verdict.Ok : Verdict.Fail;
107107
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));

assembly/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
run
1111
} from ".";
1212

13-
1413
// Shared setup for all tests (executed once before all tests)
1514
beforeAll(() => {
1615
log("Setting up test environment...");

0 commit comments

Comments
 (0)