oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "bytes"
5 "encoding/json"
6 "flag"
7 "fmt"
8 "os"
9 "path/filepath"
10 "testing"
11)
12
13// The markup corpus (spec §7, gate L4) holds the synthetic pages
14// SeedSynthetic writes. markup cannot import this package, so this test
15// writes them for it, and fails when the committed copy is stale.
16var updateCorpus = flag.Bool("update", false,
17 "rewrite markup/testdata/corpus/synthetic.json")
18
19// syntheticCorpusPages is a seed's worth of pages: every body
20// SeedSynthetic writes for this count.
21const syntheticCorpusPages = 24
22
23func TestSyntheticCorpusIsCurrent(t *testing.T) {
24 path := filepath.Join("markup", "testdata", "corpus", "synthetic.json")
25 type entry struct {
26 Name string `json:"name"`
27 Body string `json:"body"`
28 }
29 var entries []entry
30 for number, body := range SyntheticBodies(syntheticCorpusPages) {
31 entries = append(entries, entry{
32 Name: fmt.Sprintf("synthetic/%02d", number), Body: body})
33 }
34 fresh, err := json.MarshalIndent(entries, "", " ")
35 if err != nil {
36 t.Fatal(err)
37 }
38 fresh = append(fresh, '\n')
39 if *updateCorpus {
40 if err := os.WriteFile(path, fresh, 0o644); err != nil {
41 t.Fatal(err)
42 }
43 return
44 }
45 committed, err := os.ReadFile(path)
46 if err != nil || !bytes.Equal(committed, fresh) {
47 t.Fatalf("%s is stale: run make golden and commit it (%v)", path,
48 err)
49 }
50}
51