test(stack, str) Added tests for stack and str modules.
h3rald h3rald@h3rald.com
Fri, 03 Jun 2016 11:37:58 +0200
5 files changed,
50 insertions(+),
8 deletions(-)
M
core/regex.nim
→
core/regex.nim
@@ -34,11 +34,12 @@ proc replace*(str, pattern, repl: string): string =
return replace(str, pattern, repl, "") proc `=~`*(str, r: string): seq[string] = - let m = r.search("(s)?/(.+?)?/(.+?)?/([mis]{0,3})") + let m = r.search("(s)?/(.+?)/((.+?)/)?([mis]{0,3})?") + # full match, s, reg, replace/, replace, flags if m[1] == "s" and m[3] != "": - return @[replace(str, m[2], m[3], m[4])] + return @[replace(str, m[2], m[4], m[5])] else: - return search(str, m[2], m[4]) + return search(str, m[2], m[5]) when isMainModule:
M
lib/stack.nim
→
lib/stack.nim
@@ -19,12 +19,11 @@ .symbol("dup") do (i: In):
i.push i.peek .symbol("dip") do (i: In): - let q = i.pop + var q = i.pop if not q.isQuotation: i.error errNoQuotation let v = i.pop - for item in q.qVal: - i.push item + i.unquote("<dip>", q) i.push v .symbol("swap") do (i: In):@@ -34,11 +33,11 @@ i.push a
i.push b .symbol("sip") do (i: In): - let a = i.pop + var a = i.pop let b = i.pop if a.isQuotation and b.isQuotation: i.push b - i.push a.qVal + i.unquote("<sip>", a) i.push b else: i.error(errIncorrect, "Two quotations are required on the stack")
A
tests/stack.min
@@ -0,0 +1,17 @@
+@test +#test + +"stack" describe + + (1 id 1 ==) assert + + (1 pop getstack () ==) assert + + (1 dup getstack (1 1) ==) assert + + (3 2 (1 +) dip + 6 ==) assert + + ((1) (2 swap append) sip concat (1 2 1) ==) assert + + report + clear
A
tests/str.min
@@ -0,0 +1,23 @@
+@test +#test + +"str" describe + + ("a,b,c" "," split ("a" "b" "c") ==) assert + + ("test #1" "[0-9]" search ("1") ==) assert + + ("This is test #1" "test #([0-9])" search ("test #1" "1") ==) assert + + ("This is a random string" "random" match true ==) assert + + ("something is not something else" "some" "any" replace "anything is not anything else" ==) assert + + ("MiNiM is a concatenative programming language" "/^minim/i" =~ ("MiNiM") ==) assert + + ("This is a difficult test" "s/difficult/simple/" =~ ("This is a simple test") ==) assert + + ("This is a DIFFICULT\n test" "s/difficult/simple/mis" =~ ("This is a simple\n test") ==) assert + + report + clear