summaryrefslogtreecommitdiff
path: root/Data/Libraries/Penlight/tests/test-stringx2.lua
blob: c690e58e7bcc20f1a901f2eb630d817ad080e757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local asserteq = require 'pl.test' . asserteq


-- strings ---
require 'pl.stringx'.import() ---> convenient!
local s = '123'
assert (s:isdigit())
assert (not s:isspace())
s = 'here the dog is just a dog'
assert (s:startswith('here'))
assert (s:endswith('dog'))
assert (s:count('dog') == 2)
s = '  here we go    '
asserteq (s:lstrip() , 'here we go    ')
asserteq (s:rstrip() , '  here we go')
asserteq (s:strip() , 'here we go')
asserteq (('hello'):center(20,'+') , '+++++++hello++++++++')

asserteq (('hello dolly'):title() , 'Hello Dolly')
asserteq (('h bk bonzo TOK fred m'):title() , 'H Bk Bonzo Tok Fred M')