From 48fa315a22d0cc4b4ab4cc082a272491e8c83613 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 19 Oct 2024 12:46:15 +1300 Subject: [PATCH] examples/marshalling: replace QByteArray test case --- examples/marshalling/marshalling_test.go | 26 ++++++------------------ 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/marshalling/marshalling_test.go b/examples/marshalling/marshalling_test.go index a4bd4e40..6aff7c94 100644 --- a/examples/marshalling/marshalling_test.go +++ b/examples/marshalling/marshalling_test.go @@ -3,9 +3,7 @@ package main import ( "os" "reflect" - "strings" "testing" - "unsafe" "github.com/mappu/miqt/qt" ) @@ -98,26 +96,14 @@ func TestMarshalling(t *testing.T) { }) - t.Run("QByteArray::split", func(t *testing.T) { - phrase := "the quick brown fox jumps over the lazy dog" - expect := strings.Split(phrase, " ") + t.Run("QByteArray", func(t *testing.T) { - qba := qt.NewQByteArray2(phrase) - got := qba.Split(' ') - if len(expect) != len(got) { - t.Fatalf("split: expected len=%d, got len=%d", len(expect), len(got)) - } + input := "foo bar baz" + ba := qt.QFile_EncodeName(input) + got := qt.QFile_DecodeName(ba) - for i := 0; i < len(expect); i++ { - if got[i].Length() != len(expect[i]) { - t.Errorf("split/idx=%d: expected len=%d, got %d", i, len(expect[i]), got[i].Length()) - } - - // TODO add more ergnomic QByteArray<-->string conversion - var rawData []byte = unsafe.Slice((*byte)(got[i].Data()), got[i].Length()) - if string(rawData) != expect[i] { - t.Errorf("split/idx=%d: expected %#v, got %#v", i, string(rawData), expect[i]) - } + if input != got { + t.Fatalf("QByteArray: expected %q, got %q", input, got) } })