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:
shua 2024-06-28 15:20:29 +02:00
parent 05ab018380
commit 0faa1d5f20
No known key found for this signature in database
GPG key ID: 73387DA37055770F
8 changed files with 679 additions and 278 deletions

View file

@ -1,18 +0,0 @@
app "test"
imports [TotallyNotJson]
provides [main] to "./platform"
HelloWorld := {} implements [Encoding {toEncoder}]
toEncoder = \@HelloWorld {} ->
Encode.custom \bytes, fmt ->
bytes
|> Encode.appendWith (Encode.string "Hello, World!\n") fmt
f =
when Str.fromUtf8 (Encode.toBytes (@HelloWorld {}) TotallyNotJson.json) is
Ok s -> s
_ -> "<bad>"
main = f
# ^ Str

View file

@ -0,0 +1,66 @@
app "test"
imports []
provides [main] to "./platform"
OnlyStrEncoder := {} implements [Encode.EncoderFormatting {
u8: encodeU8,
u16: encodeU16,
u32: encodeU32,
u64: encodeU64,
u128: encodeU128,
i8: encodeI8,
i16: encodeI16,
i32: encodeI32,
i64: encodeI64,
i128: encodeI128,
f32: encodeF32,
f64: encodeF64,
dec: encodeDec,
bool: encodeBool,
string: encodeString,
list: encodeList,
record: encodeRecord,
tuple: encodeTuple,
tag: encodeTag,
}]
encodeNothing = Encode.custom \bytes, @OnlyStrEncoder {} -> bytes
encodeU8 = \_n -> encodeNothing
encodeU16 = \_n -> encodeNothing
encodeU32 = \_n -> encodeNothing
encodeU64 = \_n -> encodeNothing
encodeU128 = \_n -> encodeNothing
encodeI8 = \_n -> encodeNothing
encodeI16 = \_n -> encodeNothing
encodeI32 = \_n -> encodeNothing
encodeI64 = \_n -> encodeNothing
encodeI128 = \_n -> encodeNothing
encodeF32 = \_n -> encodeNothing
encodeF64 = \_n -> encodeNothing
encodeDec = \_n -> encodeNothing
encodeBool = \_b -> encodeNothing
encodeString = \str -> Encode.custom \bytes, @OnlyStrEncoder {} -> List.concat bytes (Str.toUtf8 str)
encodeList : List elem, (elem -> Encoder OnlyStrEncoder) -> Encoder OnlyStrEncoder
encodeList = \_lst, _encodeElem -> encodeNothing
encodeRecord : List {key: Str, value: Encoder OnlyStrEncoder} -> Encoder OnlyStrEncoder
encodeRecord = \_fields -> encodeNothing
encodeTuple : List (Encoder OnlyStrEncoder) -> Encoder OnlyStrEncoder
encodeTuple = \_elems -> encodeNothing
encodeTag : Str, List (Encoder OnlyStrEncoder) -> Encoder OnlyStrEncoder
encodeTag = \_name, _payload -> encodeNothing
HelloWorld := {} implements [Encoding {toEncoder}]
toEncoder = \@HelloWorld {} ->
Encode.custom \bytes, fmt ->
bytes
|> Encode.appendWith (Encode.string "Hello, World!\n") fmt
f =
when Str.fromUtf8 (Encode.toBytes (@HelloWorld {}) (@OnlyStrEncoder {})) is
Ok s -> s
_ -> "<bad>"
main = f
# ^ Str