Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Apr 3, 2024
1 parent 57ef418 commit c84e129
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
42 changes: 42 additions & 0 deletions types/convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright © 2024 zc2638 <[email protected]>.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
"encoding/json"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRegister(t *testing.T) {
Register("json.Number", Integer)
assert.Equal(t, Integer, Get("json.Number"))
}

func TestParse(t *testing.T) {
pointer := &[]int{1, 2, 3}
pt := Parse(reflect.TypeOf(pointer))
assert.Equal(t, Array, pt)

jn := json.Number("123")
pt = Parse(reflect.TypeOf(jn))
assert.Equal(t, Get("json.Number"), pt)

other := make(chan struct{})
pt = Parse(reflect.TypeOf(other))
assert.Equal(t, Unknown, pt)
}
29 changes: 29 additions & 0 deletions types/format_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2024 zc2638 <[email protected]>.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseFormat(t *testing.T) {
data := &[]int{1, 2, 3}
rt := reflect.TypeOf(data)
format := ParseFormat(rt)
assert.Equal(t, FormatNone, format)
}
16 changes: 14 additions & 2 deletions types/types_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Package types
// Created by zc on 2022/6/11.
// Copyright © 2022 zc2638 <[email protected]>.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
Expand Down

0 comments on commit c84e129

Please sign in to comment.