mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-01 21:40:58 +00:00
test_gen: replace stdlib Json with inline implementation
Towards the goal of removing Json from stdlib, this change replaces usage of TotallyNotJson in test_gen/gen_abilities with a simple usable inline implementation of Encoder/DecoderFormatting. Similarly, the use of TotallyNotJson in test_reporting is not necessary at all and is replaced with a Decoder that wouldn't actually work, but which does compile.
This commit is contained in:
parent
05ab018380
commit
0faa1d5f20
8 changed files with 679 additions and 278 deletions
|
|
@ -11401,10 +11401,50 @@ In roc, functions are always written as a lambda, like{}
|
|||
r#"
|
||||
app "test" imports [] provides [main] to "./platform"
|
||||
|
||||
import TotallyNotJson
|
||||
ErrDecoder := {} implements [DecoderFormatting {
|
||||
u8: decodeU8,
|
||||
u16: decodeU16,
|
||||
u32: decodeU32,
|
||||
u64: decodeU64,
|
||||
u128: decodeU128,
|
||||
i8: decodeI8,
|
||||
i16: decodeI16,
|
||||
i32: decodeI32,
|
||||
i64: decodeI64,
|
||||
i128: decodeI128,
|
||||
f32: decodeF32,
|
||||
f64: decodeF64,
|
||||
dec: decodeDec,
|
||||
bool: decodeBool,
|
||||
string: decodeString,
|
||||
list: decodeList,
|
||||
record: decodeRecord,
|
||||
tuple: decodeTuple,
|
||||
}]
|
||||
decodeU8 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeU16 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeU32 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeU64 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeU128 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeI8 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeI16 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeI32 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeI64 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeI128 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeF32 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeF64 = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeDec = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeBool = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeString = Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeList : Decoder elem (ErrDecoder) -> Decoder (List elem) (ErrDecoder)
|
||||
decodeList = \_ -> Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeRecord : state, (state, Str -> [Keep (Decoder state (ErrDecoder)), Skip]), (state, (ErrDecoder) -> Result val DecodeError) -> Decoder val (ErrDecoder)
|
||||
decodeRecord =\_, _, _ -> Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
decodeTuple : state, (state, U64 -> [Next (Decoder state (ErrDecoder)), TooLong]), (state -> Result val DecodeError) -> Decoder val (ErrDecoder)
|
||||
decodeTuple = \_, _, _ -> Decode.custom \rest, @ErrDecoder {} -> {result: Err TooShort, rest}
|
||||
|
||||
main =
|
||||
decoded = Str.toUtf8 "{\"first\":\"ab\",\"second\":\"cd\"}" |> Decode.fromBytes TotallyNotJson.json
|
||||
decoded = Str.toUtf8 "{\"first\":\"ab\",\"second\":\"cd\"}" |> Decode.fromBytes (@ErrDecoder {})
|
||||
when decoded is
|
||||
Ok rcd -> rcd.first rcd.second
|
||||
_ -> "something went wrong"
|
||||
|
|
@ -11415,8 +11455,8 @@ In roc, functions are always written as a lambda, like{}
|
|||
|
||||
This expression has a type that does not implement the abilities it's expected to:
|
||||
|
||||
8│ Ok rcd -> rcd.first rcd.second
|
||||
^^^^^^^^^
|
||||
48│ Ok rcd -> rcd.first rcd.second
|
||||
^^^^^^^^^
|
||||
|
||||
I can't generate an implementation of the `Decoding` ability for
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue