diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2019-01-06 00:54:18 +0300 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2019-01-06 11:27:26 +0300 |
commit | f7982974cd47b667436cf168ec28444dbbe7e82e (patch) | |
tree | bde391938ef26e65f518e9a509c9a154b8c9e059 | |
parent | 41f33ee2a4363b84d224b4920222d979cfc22680 (diff) |
rearrange tests to matching module tests
-rw-r--r-- | tests/test-list2.lua (renamed from tests/test-__pylib.lua) | 31 | ||||
-rw-r--r-- | tests/test-stringx2.lua | 20 | ||||
-rw-r--r-- | tests/test-text2.lua | 8 |
3 files changed, 32 insertions, 27 deletions
diff --git a/tests/test-__pylib.lua b/tests/test-list2.lua index 0d7bb19..174b1c7 100644 --- a/tests/test-__pylib.lua +++ b/tests/test-list2.lua @@ -1,11 +1,7 @@ --- test-pylib.lua local List = require 'pl.List' -local text = require 'pl.text' -local Template = text.Template local asserteq = require 'pl.test' . asserteq -l = List{10,20,30,40,50} -s = List{1,2,3,4,5} +local s = List{1,2,3,4,5} -- test using: lua pylist.lua local lst = List() @@ -19,7 +15,7 @@ lst:remove_value(40) asserteq (lst,List{10,20,11,30,50}) asserteq (lst:contains(11),true) asserteq (lst:contains(40),false) -local q=lst:pop() +local _ = lst:pop() asserteq( lst:index(30),4 ) asserteq( lst:count(10),1 ) lst:sort() @@ -37,7 +33,7 @@ asserteq (lst:slice(2,4),{20,30,40}) asserteq (lst:slice(-4,-2),{20,30,40}) lst = List.range(0,9) -seq = List{0,1,2,3,4,5,6,7,8,9} +local seq = List{0,1,2,3,4,5,6,7,8,9} asserteq(List.range(4),{1,2,3,4}) asserteq(List.range(0,8,2),{0,2,4,6,8}) asserteq(List.range(0,1,0.2),{0,0.2,0.4,0.6,0.8,1},1e-9) @@ -52,32 +48,13 @@ asserteq (List('abcd'),List{'a','b','c','d'}) local caps = List() List('abcd'):foreach(function(v) caps:append(v:upper()) end) asserteq (caps,List{'A','B','C','D'}) -ls = List{10,20,30,40} +local ls = List{10,20,30,40} ls:slice_assign(2,3,{21,31}) asserteq (ls , List{10,21,31,40}) asserteq (ls:remove(2), List{10,31,40}) asserteq (ls:clear(), List{}) asserteq (ls:len(), 0) --- strings --- -require 'pl.stringx'.import() ---> convenient! -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) assert (List.split(s) == List{'here', 'the', 'dog', 'is', 'just', 'a', 'dog'}) assert (List.split('foo;bar;baz', ';') == List{'foo', 'bar', 'baz'}) -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++++++++') - -t = Template('${here} is the $answer') -asserteq(t:substitute {here = 'one', answer = 'two'} , 'one is the two') - -asserteq (('hello dolly'):title() , 'Hello Dolly') -asserteq (('h bk bonzo TOK fred m'):title() , 'H Bk Bonzo Tok Fred M') diff --git a/tests/test-stringx2.lua b/tests/test-stringx2.lua new file mode 100644 index 0000000..c690e58 --- /dev/null +++ b/tests/test-stringx2.lua @@ -0,0 +1,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') diff --git a/tests/test-text2.lua b/tests/test-text2.lua new file mode 100644 index 0000000..c22edbe --- /dev/null +++ b/tests/test-text2.lua @@ -0,0 +1,8 @@ +local text = require 'pl.text' +local Template = text.Template +local asserteq = require 'pl.test' . asserteq + + +local t = Template('${here} is the $answer') +asserteq(t:substitute {here = 'one', answer = 'two'} , 'one is the two') + |