v0.6.1 aa12db3

golden_test.go RawHistoryFolder

1package text
2
3import (
4	"bytes"
5	"image"
6	"image/color"
7	"image/draw"
8	"image/png"
9	"math"
10	"os"
11	"path/filepath"
12	"testing"
13)
14
15func goldenPNG(t *testing.T, scale float64) []byte {
16	t.Helper()
17	c := fixture(t)
18	l, err := NewEngine(c).Measure("office fi سلام कि 日本語 ★", Request{Families: []string{"Noto Sans"}, Size: 20}, 0)
19	if err != nil {
20		t.Fatal(err)
21	}
22	dst := image.NewRGBA(image.Rect(0, 0, int(math.Ceil(l.Width*scale))+12, int(math.Ceil(l.Height*scale))+12))
23	draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
24	for _, line := range l.Lines {
25		for _, run := range line.Runs {
26			for _, g := range run.Glyphs {
27				x, y := 6+g.X*scale, 6+g.Y*scale
28				k, err := GlyphKey(run.Face, g.ID, 20*scale, x, run.Face.Variations)
29				if err != nil {
30					t.Fatal(err)
31				}
32				mask, err := Rasterize(run.Face, k)
33				if err != nil {
34					t.Fatal(err)
35				}
36				if mask.Alpha.Rect.Empty() {
37					continue
38				}
39				// Phase is already encoded into the mask; the integer dot and glyph origin
40				// determine the destination rectangle, without rounding advance positions.
41				pt := image.Pt(int(math.Floor(x))+mask.Origin.X, int(math.Floor(y))+mask.Origin.Y)
42				draw.DrawMask(dst, mask.Alpha.Bounds().Add(pt), image.NewUniform(color.Black), image.Point{}, mask.Alpha, image.Point{}, draw.Over)
43			}
44		}
45	}
46	var buf bytes.Buffer
47	if err := png.Encode(&buf, dst); err != nil {
48		t.Fatal(err)
49	}
50	return buf.Bytes()
51}
52func TestGoldenPending(t *testing.T) {
53	for _, tc := range []struct {
54		name  string
55		scale float64
56	}{{"1", 1}, {"1.25", 1.25}, {"1.5", 1.5}, {"2", 2}} {
57		t.Run(tc.name, func(t *testing.T) {
58			pending := filepath.Join("../../testdata/golden/pending", tc.name+".png")
59			got := goldenPNG(t, tc.scale)
60			want, err := os.ReadFile(pending)
61			if err != nil {
62				t.Fatal(err)
63			}
64			if !bytes.Equal(got, want) {
65				t.Errorf("pending CPU image drift: %s", pending)
66			}
67			approved := filepath.Join("../../testdata/golden/approved", tc.name+".png")
68			if ref, err := os.ReadFile(approved); err == nil && !bytes.Equal(got, ref) {
69				t.Errorf("approved reference mismatch: %s", approved)
70			}
71		})
72	}
73}

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 12

↑↓ moveenter openesc close