main 98594d0

golden_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package expr
4
5import (
6	"os"
7	"path/filepath"
8	"strings"
9	"testing"
10)
11
12// TestToJSONGolden checks toJSON(fromJSON(x)) against the output of the
13// reference implementation for each testdata/tojson/NAME.json. The .golden
14// files are generated by gen/golden.mjs.
15func TestToJSONGolden(t *testing.T) {
16	inputs, err := filepath.Glob("testdata/tojson/*.json")
17	if err != nil || len(inputs) < 30 {
18		t.Fatalf("golden inputs: %v (%d found)", err, len(inputs))
19	}
20	for _, in := range inputs {
21		name := strings.TrimSuffix(filepath.Base(in), ".json")
22		t.Run(name, func(t *testing.T) {
23			text, err := os.ReadFile(in)
24			if err != nil {
25				t.Fatal(err)
26			}
27			// NAME.golden is the answer of the JavaScript reference. Where
28			// the C# runner answers differently, NAME.runner holds its
29			// answer and is what this package follows (see PORTING.md).
30			want, err := os.ReadFile(strings.TrimSuffix(in, ".json") + ".runner")
31			fromRunner := err == nil
32			if os.IsNotExist(err) {
33				want, err = os.ReadFile(strings.TrimSuffix(in, ".json") + ".golden")
34			}
35			if err != nil {
36				t.Fatal(err)
37			}
38			v, err := FromJSON(text)
39			if err != nil {
40				t.Fatal(err)
41			}
42			if got := ToJSON(v); got != string(want) {
43				t.Errorf("toJSON mismatch\n got: %q\nwant: %q", got, want)
44			}
45			if fromRunner {
46				// The runner's output is not JSON in general: numbers have 15
47				// significant digits and NaN and Infinity are bare words.
48				return
49			}
50			// The golden output is itself JSON that must round-trip.
51			v2, err := FromJSON(want)
52			if err != nil {
53				t.Fatalf("golden output does not parse: %v", err)
54			}
55			if got := ToJSON(v2); got != string(want) {
56				t.Errorf("toJSON is not stable\n got: %q\nwant: %q", got, want)
57			}
58		})
59	}
60}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close