about summary refs log tree commit diff stats
path: root/090scenario_filesystem_test.mu
diff options
context:
space:
mode:
Diffstat (limited to '090scenario_filesystem_test.mu')
-rw-r--r--090scenario_filesystem_test.mu31
1 files changed, 31 insertions, 0 deletions
diff --git a/090scenario_filesystem_test.mu b/090scenario_filesystem_test.mu
index 4d4624eb..de93a2d9 100644
--- a/090scenario_filesystem_test.mu
+++ b/090scenario_filesystem_test.mu
@@ -21,3 +21,34 @@ scenario read-from-fake-file [
     5 <- 1  # eof
   ]
 ]
+
+scenario write-to-fake-file [
+  local-scope
+  assume-filesystem [
+    #[a] <- []
+  ]
+  sink:address:sink:character, writer:number/routine <- start-writing filesystem:address:filesystem, [a]
+  sink <- write sink, 120/x
+  sink <- write sink, 121/y
+  close sink
+  wait-for-routine writer
+  contents-read-back:address:array:character <- slurp filesystem, [a]
+  10:boolean/raw <- equal contents-read-back, [xy]
+  memory-should-contain [
+    10 <- 1  # file contents read back exactly match what was written
+  ]
+]
+
+def slurp fs:address:filesystem, filename:address:array:character -> contents:address:array:character [
+  local-scope
+  load-ingredients
+  source:address:source:character <- start-reading fs, filename
+  buf:address:buffer <- new-buffer 30/capacity
+  {
+    c:character, done?:boolean, source <- read source
+    break-if done?
+    buf <- append buf, c
+    loop
+  }
+  contents <- buffer-to-array buf
+]