diff --git a/test/person.pb b/test/person.pb index e4b7ff57c89e5f07b21199650c489055019d2511..93a39def82371570a29aa95f31224e409558ea12 100644 GIT binary patch literal 34 Xcmd;>#walBCyS&O0|Y1upo;(iZV&}U literal 16 Tcmd;>#walBCyS&O0|Wp79()3d diff --git a/test/person.protosope.txt b/test/person.protosope.txt index 8663001..7dc2393 100644 --- a/test/person.protosope.txt +++ b/test/person.protosope.txt @@ -1,3 +1,8 @@ 1: 150 2: 81050 3: 42i64 +4: { + 1: 150 + 2: 81050 + 3: 42i64 +} diff --git a/test/protobuf_decode_gleam_test.gleam b/test/protobuf_decode_gleam_test.gleam index 3db5a93..19f4ec5 100644 --- a/test/protobuf_decode_gleam_test.gleam +++ b/test/protobuf_decode_gleam_test.gleam @@ -1,4 +1,5 @@ import gleam/dynamic/decode.{type Decoder} +import gleam/option import gleeunit import protobuf_decode_gleam.{decode, decode_u64, decode_uint} import simplifile as file @@ -8,21 +9,37 @@ pub fn main() -> Nil { } type Person { - Person(id: Int, age: Int, score: Int) + Person(id: Int, age: Int, score: Int, self: option.Option(Person)) } fn person_decoder() -> Decoder(Person) { use id <- decode.field(3, decode_u64()) use age <- decode.field(1, decode_uint()) use score <- decode.field(2, decode_uint()) - decode.success(Person(id:, age:, score:)) + use person <- decode.optional_field( + 4, + option.None, + person_decoder() |> decode.map(option.Some), + ) + decode.success(Person(id:, age:, score:, self: person)) } pub fn person_pb_test() { let path = "./test/person.pb" let assert Ok(bits) = file.read_bits(from: path) let assert Ok(person) = decode(from: bits, using: person_decoder()) - assert person == Person(id: 42, age: 150, score: 81_050) + assert person + == Person( + id: 42, + age: 150, + score: 81_050, + self: option.Some(Person( + id: 42, + age: 150, + score: 81_050, + self: option.None, + )), + ) } type TwoInts {