diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-08-25 14:00:06 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-08-25 14:00:06 -0700 |
commit | 2d3d88d9558c0445119d8cbae55e8b73937778a4 (patch) | |
tree | 22b13b824a4fe96c66bd5f97f2178ac614ee2c32 /090scenario_filesystem_test.mu | |
parent | 0a5e23018e1967fcccf20bbcd16b53e02c312346 (diff) | |
download | mu-2d3d88d9558c0445119d8cbae55e8b73937778a4.tar.gz |
3253 - writing to fake files in scenarios
High time I committed the part that works.
Diffstat (limited to '090scenario_filesystem_test.mu')
-rw-r--r-- | 090scenario_filesystem_test.mu | 31 |
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 +] |