From 220129584e8f13a90e6ba1f640aafc433bae6ae4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 30 Sep 2026 20:14:52 +0200 Subject: [PATCH] Write the seeded pin's data through writeFiles --- format_stability_test.go | 46 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/format_stability_test.go b/format_stability_test.go index 8028182..3cfb0c9 100644 --- a/format_stability_test.go +++ b/format_stability_test.go @@ -1,39 +1,29 @@ package fejkdata -import ( - "os" - "path/filepath" - "testing" -) +import "testing" // TestSeededOutputIsStable pins the exact bytes a seeded generator emits for each // piece of the token grammar, so a change to how a format is scanned or rendered // cannot quietly shift the rng stream that reproducibility depends on. func TestSeededOutputIsStable(t *testing.T) { - dir := writeData(t, map[string]string{ - "alt": `{"format":"{a|b}","a":"A","b":"B"}`, - "calc": `{"format":"{net} x {qty} = {calc(net * qty, 2)}","net":["19.99","5.00","100.00"],"qty":["2","3","7"]}`, - "classes": `"{digits(2)}-{int(1,9)}{int(1,9)}-{upper(2)}-{lower(2)}"`, - "escapes": `{"format":"01Aa#{x}","x":"!"}`, - "funcs": `"{hex(6)} {int(10,99)} {float(0,1,3)} {nanoid(5)} {seq()}"`, - "municipality": `{"format":"{name}","rows":"municipality.tsv","key":"code","name":"name","parent":"region"}`, - "nested": `{"format":"{outer}","outer":{"format":"{inner}-{digits(2)}","inner":"i"}}`, - "paths": `{"format":"{p.a}{p.b}","p":[{"format":"x","a":"1","b":"2"},{"format":"y","a":"A","b":"B"},{"format":"z","a":"a","b":"b"}]}`, - "ref": `"see {/alt}"`, - "refpath": `"{/region.municipality.name} in {/region.name}"`, - "region": `{"format":"{name}","rows":"region.tsv","key":"code","name":"name","weight":"people"}`, - "repeat": `{"format":"{w}","repeat":4,"separator":",","w":["x","y","z"]}`, - "sums": `{"format":"9{d}{luhn()} {e}{ean()} {m}{mod11()}","d":"012345678901234","e":"123456789012","m":"12345678"}`, - "weights": `[{"format":"big","weight":9},"tiny"]`, + dir := writeFiles(t, map[string]string{ + "alt.json": `{"format":"{a|b}","a":"A","b":"B"}`, + "calc.json": `{"format":"{net} x {qty} = {calc(net * qty, 2)}","net":["19.99","5.00","100.00"],"qty":["2","3","7"]}`, + "classes.json": `"{digits(2)}-{int(1,9)}{int(1,9)}-{upper(2)}-{lower(2)}"`, + "escapes.json": `{"format":"01Aa#{x}","x":"!"}`, + "funcs.json": `"{hex(6)} {int(10,99)} {float(0,1,3)} {nanoid(5)} {seq()}"`, + "municipality.json": `{"format":"{name}","rows":"municipality.tsv","key":"code","name":"name","parent":"region"}`, + "municipality.tsv": "code\tname\tregion\n0180\tStockholm\t01\n0184\tSolna\t01\n1280\tMalmö\t12\n1281\tLund\t12\n", + "nested.json": `{"format":"{outer}","outer":{"format":"{inner}-{digits(2)}","inner":"i"}}`, + "paths.json": `{"format":"{p.a}{p.b}","p":[{"format":"x","a":"1","b":"2"},{"format":"y","a":"A","b":"B"},{"format":"z","a":"a","b":"b"}]}`, + "ref.json": `"see {/alt}"`, + "refpath.json": `"{/region.municipality.name} in {/region.name}"`, + "region.json": `{"format":"{name}","rows":"region.tsv","key":"code","name":"name","weight":"people"}`, + "region.tsv": "code\tname\tpeople\n01\tStockholms län\t3\n12\tSkåne län\t1\n", + "repeat.json": `{"format":"{w}","repeat":4,"separator":",","w":["x","y","z"]}`, + "sums.json": `{"format":"9{d}{luhn()} {e}{ean()} {m}{mod11()}","d":"012345678901234","e":"123456789012","m":"12345678"}`, + "weights.json": `[{"format":"big","weight":9},"tiny"]`, }) - for name, rows := range map[string]string{ - "municipality": "code\tname\tregion\n0180\tStockholm\t01\n0184\tSolna\t01\n1280\tMalmö\t12\n1281\tLund\t12\n", - "region": "code\tname\tpeople\n01\tStockholms län\t3\n12\tSkåne län\t1\n", - } { - if err := os.WriteFile(filepath.Join(dir, name+".tsv"), []byte(rows), 0o644); err != nil { - t.Fatal(err) - } - } want := map[string][]string{ "alt": {"A", "A", "B", "A"}, "calc": {"100.00 x 3 = 300.00", "100.00 x 3 = 300.00", "100.00 x 7 = 700.00", "5.00 x 3 = 15.00"},