Skip to content

Commit

Permalink
feat(stdlib): Marshall
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Jul 8, 2022
1 parent 944f71c commit 8223491
Show file tree
Hide file tree
Showing 3 changed files with 657 additions and 0 deletions.
77 changes: 77 additions & 0 deletions compiler/test/stdlib/marshal.test.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * from "marshal"
import Bytes from "bytes"

assert unmarshal(marshal(void)) == void
assert unmarshal(marshal(true)) == true
assert unmarshal(marshal(42)) == 42
assert unmarshal(marshal(42l)) == 42l
assert unmarshal(marshal(42L)) == 42L
assert unmarshal(marshal(42.)) == 42.
assert unmarshal(marshal(42.f)) == 42.f
assert unmarshal(marshal(42.d)) == 42.d
assert unmarshal(marshal(1/3)) == 1/3
assert unmarshal(marshal('c')) == 'c'
assert unmarshal(marshal("unicode string 💯🌾🙏🏽")) ==
"unicode string 💯🌾🙏🏽"
assert unmarshal(
marshal(Bytes.fromString("unicode string 💯🌾🙏🏽"))
) ==
Bytes.fromString("unicode string 💯🌾🙏🏽")
assert unmarshal(marshal((14, false, "hi"))) == (14, false, "hi")
assert unmarshal(marshal([> 1, 2, 3])) == [> 1, 2, 3]
assert unmarshal(marshal([> 1l, 2l, 3l])) == [> 1l, 2l, 3l]
assert unmarshal(marshal([1, 2, 3])) == [1, 2, 3]
assert unmarshal(marshal([1l, 2l, 3l])) == [1l, 2l, 3l]

enum Foo<a> {
Bar,
Baz(a),
Qux(String, a),
Quux(Foo<a>),
}

assert unmarshal(marshal(Bar)) == Bar
assert unmarshal(marshal(Baz("baz"))) == Baz("baz")
assert unmarshal(marshal(Qux("qux", 42l))) == Qux("qux", 42l)
assert unmarshal(marshal(Quux(Qux("qux", 42l)))) == Quux(Qux("qux", 42l))

record Bing<a> {
bang: Void,
bop: a,
swish: (
String,
a
),
pow: Foo<Int32>,
}

assert unmarshal(
marshal(
{
bang: void,
bop: "bee",
swish: ("bit", "but"),
pow: Quux(Qux("qux", 42l)),
}
)
) ==
{ bang: void, bop: "bee", swish: ("bit", "but"), pow: Quux(Qux("qux", 42l)) }

let make5 = () => "five"

let closureTest = () => {
let val = make5()
let foo = () => val
assert unmarshal(marshal(foo))() == "five"
}

closureTest()

record Cyclic {
mut self: List<Cyclic>,
}

let cyclic = { self: [], }
cyclic.self = [cyclic, cyclic, cyclic]

assert unmarshal(marshal(cyclic)) == cyclic
1 change: 1 addition & 0 deletions compiler/test/suites/stdlib.re
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe("stdlib", ({test, testSkip}) => {
assertStdlib("int64.test");
assertStdlib("list.test");
assertStdlib("map.test");
assertStdlib("marshal.test");
assertStdlib("number.test");
assertStdlib("option.test");
assertStdlib("queue.test");
Expand Down
Loading

0 comments on commit 8223491

Please sign in to comment.