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-11-27 00:34:29 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-27 00:34:29 -0800
commit6fbdc6c853631108720b4928c6e21e057d93081a (patch)
treef710606e05c4779c083747f6fb5f94191c345824 /mu.arc.t
parentb3898dc5c455cfd6ccf71e3b52bf4759f162b04d (diff)
downloadmu-6fbdc6c853631108720b4928c6e21e057d93081a.tar.gz
342 - strcat
Diffstat (limited to 'mu.arc.t')
-rw-r--r--mu.arc.t30
1 files changed, 29 insertions, 1 deletions
diff --git a/mu.arc.t b/mu.arc.t
index 609498fe..485c2634 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -2946,6 +2946,34 @@
           (~is #\l (memory* (+ before 3)))
           (~is #\l (memory* (+ before 4)))
           (~is #\o (memory* (+ before 5))))
-    (prn "F - 'new' initializes allocated memory to string literal")))
+    (prn "F - 'new' initializes allocated memory to string literal"))
+
+; helper
+(def memory-contains (addr value)
+  (and (is memory*.addr len.value)
+       (loop (addr (+ addr 1)
+              idx  0)
+         (if (> addr len.value)
+               t
+             (~is memory*.addr value.idx)
+               (do1 nil
+                    (prn "@addr should contain @value.idx but contains @memory*.addr"))
+             :else
+               (recur (+ addr 1) (+ idx 1))))))
+
+  ; test the helper
+  (if (~memory-contains before "hello")
+    (prn "F - 'memory-contains' helper is broken")))
+
+(reset)
+(new-trace "strcat")
+(add-code '((def main [
+              ((1 string-address) <- new "hello,")
+              ((2 string-address) <- new " world!")
+              ((3 string-address) <- strcat (1 string-address) (2 string-address))
+             ])))
+(run 'main)
+(if (~memory-contains memory*.3 "hello, world!")
+  (prn "F - 'strcat' concatenates strings"))
 
 (reset)  ; end file with this to persist the trace for the final test