forked from ExtraMojo/ExtraMojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_regex.mojo
61 lines (45 loc) · 1.59 KB
/
test_regex.mojo
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
from ExtraMojo.regex.simple_re import *
from testing import *
fn main() raises:
test_start_anchor()
test_end_anchor()
test_dot()
test_star()
test_literal()
test_dot_star()
test_all()
print("SUCCESS")
fn test_start_anchor() raises:
var re = "^cat"
assert_true(is_match(re, "cats of a feather"))
assert_false(is_match(re, "bird cats of a cat"))
fn test_end_anchor() raises:
var re = "what$"
assert_true(is_match(re, "It is what"))
assert_false(is_match(re, "what is in the box"))
fn test_dot() raises:
var re = "w.t"
assert_true(is_match(re, "Is that a witty remark?"))
assert_false(is_match(re, "wt is that what thing there"))
fn test_star() raises:
var re = "wha*"
assert_true(is_match(re, "what am I doing here"))
assert_true(is_match(re, "whaaaaaaat am I doing here"))
assert_true(is_match(re, "wht am I doing here"))
assert_false(is_match(re, "wt am I doing here"))
fn test_literal() raises:
var re = "ACTG"
assert_true(is_match(re, "TGGGACTGCCCACTG"))
assert_true(is_match(re, "CTGGGACGCCCACTG"))
assert_false(is_match(re, "CTGGGACGCCCACG"))
fn test_dot_star() raises:
var re = "STAR.*"
assert_true(is_match(re, "STAR"))
assert_true(is_match(re, "I'M A STAR"))
assert_true(is_match(re, "I'M A STARXXXXXXX"))
assert_true(is_match(re, "I'M A STARS"))
assert_true(is_match(re, "I'M A STAR!!!!!"))
assert_false(is_match(re, "I'm not a STArsss"))
fn test_all() raises:
assert_true(is_match("^cat.*$", "catsssssss"))
assert_false(is_match("^cat.*$", "many catsssssss"))