forked from svelterust/vom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence_test.v
57 lines (50 loc) · 1.3 KB
/
sequence_test.v
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
module vom
fn test_tuple() ! {
parser := tuple([tag('#'), take(5), tag(' :D')])
rest, output, len := parser('#hello :D...')!
assert output == ['#', 'hello', ' :D']
assert rest == '...'
assert len == 9
}
fn test_delimited() ! {
parser := delimited(tag('<h1>'), take(6), tag('</h1>'))
rest, output, len := parser('<h1>Hello!</h1>...')!
assert output == 'Hello!'
assert rest == '...'
assert len == 15
}
fn test_pair() ! {
parser := pair(tag('vlang'), tag('awesome'))
rest, output, len := parser('vlangawesome!')!
assert output == ['vlang', 'awesome']
assert rest == '!'
assert len == 12
}
fn test_separated_pair() ! {
parser := separated_pair(take(5), tag(','), take(7))
rest, output, len := parser('vlang,awesome!')!
assert output == ['vlang', 'awesome']
assert rest == '!'
assert len == 13
}
fn test_preceded() ! {
parser := preceded(tag('- '), take(4))
rest, output, len := parser('- list!')!
assert output == 'list'
assert rest == '!'
assert len == 6
}
fn test_terminated() ! {
parser := terminated(take(2), tag(' {'))
rest, output, len := parser('fn {}')!
assert output == 'fn'
assert rest == '}'
assert len == 4
}
fn test_concat() ! {
parser := concat([tag('ab'), tag('bd'), tag('c')])
rest, output, len := parser('abbdc,dd')!
assert output == 'abbdc'
assert rest == ',dd'
assert len == 5
}