main 98594d0

number_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package expr
4
5import (
6	"math"
7	"os"
8	"strconv"
9	"strings"
10	"testing"
11)
12
13// TestParseNumberMatchesRunner replays testdata/number_cases.txt, the answers
14// of the runner's ExpressionUtility.ParseNumber (gen/runner/number_cases.mjs)
15// on 443 strings: hexadecimal, octal and binary forms, signs, exponents,
16// Infinity and NaN spellings, Unicode digits and spaces.
17func TestParseNumberMatchesRunner(t *testing.T) {
18	data, err := os.ReadFile("testdata/number_cases.txt")
19	if err != nil {
20		t.Fatal(err)
21	}
22	n := 0
23	for _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {
24		f := strings.Fields(line)
25		if len(f) != 2 {
26			t.Fatalf("bad line %q", line)
27		}
28		in := decodeUnits(f[0])
29		var want float64
30		if f[1] == "NaN" {
31			want = math.NaN()
32		} else {
33			bits, err := strconv.ParseUint(f[1], 16, 64)
34			if err != nil {
35				t.Fatal(err)
36			}
37			want = math.Float64frombits(bits)
38		}
39		got := parseNumber(in)
40		if math.Float64bits(got) != math.Float64bits(want) && !(math.IsNaN(got) && math.IsNaN(want)) {
41			t.Errorf("parseNumber(%q [%s]) = %v (%x), runner %v (%x)", in, f[0], got, math.Float64bits(got), want, math.Float64bits(want))
42		}
43		n++
44	}
45	if n < 400 {
46		t.Errorf("only %d cases", n)
47	}
48}
49
50// decodeUnits decodes dot-separated hexadecimal UTF-16 code units ("-" is the
51// empty string).
52func decodeUnits(h string) string {
53	if h == "-" {
54		return ""
55	}
56	var units []uint16
57	for _, u := range strings.Split(h, ".") {
58		n, _ := strconv.ParseUint(u, 16, 16)
59		units = append(units, uint16(n))
60	}
61	return utf16String(units)
62}

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