diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2019-07-08 12:04:33 +0300 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2019-07-08 12:04:33 +0300 |
commit | 1ce00c1f53c0ee1df7c0caf73de6f030916fd477 (patch) | |
tree | 45c41d9684af4380db15ff862d2bbf6c84e153d9 | |
parent | 2e8d5232e7e8b80a52b73b98b83dd12044b11d6f (diff) |
weird split behavioursplits
added testcases describing current behaviour and comments on
python behaviour.
-rw-r--r-- | tests/test-stringx.lua | 7 | ||||
-rw-r--r-- | tests/test-utils.lua | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/tests/test-stringx.lua b/tests/test-stringx.lua index bc64341..daf778a 100644 --- a/tests/test-stringx.lua +++ b/tests/test-stringx.lua @@ -140,14 +140,15 @@ asserteq(T(stringx.replace('a.b', '.', '%d')), T('a%db')) -- split local split = stringx.split asserteq(split('', ''), {''}) -asserteq(split('', 'z'), {}) --FIX:intended and specified behavior? -asserteq(split('a', ''), {'a'}) --FIX:intended and specified behavior? -asserteq(split('a', 'a'), {''}) +asserteq(split('', 'z'), {}) --FIX:intended and specified behavior? --> python returns original string (as 1st entry in return table) +asserteq(split('a', ''), {'a'}) --FIX:intended and specified behavior? --> python errors out! +asserteq(split('a', 'a'), {''}) --> python returns {'', ''} -- stringx.split now follows the Python pattern, so it uses a substring, not a pattern. -- If you need to split on a pattern, use utils.split() -- asserteq(split('ab1cd23ef%d', '%d+'), {'ab', 'cd', 'ef%d'}) -- pattern chars -- note that leading space is ignored by the default asserteq(split(' 1 2 3 '),{'1','2','3'}) +asserteq(split(' 1 2 3 ',' '),{'','1','','','2','','','3',''}) asserteq(split('a*bb*c*ddd','*'),{'a','bb','c','ddd'}) asserteq(split('dog:fred:bonzo:alice',':',3), {'dog','fred','bonzo:alice'}) asserteq(split('dog:fred:bonzo:alice:',':',3), {'dog','fred','bonzo:alice:'}) diff --git a/tests/test-utils.lua b/tests/test-utils.lua index 90634e2..0141ede 100644 --- a/tests/test-utils.lua +++ b/tests/test-utils.lua @@ -89,6 +89,9 @@ local split = utils.split asserteq(split("hello dolly"),{"hello","dolly"}) asserteq(split("hello,dolly",","),{"hello","dolly"}) asserteq(split("hello,dolly,",","),{"hello","dolly"}) +asserteq(split(",dolly,",","),{"","dolly"}) +asserteq(split(",,",","),{"",""}) +asserteq(split(",",","),{}) local first,second = utils.splitv("hello:dolly",":") asserteq(T(first,second),T("hello","dolly")) |