v2.31.0-dev10 f49cffc

parse_test.go RawHistoryFolder

1package bytesize
2
3import (
4	"testing"
5)
6
7func TestParse(t *testing.T) {
8	tests := []struct {
9		name    string
10		input   string
11		want    int64
12		wantErr bool
13	}{
14		{
15			name:  "bytes",
16			input: "512B",
17			want:  512,
18		},
19		{
20			name:  "kilobytes",
21			input: "100KB",
22			want:  100 * 1024,
23		},
24		{
25			name:  "megabytes",
26			input: "512MB",
27			want:  512 * 1024 * 1024,
28		},
29		{
30			name:  "gigabytes",
31			input: "1GB",
32			want:  1024 * 1024 * 1024,
33		},
34		{
35			name:  "terabytes",
36			input: "1TB",
37			want:  int64(1024) * 1024 * 1024 * 1024,
38		},
39		{
40			name:  "decimal megabytes",
41			input: "1.5GB",
42			want:  int64(1.5 * 1024 * 1024 * 1024),
43		},
44		{
45			name:  "lowercase",
46			input: "512mb",
47			want:  512 * 1024 * 1024,
48		},
49		{
50			name:  "mixed case",
51			input: "512Mb",
52			want:  512 * 1024 * 1024,
53		},
54		{
55			name:  "with spaces",
56			input: " 512 MB ",
57			want:  512 * 1024 * 1024,
58		},
59		{
60			name:    "empty string",
61			input:   "",
62			wantErr: true,
63		},
64		{
65			name:    "missing unit",
66			input:   "512",
67			wantErr: true,
68		},
69		{
70			name:    "missing value",
71			input:   "MB",
72			wantErr: true,
73		},
74		{
75			name:    "invalid value",
76			input:   "abcMB",
77			wantErr: true,
78		},
79		{
80			name:    "negative value",
81			input:   "-1GB",
82			wantErr: true,
83		},
84		{
85			name:    "unknown unit",
86			input:   "512XB",
87			wantErr: true,
88		},
89	}
90
91	for _, tt := range tests {
92		t.Run(tt.name, func(t *testing.T) {
93			got, err := Parse(tt.input)
94			if (err != nil) != tt.wantErr {
95				t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
96				return
97			}
98			if !tt.wantErr && got != tt.want {
99				t.Errorf("Parse() = %v, want %v", got, tt.want)
100			}
101		})
102	}
103}

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 7

Tags 106

↑↓ moveenter openesc close