Öffentliche Dateiansicht: Raw-Dateien, Tree, Releases und Issues sind ohne Login verfügbar.
internal/detector/driverlicense_test.go Raw
 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package detector

import "testing"

func TestDetectDriverLicense(t *testing.T) {
	tests := []struct {
		name  string
		input string
		want  []string
	}{
		{
			"with führerschein keyword",
			"Führerscheinnummer: B951204XY",
			[]string{"B951204XY"},
		},
		{
			"with fahrerlaubnis keyword",
			"Fahrerlaubnis B951204XY wurde ausgestellt",
			[]string{"B951204XY"},
		},
		{
			"with driver license keyword",
			"Driver license: B951204XY",
			[]string{"B951204XY"},
		},
		{
			"with driving licence keyword",
			"Driving licence B951204XY",
			[]string{"B951204XY"},
		},
		{
			"with FS-Nr keyword",
			"FS-Nr. B951204XY",
			[]string{"B951204XY"},
		},
		{
			"multiple licenses",
			"Führerschein B951204XY und Führerschein M123456AB",
			[]string{"B951204XY", "M123456AB"},
		},
		{
			"no match without context",
			"B951204XY",
			nil,
		},
		{
			"no match context out of window",
			"Führerschein " + repeatStr("x", 250) + " B951204XY",
			nil,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := detectDriverLicense(tt.input)
			if len(got) != len(tt.want) {
				t.Fatalf("got %d findings, want %d — %v", len(got), len(tt.want), got)
			}
			for i, f := range got {
				if f.Text != tt.want[i] {
					t.Errorf("[%d] text = %q, want %q", i, f.Text, tt.want[i])
				}
				if f.Confidence != 0.75 {
					t.Errorf("[%d] confidence = %v, want 0.75", i, f.Confidence)
				}
			}
		})
	}
}

func repeatStr(s string, n int) string {
	result := make([]byte, len(s)*n)
	for i := range n {
		copy(result[i*len(s):], s)
	}
	return string(result)
}