More robust fetching of grapheme break test data in Go test

This commit is contained in:
Kovid Goyal
2025-03-26 21:56:52 +05:30
parent 2aa2607adc
commit 305c1a25c5
3 changed files with 9 additions and 16 deletions

View File

@@ -3,17 +3,18 @@ package wcswidth
import (
"encoding/json"
"fmt"
"os/exec"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"kitty/tools/utils"
_ "embed"
)
var _ = fmt.Print
//go:embed GraphemeBreakTest.json
var test_data []byte
type GraphemeBreakTest struct {
Data []string `json:"data"`
Comment string `json:"comment"`
@@ -29,19 +30,8 @@ func TestSplitIntoGraphemes(t *testing.T) {
t.Fatalf("Failed to split %#v into graphemes: %s", text, diff)
}
}
cmd := exec.Command(utils.KittyExe(), "+runpy", `
from kitty.constants import read_kitty_resource
import sys
sys.stdout.buffer.write(read_kitty_resource("GraphemeBreakTest.json", "kitty_tests"))
sys.stdout.flush()
`)
var output []byte
var err error
if output, err = cmd.Output(); err != nil {
t.Fatalf("Getting GraphemeBreakTest.json failed with error: %s", err)
}
tests := []GraphemeBreakTest{}
if err = json.Unmarshal(output, &tests); err != nil {
if err := json.Unmarshal(test_data, &tests); err != nil {
t.Fatalf("Failed to parse GraphemeBreakTest JSON with error: %s", err)
}
for i, x := range tests {