summaryrefslogtreecommitdiff
path: root/cmd/krino/enum_test.go
blob: 144fec696fe73d205248991ee48d7d1ee5c7cf53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-License-Identifier: GPL-3.0-or-later

package main

import (
	"slices"
	"strings"
	"testing"

	"krino/internal/enumtest"
	"krino/internal/scan"
)

// TestEverySkipReasonIsSummarised: every scan.Reason is counted in the
// "not acted on" line and reads as words. 0.0.4 added TooBig and only a
// hand check caught it missing from skipReasonOrder. scan.Reason is an iota
// block from 0, so the i-th constant is the value i.
func TestEverySkipReasonIsSummarised(t *testing.T) {
	reasons, err := enumtest.Names("../../internal/scan/scan.go", "Reason")
	if err != nil {
		t.Fatal(err)
	}
	for i, name := range reasons {
		r := scan.Reason(i)
		if !slices.Contains(skipReasonOrder, r) {
			t.Errorf("scan.%s is missing from skipReasonOrder", name)
		}
		if s := r.String(); s == "" || strings.ContainsAny(s, "0123456789") {
			t.Errorf("scan.%s reads %q", name, s)
		}
	}
	if len(skipReasonOrder) != len(reasons) {
		t.Errorf("skipReasonOrder has %d reasons, scan declares %d", len(skipReasonOrder), len(reasons))
	}
}