-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlike_test.ts
91 lines (73 loc) · 2.49 KB
/
like_test.ts
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
import { assert, assertEquals } from "./deps.ts";
import { getLikeRegExp } from "./like.ts";
Deno.test("where name like 'abc.txt'", () => {
const regexp = getLikeRegExp("abc.txt");
/* Match */
assert("abc.txt".match(regexp));
/* Does not match */
assertEquals("a.txt".match(regexp), null);
assertEquals("abc_d.txt".match(regexp), null);
assertEquals("abc.tx".match(regexp), null);
});
Deno.test("where name like '%.txt'", () => {
const regexp = getLikeRegExp("%.txt");
/* Match */
assert("abc.txt".match(regexp));
assert("c.txt".match(regexp));
assert("ab_c.txt".match(regexp));
assert("ab_-\/*+ddc.txt".match(regexp));
/* Does not match */
assertEquals("abc.bin".match(regexp), null);
assertEquals(".txn".match(regexp), null);
assertEquals("abc_txt".match(regexp), null);
assertEquals("abc.!txt".match(regexp), null);
assertEquals("abc.txt_bin".match(regexp), null);
});
Deno.test("where name like '%.txt%'", () => {
const regexp = getLikeRegExp("%.txt%");
/* Match */
assert("abc.txt".match(regexp));
assert("c.txt".match(regexp));
assert("ab_c.txt".match(regexp));
assert("ab_-\/*+ddc.txt".match(regexp));
/* Does not match */
assertEquals("abc.bin".match(regexp), null);
assertEquals(".txn".match(regexp), null);
assertEquals("abc_txt".match(regexp), null);
});
Deno.test("where name like 'ab%txt'", () => {
const regexp = getLikeRegExp("ab%txt");
/* Match */
assert("abc.txt".match(regexp));
assert("abdef_.txt".match(regexp));
assert("ab_c.txt".match(regexp));
assert("ab_-\/*+ddc.txt".match(regexp));
/* Does not match */
assertEquals("abc.bin".match(regexp), null);
assertEquals("abc".match(regexp), null);
assertEquals("d_abc.txt".match(regexp), null);
assertEquals("abc.txt.".match(regexp), null);
assertEquals("abc.txt!".match(regexp), null);
});
Deno.test("where name like 'abc.%'", () => {
const regexp = getLikeRegExp("abc.%");
/* Match */
assert("abc.txt".match(regexp));
assert("abc.bin".match(regexp));
assert("abc.".match(regexp));
/* Does not match */
assertEquals("abc".match(regexp), null);
assertEquals("d".match(regexp), null);
assertEquals("abc?.".match(regexp), null);
});
Deno.test("where name like '%.%'", () => {
const regexp = getLikeRegExp("%.%");
/* Match */
assert("abc.txt".match(regexp));
assert("abc.bin".match(regexp));
assert("abc.".match(regexp));
assert(".".match(regexp));
assert(".txt".match(regexp));
/* Does not match */
assertEquals("abc".match(regexp), null);
});