Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"sort"
"strings"
"testing"
)

Expand Down Expand Up @@ -67,3 +68,26 @@ func readJSON(t *testing.T, path string, v any) {
t.Fatalf("%s: %v", path, err)
}
}

// TestFixturesAreASCII keeps the fixtures robust: invisible characters such as
// U+2028 and U+2029 must be escape sequences in the JSON, because editors and tools
// strip or normalise them when they are written raw (which once silently turned
// the line_sep fixture into plain "abc").
func TestFixturesAreASCII(t *testing.T) {
for _, path := range []string{"testdata/blocknote_fixtures.json", "testdata/blocknote_golden.json"} {
b, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
for i, c := range b {
if c >= 0x80 && path == "testdata/blocknote_fixtures.json" {
t.Fatalf("%s has a raw non-ASCII byte at offset %d; write it as an escape sequence", path, i)
}
}
for _, r := range []rune{0x2028, 0x2029, 0xFEFF} {
if strings.ContainsRune(string(b), r) {
t.Errorf("%s contains a raw %U; write it as an escape sequence", path, r)
}
}
}
}
10 changes: 7 additions & 3 deletions js/golden.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ describe("BlockNote markdown golden output", () => {
for (const name of Object.keys(fixtures).sort()) {
actual[name] = await render(fixtures[name]);
}
await expect(`${JSON.stringify(actual, null, 1)}\n`).toMatchFileSnapshot(
goldenPath,
);
// U+2028, U+2029 and U+FEFF are valid raw in JSON but editors and tools
// strip or normalise them, so write them as escapes.
const json = JSON.stringify(actual, null, 1)
.replaceAll("\u2028", "\\u2028")
.replaceAll("\u2029", "\\u2029")
.replaceAll("\uFEFF", "\\uFEFF");
await expect(`${json}\n`).toMatchFileSnapshot(goldenPath);
});
});
Loading
Loading