about summary refs log tree commit diff stats
path: root/mu.arc.t
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-12-19 18:57:11 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-12-19 19:03:35 -0800
commitf45ea0cb5c4109bc573da1d0b2289b451a29b068 (patch)
treed71a8c0ad5611e0e4c46328177bccc41aa317357 /mu.arc.t
parent4fc54b3d98023d36387f009de23f9ea03a68d939 (diff)
downloadmu-f45ea0cb5c4109bc573da1d0b2289b451a29b068.tar.gz
441 - string 'find-next' for characters
Diffstat (limited to 'mu.arc.t')
-rw-r--r--mu.arc.t88
1 files changed, 88 insertions, 0 deletions
diff --git a/mu.arc.t b/mu.arc.t
index 1c5cc132..2e284b7d 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -3321,6 +3321,94 @@
 (if (~memory-contains-array memory*.5 "hello, abc, def, and ghi!")
   (prn "F - 'interpolate' splices in any number of strings"))
 
+(reset)
+(new-trace "string-find-next")
+(add-code '((function main [
+              (1:string-address <- new "a/b")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 0:literal)
+             ])))
+(run 'main)
+(if (~is memory*.2 1)
+  (prn "F - 'find-next' finds first location of a character"))
+
+(reset)
+(new-trace "string-find-next-empty")
+(add-code '((function main [
+              (1:string-address <- new "")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 0:literal)
+             ])))
+(run 'main)
+(each routine completed-routines*
+  (aif rep.routine!error (prn "error - " it)))
+(if (~is memory*.2 0)
+  (prn "F - 'find-next' finds first location of a character"))
+
+(reset)
+(new-trace "string-find-next-initial")
+(add-code '((function main [
+              (1:string-address <- new "/abc")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 0:literal)
+             ])))
+(run 'main)
+(if (~is memory*.2 0)
+  (prn "F - 'find-next' handles prefix match"))
+
+(reset)
+(new-trace "string-find-next-final")
+(add-code '((function main [
+              (1:string-address <- new "abc/")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 0:literal)
+             ])))
+(run 'main)
+;? (prn memory*.2)
+(if (~is memory*.2 3)
+  (prn "F - 'find-next' handles suffix match"))
+
+(reset)
+(new-trace "string-find-next-missing")
+(add-code '((function main [
+              (1:string-address <- new "abc")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 0:literal)
+             ])))
+(run 'main)
+;? (prn memory*.2)
+(if (~is memory*.2 3)
+  (prn "F - 'find-next' handles no match"))
+
+(reset)
+(new-trace "string-find-next-invalid-index")
+(add-code '((function main [
+              (1:string-address <- new "abc")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 4:literal)
+             ])))
+;? (= dump-trace* (obj whitelist '("run")))
+(run 'main)
+(each routine completed-routines*
+  (aif rep.routine!error (prn "error - " it)))
+;? (prn memory*.2)
+(if (~is memory*.2 4)
+  (prn "F - 'find-next' skips invalid index (past end of string)"))
+
+(reset)
+(new-trace "string-find-next-first")
+(add-code '((function main [
+              (1:string-address <- new "ab/c/")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 0:literal)
+             ])))
+(run 'main)
+(if (~is memory*.2 2)
+  (prn "F - 'find-next' finds first of multiple options"))
+
+(reset)
+(new-trace "string-find-next-second")
+(add-code '((function main [
+              (1:string-address <- new "ab/c/")
+              (2:integer <- find-next 1:string-address ((#\/ literal)) 3:literal)
+             ])))
+(run 'main)
+(if (~is memory*.2 4)
+  (prn "F - 'find-next' finds second of multiple options"))
+
 )  ; section 100 for string utilities
 
 (reset)