Add gen tests for derived tag encoders

This commit is contained in:
Ayaz Hafiz 2022-07-12 16:48:58 -04:00
parent 2ca86c84dc
commit 276bb173a0
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -518,3 +518,79 @@ fn encode_derived_tag_one_payload_string() {
RocStr RocStr
) )
} }
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn encode_derived_tag_two_payloads_string() {
assert_evals_to!(
indoc!(
r#"
app "test"
imports [Encode.{ toEncoder }, Json]
provides [main] to "./platform"
main =
x : [A Str Str]
x = A "foo" "bar"
result = Str.fromUtf8 (Encode.toBytes x Json.format)
when result is
Ok s -> s
_ -> "<bad>"
"#
),
RocStr::from(r#"{"A":["foo","bar",]}"#),
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn encode_derived_nested_tag_string() {
assert_evals_to!(
indoc!(
r#"
app "test"
imports [Encode.{ toEncoder }, Json]
provides [main] to "./platform"
main =
x : [A [B Str Str]]
x = A (B "foo" "bar")
encoded = Encode.toBytes x Json.format
result = Str.fromUtf8 encoded
when result is
Ok s -> s
_ -> "<bad>"
"#
),
RocStr::from(r#"{"a":{"b":"bar",},}"#),
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn encode_derived_nested_record_tag_record() {
assert_evals_to!(
indoc!(
r#"
app "test"
imports [Encode.{ toEncoder }, Json]
provides [main] to "./platform"
main =
x : {a: [B {c: Str}]}
x = {a: (B ({c: "foo"}))}
encoded = Encode.toBytes x Json.format
result = Str.fromUtf8 encoded
when result is
Ok s -> s
_ -> "<bad>"
"#
),
RocStr::from(r#"{"a":{"b":"bar",},}"#),
RocStr
)
}