-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.test.gr
45 lines (38 loc) · 1.1 KB
/
string.test.gr
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
import {
words,
unwords,
lines,
unlines,
every,
some,
containsChar,
map,
} from "./string"
import { isDigit } from "./char"
let w = "grain is awesome!"
assert words(w) == [> "grain", "is", "awesome!"]
assert unwords(words(w)) == w
let l = "hello\n\nworld\r\nbob\n\rthis is a sentence\n\ralice"
assert lines(l) ==
[> "hello", "", "world", "bob", "this is a sentence", "alice"]
assert unlines(lines(l)) == "hello\n\nworld\nbob\nthis is a sentence\nalice"
assert every(isDigit, "a string 0-9") == false
assert every(isDigit, "0123456789") == true
assert every(c => c == 'c', "ccccc") == true
assert every(c => c == 'c', "ccacc") == false
assert some(isDigit, "a string 0-9") == true
assert some(isDigit, "0123456789") == true
assert some(isDigit, "a string without digits") == false
assert some(c => c == 'c', "aacbb") == true
assert some(c => c == 'c', "CaxyZCC") == false
assert containsChar('c', "no C here") == false
assert containsChar('c', "now c here") == true
let tea = "I'm a teapot"
let teapot = "I'm a TeapoT"
assert map(c => {
match (c) {
't' => 'T',
_ => c,
}
}, tea) ==
teapot