From 5dda112124183a741dd0e3c44c073f5cfab92ad7 Mon Sep 17 00:00:00 2001 From: Gavin Morrow Date: Mon, 29 Sep 2025 15:19:07 -0400 Subject: [PATCH] Add additional test for strings --- test/person.pb | Bin 44 -> 56 bytes test/person.protoscope.txt | 6 ++++-- test/protobin_test.gleam | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/test/person.pb b/test/person.pb index f324f8df14577b64562f6d0006fa83dd306e7314..fe6ae457abafb0647dbc7fb9889d3b084e131058 100644 GIT binary patch literal 56 jcmb2tVt@c67RRE@M2=~U0<(UyC`n@%*A-)6U;q;U0(A*I literal 44 dcmd;>#walBCyS&O0|Y3EqKoK?F)%QI2>_=G1<(Kh diff --git a/test/person.protoscope.txt b/test/person.protoscope.txt index cb1142b..7460cea 100644 --- a/test/person.protoscope.txt +++ b/test/person.protoscope.txt @@ -1,10 +1,12 @@ +3: 42i64 +6: { "Aria" } 1: 150 2: 81050 -3: 42i64 4: { + 3: 42i64 + 6: { "Aria" } 1: 150 2: 81050 - 3: 42i64 5: 22i32 } 5: 22i32 diff --git a/test/protobin_test.gleam b/test/protobin_test.gleam index 1c9ec67..4137011 100644 --- a/test/protobin_test.gleam +++ b/test/protobin_test.gleam @@ -10,11 +10,19 @@ pub fn main() -> Nil { } type Person { - Person(id: Int, age: Int, score: Int, self: option.Option(Person), day: Int) + Person( + id: Int, + name: String, + age: Int, + score: Int, + self: option.Option(Person), + day: Int, + ) } const default_person = Person( id: 0, + name: "", age: 0, score: 0, self: option.None, @@ -30,6 +38,7 @@ fn person_decoder() -> Decoder(Person) { ) use id <- decode.field(3, protobin.decode_fixed(64)) + use name <- decode.field(6, protobin.decode_string()) use age <- decode.field(1, protobin.decode_uint()) use score <- decode.field(2, protobin.decode_uint()) use person <- decode.optional_field( @@ -39,7 +48,7 @@ fn person_decoder() -> Decoder(Person) { ) use day <- decode.field(5, protobin.decode_fixed(32)) - Person(id:, age:, score:, self: person, day:) |> decode.success + Person(id:, name:, age:, score:, self: person, day:) |> decode.success } pub fn person_pb_test() { @@ -52,10 +61,12 @@ pub fn person_pb_test() { assert person == Person( id: 42, + name: "Aria", age: 150, score: 81_050, self: option.Some(Person( id: 42, + name: "Aria", age: 150, score: 81_050, self: option.None, -- 2.51.2