-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialize_test.go
53 lines (40 loc) · 1.01 KB
/
serialize_test.go
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
// SPDX-FileCopyrightText: 2019-2024 caixw
//
// SPDX-License-Identifier: MIT
package config
import (
"encoding/json"
"encoding/xml"
"testing"
"github.com/issue9/assert/v4"
)
func TestSerializer(t *testing.T) {
a := assert.New(t, false)
s := Serializer{}
a.Equal(0, s.Len())
t.Run("Add", func(t *testing.T) {
a := assert.New(t, false)
s.Add(json.Marshal, json.Unmarshal, ".json", "js")
a.True(s.Exists("json")).
True(s.Exists(".js")).
Equal(2, s.Len())
a.PanicString(func() {
s.Add(xml.Marshal, xml.Unmarshal)
}, "参数 ext 不能为空")
a.PanicString(func() {
s.Add(xml.Marshal, xml.Unmarshal, "")
}, "扩展名不能为空")
a.PanicString(func() {
s.Add(xml.Marshal, xml.Unmarshal, "json")
}, "已经存在同名的扩展名 .json")
})
t.Run("Delete", func(t *testing.T) {
a := assert.New(t, false)
s.Delete(".not-exists")
a.Equal(2, s.Len())
s.Delete(".json", ".mjs")
a.Equal(1, s.Len())
a.NotNil(s.GetByFilename("abc.js")).
Nil(s.GetByFilename(".json"))
})
}