Skip to content

Commit

Permalink
Option works!
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Sep 1, 2024
1 parent 004c748 commit 359c6fa
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions commitlint/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ function fn(p: C) {
}
}

class None {}
class Value<T> {
value: T;

constructor(val: T) {
this.value = val;
}
}
type Option<T> = None | Value<T>;

test("testing DUs", () => {
let foo = new A();
expect(foo.x).toBe("hello");
Expand All @@ -63,3 +73,19 @@ test("testing DUs", () => {
let bar2 = fn(bar);
expect(bar2).toBe("1");
});

function fnO(option: Option<number>) {
if (option instanceof None) {
return "NAH";
} else {
let val = option.value;
return (val * val).toString();
}
}

test("testing Options", () => {
let foo: Option<number> = new None();
let bar: Option<number> = new Value(2);
expect(fnO(foo)).toBe("NAH");
expect(fnO(bar)).toBe("4");
});

0 comments on commit 359c6fa

Please sign in to comment.