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
|
package lulu
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func TestPkgId(t *testing.T) {
t.Parallel()
for _, pair := range []struct {
j string
pkg PkgId
}{
{
`"0850X1100.BW.STD.LW.060UW444.MNG"`,
PkgId{
UsLetter,
Mono,
Standard,
LinenWrap,
P60UncoatedWhite,
Matte,
NavyLinen,
GoldFoil},
}, {
`"0600X0900.FC.STD.PB.080CW444.GXX"`,
PkgId{
UsTrade,
Color,
Standard,
Perfect,
P80CoatedWhite,
Gloss,
NoLinen,
NoFoil},
}, {
`"0700X1000.FC.PRE.CO.060UC444.MXX"`,
PkgId{
Executive,
Color,
Premium,
Coil,
P60UncoatedCream,
Matte,
NoLinen,
NoFoil},
}, {
`"0600X0900.BW.STD.PB.060UW444.MXX"`,
PkgId{
UsTrade,
Mono,
Standard,
Perfect,
P60UncoatedWhite,
Matte,
NoLinen,
NoFoil},
},
} {
requireMarshalJsonEq(t, pair.j, pair.pkg)
requireUnmarshalJsonEq(t, pair.pkg, pair.j)
}
}
func TestUnmarshalInvalidPkgId(t *testing.T) {
var pkg PkgId
require.Error(t, json.Unmarshal([]byte(``), &pkg))
require.Error(t, json.Unmarshal([]byte(`""`), &pkg))
require.Error(t, json.Unmarshal([]byte(`"abc"`), &pkg))
require.Error(t, json.Unmarshal([]byte(`"9999X9999.XX.XXX.XX.999XX999.ZZZ"`), &pkg))
}
|