mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Add gen tests for derived tag encoders
This commit is contained in:
parent
2ca86c84dc
commit
276bb173a0
1 changed files with 76 additions and 0 deletions
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue