forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.lua
More file actions
70 lines (58 loc) · 2.66 KB
/
Copy pathstring.lua
File metadata and controls
70 lines (58 loc) · 2.66 KB
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
-- tests string functions added by dfhack.lua
function test.startswith()
expect.true_(('abcd'):startswith(''))
expect.true_(('abcd'):startswith('abc'))
expect.false_(('abcd'):startswith('bcd'))
expect.false_(('abcd'):startswith('abcde'))
expect.true_((''):startswith(''))
expect.false_((''):startswith('a'))
expect.false_(('str'):startswith('.'),
'ensure we match literals, not patterns')
end
function test.endswith()
expect.true_(('abcd'):endswith(''))
expect.true_(('abcd'):endswith('bcd'))
expect.false_(('abcd'):endswith('abc'))
expect.false_(('abcd'):endswith('zabcd'))
expect.true_((''):endswith(''))
expect.false_((''):endswith('a'))
expect.false_(('str'):endswith('.'),
'ensure we match literals, not patterns')
end
function test.split()
expect.table_eq({'hello','world'}, ('hello world'):split())
expect.table_eq({'hello','','world'}, ('hello world'):split())
expect.table_eq({'hello','world'}, ('hello world'):split(' +'))
expect.table_eq({'hello','world'}, ('hello.world'):split('.', true),
'ensure literal interpretation when plain is true')
expect.table_eq({'', '', '', ''}, ('abc'):split('.'),
'ensure pattern interpretation when plain is false')
-- we don't actually care what this returns, just that it does return
expect.true_(('hello world'):split('.*'), 'ensure no infinite loop')
expect.table_eq({'hello ', ' world'}, ('hello , world'):split(','),
'ensure spaces are kept when they are not the delimiter')
expect.table_eq({'hello'}, ('hello'):split(), 'no delimiter')
end
function test.trim()
expect.eq('hello', ('hello'):trim())
expect.eq('hello', (' hello'):trim())
expect.eq('hello', ('hello '):trim())
expect.eq('hello', (' hello '):trim())
expect.eq('', (''):trim())
expect.eq('', (' '):trim())
expect.eq('', (' \t \n \v '):trim())
expect.eq('hel lo', (' hel lo '):trim(), 'keep interior spaces')
expect.eq('hel \n lo', (' hel \n lo '):trim(),
'keep interior spaces across newlines')
end
function test.wrap()
expect.eq('hello world', ('hello world'):wrap(20))
expect.eq('hello world', ('hello world'):wrap(20))
expect.eq('hello world\nhow are you?',('hello world how are you?'):wrap(12))
expect.eq('hello\nworld', ('hello world'):wrap(5))
expect.eq('hello\nworld', ('hello world'):wrap(5))
expect.eq('hello\nworld', ('hello world'):wrap(8))
expect.eq('hel\nlo\nwor\nld', ('hello world'):wrap(3))
expect.eq('hel\nloo\nwor\nldo', ('helloo worldo'):wrap(3))
expect.eq('', (''):wrap())
end