summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-01-19 07:37:04 -0500
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-01-19 07:37:04 -0500
commit04699a7587dc83d37bd5e1618409cac11dc04f75 (patch)
treef7d405b07d0a2e0e41844ce8ff3e1073f178106b
parent260ab8b01bb4daa0488232cada81d3a5befa8e91 (diff)
downloadNim-04699a7587dc83d37bd5e1618409cac11dc04f75.tar.gz
Add perl split tests
-rw-r--r--test/split.nim24
1 files changed, 23 insertions, 1 deletions
diff --git a/test/split.nim b/test/split.nim
index 184b5f9e2..9f9ebef36 100644
--- a/test/split.nim
+++ b/test/split.nim
@@ -1,4 +1,4 @@
-import unittest
+import unittest, strutils
 include nre
 
 suite "string splitting":
@@ -16,3 +16,25 @@ suite "string splitting":
     check("123".split(re"", maxsplit = 1) == @["1", "23"])
     check("123".split(re"", maxsplit = 0) == @["123"])
     check("123".split(re"", maxsplit = -1) == @["1", "2", "3"])
+
+  test "perl split tests":
+    check("forty-two"                    .split(re"")      .join(",") == "f,o,r,t,y,-,t,w,o")
+    check("forty-two"                    .split(re"", 3)   .join(",") == "f,o,rty-two")
+    check("split this string"            .split(re" ")     .join(",") == "split,this,string")
+    check("split this string"            .split(re" ", 2)  .join(",") == "split,this string")
+    check("try$this$string"              .split(re"\$")    .join(",") == "try,this,string")
+    check("try$this$string"              .split(re"\$", 2) .join(",") == "try,this$string")
+    check("comma, separated, values"     .split(re", ")    .join("|") == "comma|separated|values")
+    check("comma, separated, values"     .split(re", ", 2) .join("|") == "comma|separated, values")
+    check("Perl6::Camelia::Test"         .split(re"::")    .join(",") == "Perl6,Camelia,Test")
+    check("Perl6::Camelia::Test"         .split(re"::", 2) .join(",") == "Perl6,Camelia::Test")
+    check("split,me,please"              .split(re",")     .join("|") == "split|me|please")
+    check("split,me,please"              .split(re",", 2)  .join("|") == "split|me,please")
+    check("Hello World    Goodbye   Mars".split(re"\s+")   .join(",") == "Hello,World,Goodbye,Mars")
+    check("Hello World    Goodbye   Mars".split(re"\s+", 3).join(",") == "Hello,World,Goodbye   Mars")
+    check("Hello test"                   .split(re"(\s+)") .join(",") == "Hello, ,test")
+    check("this will be split"           .split(re" ")     .join(",") == "this,will,be,split")
+    check("this will be split"           .split(re" ", 3)  .join(",") == "this,will,be split")
+    check("a.b"                          .split(re"\.")    .join(",") == "a,b")
+    check(""                             .split(re"")      .len       == 0)
+    check(":"                            .split(re"")      .len       == 1)