2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assert } from "@std/assert";
|
2022-09-30 07:27:11 +00:00
|
|
|
import { validate } from "./v4.ts";
|
2020-08-30 18:39:51 +00:00
|
|
|
|
2023-12-20 21:52:37 +00:00
|
|
|
Deno.test("validate() checks if a string is a valid v4 UUID", () => {
|
2022-09-30 07:27:11 +00:00
|
|
|
const u = crypto.randomUUID();
|
2021-02-02 03:16:27 +00:00
|
|
|
const t = "84fb7824-b951-490e-8afd-0c13228a8282";
|
|
|
|
const n = "84fb7824-b951-490g-8afd-0c13228a8282";
|
2020-08-30 18:39:51 +00:00
|
|
|
|
2021-02-02 03:16:27 +00:00
|
|
|
assert(validate(u), `generated ${u} should be valid`);
|
|
|
|
assert(validate(t), `${t} should be valid`);
|
|
|
|
assert(!validate(n), `${n} should not be valid`);
|
2020-08-30 18:39:51 +00:00
|
|
|
});
|