Support deriving Decode for opaques

This commit is contained in:
Ayaz Hafiz 2022-10-18 15:06:10 -05:00
parent 61ba59de07
commit 1d885c4ab2
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 115 additions and 2 deletions

View file

@ -791,6 +791,32 @@ fn decode_use_stdlib() {
)
}
#[test]
#[cfg(all(
any(feature = "gen-llvm", feature = "gen-wasm"),
not(debug_assertions) // https://github.com/roc-lang/roc/issues/3898
))]
fn decode_derive_decoder_for_opaque() {
assert_evals_to!(
indoc!(
r#"
app "test"
imports [Json]
provides [main] to "./platform"
HelloWorld := { a: Str } has [Decoding]
main =
when Str.toUtf8 """{"a":"Hello, World!"}""" |> Decode.fromBytes Json.fromUtf8 is
Ok (@HelloWorld {a}) -> a
_ -> "FAIL"
"#
),
RocStr::from(r#"Hello, World!"#),
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn decode_use_stdlib_json_list() {