all repos

clerk @ 731ba24

missing tooling for ledger/hledger

clerk/internal/linter/linter_test.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
linter: add chronological order, 1 month ago
1
package linter
2
3
import (
4
	"strings"
5
	"testing"
6
7
	"olexsmir.xyz/clerk/internal/testutil/golden"
8
	"olexsmir.xyz/clerk/journal"
9
)
10
11
var tests = map[string][]Rule{
12
	"correct":                  Rules,
13
	"empty-postings":           {&EmptyPostings{}},
14
	"parse-error":              {&ParseError{}},
15
	"omitted-precision":        {&OmittedPrecision{}},
16
	"missing-commodity":        {&MissingCommodity{}},
17
	"missing-status":           {&MissingStatus{}},
18
	"account-depth":            {&AccountDepthLimit{MaxDepth: 3}},
19
	"multiple-omitted-amounts": {&MultipleOmittedAmounts{}},
20
	"orderdate":                {&OrderDate{}},
21
}
22
23
func TestLinter(t *testing.T) {
24
	for tname, trules := range tests {
25
		t.Run(tname, func(t *testing.T) {
26
			inp := golden.Load(t, tname)
27
			pf, err := journal.NewLoader().LoadBytes(tname+".journal", inp)
28
			if err != nil {
29
				t.Fatalf("failed to load test journal: %v\n", err)
30
			}
31
32
			finds := NewLinter(trules).Run(pf.Ast)
33
34
			var b strings.Builder
35
			Fprint(&b, PathBasename, finds)
36
			golden.Assert(t, tname, b.String())
37
		})
38
	}
39
}
40
41
func BenchmarkLinter(b *testing.B) {
42
	pf, err := journal.NewLoader().Load(
43
		"../../journal/testdata/journals/actual-1ktxns-100accts.journal",
44
	)
45
	if err != nil {
46
		b.Fatalf("failed to load benchmark journal: %v", err)
47
	}
48
	l := NewLinter(Rules)
49
50
	b.ResetTimer()
51
	b.ReportAllocs()
52
	for b.Loop() {
53
		l.Run(pf.Ast)
54
	}
55
}