clerk/internal/linter/linter_test.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com linter: add missing transaction status, 1 month ago
olexsmir@gmail.com linter: add missing transaction status, 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 | } |
| 19 | |
| 20 | func TestLinter(t *testing.T) { |
| 21 | for tname, trules := range tests { |
| 22 | t.Run(tname, func(t *testing.T) { |
| 23 | inp := golden.Load(t, tname) |
| 24 | pf, err := journal.NewLoader().LoadBytes(tname+".journal", inp) |
| 25 | if err != nil { |
| 26 | t.Fatalf("failed to load test journal: %v\n", err) |
| 27 | } |
| 28 | |
| 29 | finds := NewLinter(trules).Run(pf.Ast) |
| 30 | |
| 31 | var b strings.Builder |
| 32 | Fprint(&b, PathBasename, finds) |
| 33 | golden.Assert(t, tname, b.String()) |
| 34 | }) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func BenchmarkLinter(b *testing.B) { |
| 39 | pf, err := journal.NewLoader().Load( |
| 40 | "../../journal/testdata/journals/actual-1ktxns-100accts.journal", |
| 41 | ) |
| 42 | if err != nil { |
| 43 | b.Fatalf("failed to load benchmark journal: %v", err) |
| 44 | } |
| 45 | l := NewLinter(Rules) |
| 46 | |
| 47 | b.ResetTimer() |
| 48 | b.ReportAllocs() |
| 49 | for b.Loop() { |
| 50 | l.Run(pf.Ast) |
| 51 | } |
| 52 | } |