mirror of https://github.com/golang/go.git
log/slog: add test case for level_test.go
adds a test case for the MarshalJSON method of the Level type in the slog package. adds a test case for the MarshalText method of the Level type in the slog package.
This commit is contained in:
parent
b8ac61e6e6
commit
5d991e1cd0
|
|
@ -5,6 +5,7 @@
|
|||
package slog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -52,10 +53,14 @@ func TestLevelVar(t *testing.T) {
|
|||
|
||||
func TestMarshalJSON(t *testing.T) {
|
||||
want := LevelWarn - 3
|
||||
want_data := []byte{'"', 'I', 'N', 'F', 'O', '+', '1', '"'}
|
||||
data, err := want.MarshalJSON()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(data, want_data) {
|
||||
t.Errorf("got %s, want %s", string(data), string(want_data))
|
||||
}
|
||||
var got Level
|
||||
if err := got.UnmarshalJSON(data); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -67,10 +72,14 @@ func TestMarshalJSON(t *testing.T) {
|
|||
|
||||
func TestLevelMarshalText(t *testing.T) {
|
||||
want := LevelWarn - 3
|
||||
want_data := []byte{'I', 'N', 'F', 'O', '+', '1'}
|
||||
data, err := want.MarshalText()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(data, want_data) {
|
||||
t.Errorf("got %s, want %s", string(data), string(want_data))
|
||||
}
|
||||
var got Level
|
||||
if err := got.UnmarshalText(data); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue