Derive tag union encoders

This commit is contained in:
Ayaz Hafiz 2022-07-12 16:01:31 -04:00
parent 9aa3cb8d33
commit 1cf1e114be
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 346 additions and 5 deletions

View file

@ -494,3 +494,27 @@ fn encode_derived_nested_record_string() {
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn encode_derived_tag_one_payload_string() {
assert_evals_to!(
indoc!(
r#"
app "test"
imports [Encode.{ toEncoder }, Json]
provides [main] to "./platform"
main =
x : [A Str]
x = A "foo"
result = Str.fromUtf8 (Encode.toBytes x Json.format)
when result is
Ok s -> s
_ -> "<bad>"
"#
),
RocStr::from(r#"{"A":["foo",]}"#),
RocStr
)
}