-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlookup_test.go
More file actions
97 lines (81 loc) · 1.88 KB
/
Copy pathlookup_test.go
File metadata and controls
97 lines (81 loc) · 1.88 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2017-2026 The ivi developers. All rights reserved.
// Project site: https://github.com/gotmc/ivi
// Use of this source code is governed by a MIT-style license that
// can be found in the LICENSE.txt file for the project.
package ivi
import (
"errors"
"testing"
)
type testEnum int
const (
enumA testEnum = iota
enumB
enumC
)
var forwardMap = map[testEnum]string{
enumA: "SCPI_A",
enumB: "SCPI_B",
}
var reverseMap = map[string]testEnum{
"SCPI_A": enumA,
"SCPI_B": enumB,
}
func TestLookupSCPI(t *testing.T) {
tests := []struct {
name string
val testEnum
want string
wantErr error
}{
{"found A", enumA, "SCPI_A", nil},
{"found B", enumB, "SCPI_B", nil},
{"missing C", enumC, "", ErrValueNotSupported},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := LookupSCPI(forwardMap, tt.val)
if tt.wantErr != nil {
if !errors.Is(err, tt.wantErr) {
t.Errorf("LookupSCPI() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
if err != nil {
t.Errorf("LookupSCPI() unexpected error: %v", err)
}
if got != tt.want {
t.Errorf("LookupSCPI() = %q, want %q", got, tt.want)
}
})
}
}
func TestReverseLookup(t *testing.T) {
tests := []struct {
name string
scpi string
want testEnum
wantErr error
}{
{"found A", "SCPI_A", enumA, nil},
{"found B", "SCPI_B", enumB, nil},
{"missing", "SCPI_X", 0, ErrUnexpectedResponse},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ReverseLookup(reverseMap, tt.scpi)
if tt.wantErr != nil {
if !errors.Is(err, tt.wantErr) {
t.Errorf("ReverseLookup() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
if err != nil {
t.Errorf("ReverseLookup() unexpected error: %v", err)
}
if got != tt.want {
t.Errorf("ReverseLookup() = %v, want %v", got, tt.want)
}
})
}
}