bitbucket.org/ai69/amoy@v0.2.3/json_test.go (about)

     1  package amoy
     2  
     3  import "testing"
     4  
     5  func TestToOneLineJSON(t *testing.T) {
     6  	tests := []struct {
     7  		name string
     8  		data interface{}
     9  		want string
    10  	}{
    11  		{"nil", nil, "null"},
    12  		{"empty", map[string]string{}, `{}`},
    13  		{"string", "hello", `"hello"`},
    14  		{"int", 123, `123`},
    15  		{"float", 123.456, `123.456`},
    16  		{"bool", true, `true`},
    17  		{"array", []string{"a", "b", "c"}, `["a","b","c"]`},
    18  		{"object", map[string]string{"a": "bcd"}, `{"a":"bcd"}`},
    19  	}
    20  	for _, tt := range tests {
    21  		t.Run(tt.name, func(t *testing.T) {
    22  			if got := ToOneLineJSON(tt.data); got != tt.want {
    23  				t.Errorf("ToOneLineJSON(%v) = %q, want %q", tt.data, got, tt.want)
    24  			}
    25  		})
    26  	}
    27  }