deno.land / std@0.224.0 / collections / find_single_test.ts

find_single_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { findSingle } from "./find_single.ts";
function findSingleTest<I>( input: [Array<I>, (element: I) => boolean], expected: I | undefined, message?: string,) { const actual = findSingle(...input); assertEquals(actual, expected, message);}
Deno.test({ name: "findSingle() handles no mutation", fn() { const array = [1, 2, 3]; findSingle(array, (it) => it % 2 === 0);
assertEquals(array, [1, 2, 3]); },});
Deno.test({ name: "findSingle() handles empty input", fn() { findSingleTest( [[], (_) => true], undefined, ); },});
Deno.test({ name: "findSingle() handles only one element", fn() { findSingleTest( [[42], (_it) => true], 42, ); findSingleTest( [["foo"], (_it) => true], "foo", ); findSingleTest( [[null], (_it) => true], null, ); findSingleTest( [[undefined], (_it) => true], undefined, ); },});
Deno.test({ name: "findSingle() handles no matches", fn() { findSingleTest( [[9, 11, 13], (it) => it % 2 === 0], undefined, ); findSingleTest( [["foo", "bar"], (it) => it.startsWith("z")], undefined, ); findSingleTest( [[{ done: false }], (it) => it.done], undefined, ); },});
Deno.test({ name: "findSingle() handles only match", fn() { findSingleTest( [[9, 12, 13], (it) => it % 2 === 0], 12, ); findSingleTest( [["zap", "foo", "bar"], (it) => it.startsWith("z")], "zap", ); findSingleTest( [[{ done: false }, { done: true }], (it) => it.done], { done: true }, ); },});
Deno.test({ name: "findSingle() handles multiple matches", fn() { findSingleTest( [[9, 12, 13, 14], (it) => it % 2 === 0], undefined, ); findSingleTest( [["zap", "foo", "bar", "zee"], (it) => it.startsWith("z")], undefined, ); },});
std

Version Info

Tagged at
6 months ago