mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
38 lines
715 B
TypeScript
38 lines
715 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import { AssertionError, assertThrows } from "./mod.ts";
|
|
import { assertNever } from "./unstable_never.ts";
|
|
|
|
Deno.test("assertNever: exhaustiveness check", () => {
|
|
type Kinds = "A" | "B";
|
|
|
|
function doA() {
|
|
// ...
|
|
}
|
|
|
|
function doB() {
|
|
// ...
|
|
}
|
|
|
|
function handleKind(kind: Kinds) {
|
|
switch (kind) {
|
|
case "A":
|
|
doA();
|
|
break;
|
|
case "B":
|
|
doB();
|
|
break;
|
|
default:
|
|
assertNever(kind);
|
|
}
|
|
}
|
|
|
|
handleKind("A");
|
|
handleKind("B");
|
|
});
|
|
|
|
Deno.test("assertNever throws AssertionError", () => {
|
|
assertThrows(() => {
|
|
assertNever(42 as never);
|
|
}, AssertionError);
|
|
});
|