internal/pipewire: implement string type
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m23s
Test / Hakurei (push) Successful in 3m14s
Test / Hpkg (push) Successful in 4m16s
Test / Sandbox (race detector) (push) Successful in 4m20s
Test / Hakurei (race detector) (push) Successful in 5m11s
Test / Flake checks (push) Successful in 1m39s

This is still NUL terminated strings, and an extra NUL character on an 8-byte string does cause an extra 7 bytes of padding.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-11-25 03:33:57 +09:00
parent d92de1c709
commit 827dc9e1ba
2 changed files with 44 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package pipewire_test
import (
"encoding"
"encoding/json"
"reflect"
"testing"
)
@@ -37,7 +38,7 @@ func (testCases encodingTestCases[V, S]) run(t *testing.T) {
t.Fatalf("UnmarshalBinary: error = %v", err)
}
if !reflect.DeepEqual(&value, &tc.value) {
t.Fatalf("UnmarshalBinary: %#v, want %#v", value, tc.value)
t.Fatalf("UnmarshalBinary:\n%s\nwant\n%s", mustMarshalJSON(value), mustMarshalJSON(tc.value))
}
})
@@ -53,3 +54,12 @@ func (testCases encodingTestCases[V, S]) run(t *testing.T) {
})
}
}
// mustMarshalJSON calls [json.Marshal] and returns the result.
func mustMarshalJSON(v any) string {
if data, err := json.Marshal(v); err != nil {
panic(err)
} else {
return string(data)
}
}