summaryrefslogtreecommitdiff
path: root/lib/std/test/fmt.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-24 09:53:47 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-24 09:53:47 -0700
commit0b58f43116b059473c24999e488f6471123dcdf8 (patch)
tree1cf458166f5459b2dd00ee45fa5bb199e02ab39c /lib/std/test/fmt.myr
parentb319e47808ef74e3ed23a624ac9965551a7f51b5 (diff)
downloadmc-0b58f43116b059473c24999e488f6471123dcdf8.tar.gz
Descend into complex structures to print them.
There are some really ugly hacks here, but it works.
Diffstat (limited to 'lib/std/test/fmt.myr')
-rw-r--r--lib/std/test/fmt.myr50
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/std/test/fmt.myr b/lib/std/test/fmt.myr
index 92d7850..5c600d3 100644
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -1,7 +1,20 @@
use std
pkg =
- type pair
+ type blah
+ type blah = struct
+ a : byte[:]
+ b : int
+ ;;
+ type u = union
+ `First
+ `Second int
+ `Third byte[:]
+ ;;
+ type pair = struct
+ x : int16
+ y : int32
+ ;;
;;
const check = {expected, fmt, args : ...
@@ -15,12 +28,17 @@ const check = {expected, fmt, args : ...
;;
}
+
const main = {
builtins()
installed()
}
const builtins = {
+ var s : blah
+ var m : u
+
+ /* basic types */
check(" abcd", "{w=10}", "abcd")
check("00000bdcae", "{p=0,w=10}", "bdcae")
check("abcdefghijkl", "{p=0,w=10}", "abcdefghijkl")
@@ -43,6 +61,26 @@ const builtins = {
check("666.91972", "{}", 666.91972)
check("1.0001", "{}", 1.0001)
check("0.000101323461002", "{}", 0.000101323461002)
+
+ /*
+ compound types, followed by single value to make
+ sure we consume the right byte count.
+ */
+ check("(1, 2) true", "{} {}", (1, 2), true)
+ check("(1,) true", "{} {}", (1,), true)
+
+ s = [.a="foo true", .b=123]
+ /*check("[.a=foo, .b=123] true", "{} {}", s, true) BUSTED */
+
+ m = `First
+ check("`First true", "{} {}", m, true)
+ m = `Second 123
+ check("`Second 123 true", "{} {}", m, true)
+ m = `Third "foo"
+ check("`Third foo true", "{} {}", m, true)
+
+ check("[1, 2, 3] true", "{} {}", [1,2,3], true)
+ check("[1, 2, 3] true", "{} {}", [1,2,3][:], true)
}
const installed = {
@@ -72,18 +110,18 @@ const installed = {
check("formatted a pair: [-10, -10] x=foo", "{x=foo}", p)
check("formatted a pair: [-10, -10] y present", "{y}", p)
check("formatted a pair: [-10, -10] x=bar y present", "{x=bar,y}", p)
+ check("formatted a pair: [-10, -10] x=bar y present", "{x=bar,y}", p)
/* multiple values */
check("formatted a pair: [-10, -10], formatted a pair: [-10, -10]", "{}, {}", p, p)
/* multiple values of different types */
check("11, formatted a pair: [-10, -10], formatted an int: 111", "{}, {}, {}", 11 castto(byte), p, 111)
-}
+ /* in aggregates */
+ check("[formatted a pair: [-10, -10]]", "{}", [p])
+ check("[formatted a pair: [-10, -10]]", "{}", [p][:])
-type pair = struct
- x : int16
- y : int32
-;;
+}
const intfmt = {sb, ap, opts
var x : int