diff --git a/fuzzy_mode_convert_table.md b/fuzzy_mode_convert_table.md index 7f73c34..3095662 100644 --- a/fuzzy_mode_convert_table.md +++ b/fuzzy_mode_convert_table.md @@ -1,7 +1,7 @@ | json type \ dest type | bool | int | uint | float |string| | --- | --- | --- | --- |--|--| -| number | positive => true
negative => true
zero => false| 23.2 => 23
-32.1 => -32| 12.1 => 12
-12.1 => 0|as normal|| -| string | empty string => false
string "0" => false
other strings => true | "123.32" => 123
"-123.4" => -123
"123.23xxxw" => 123
"abcde12" => 0
"-32.1" => -32| 13.2 => 13
-1.1 => 0 |12.1 => 12.1
-12.3 => -12.3
12.4xxa => 12.4
+1.1e2 =>110 || -| bool | true => true
false => false| true => 1
false => 0 | true => 1
false => 0 |true => 1
false => 0|| -| object | true | 0 | 0 |0|| -| array | empty array => false
nonempty array => true| [] => 0
[1,2] => 1 | [] => 0
[1,2] => 1 |[] => 0
[1,2] => 1|| \ No newline at end of file +| number | positive => true
negative => true
zero => false| 23.2 => 23
-32.1 => -32| 12.1 => 12
-12.1 => 0|as normal|same as origin| +| string | empty string => false
string "0" => false
other strings => true | "123.32" => 123
"-123.4" => -123
"123.23xxxw" => 123
"abcde12" => 0
"-32.1" => -32| 13.2 => 13
-1.1 => 0 |12.1 => 12.1
-12.3 => -12.3
12.4xxa => 12.4
+1.1e2 =>110 |same as origin| +| bool | true => true
false => false| true => 1
false => 0 | true => 1
false => 0 |true => 1
false => 0|true => "true"
false => "false"| +| object | true | 0 | 0 |0|originnal json| +| array | empty array => false
nonempty array => true| [] => 0
[1,2] => 1 | [] => 0
[1,2] => 1 |[] => 0
[1,2] => 1|original json| \ No newline at end of file diff --git a/jsoniter_encode_interface_test.go b/jsoniter_encode_interface_test.go new file mode 100644 index 0000000..14b7add --- /dev/null +++ b/jsoniter_encode_interface_test.go @@ -0,0 +1,42 @@ +package jsoniter + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_encode_interface(t *testing.T) { + should := require.New(t) + var a interface{} + a = int8(10) + str, err := MarshalToString(a) + should.Nil(err) + should.Equal(str, "10") + a = float32(3) + str, err = MarshalToString(a) + should.Nil(err) + should.Equal(str, "3") + a = map[string]interface{}{"abc": 1} + str, err = MarshalToString(a) + should.Nil(err) + should.Equal(str, `{"abc":1}`) + a = uintptr(1) + str, err = MarshalToString(a) + should.Nil(err) + should.Equal(str, "1") + a = uint(1) + str, err = MarshalToString(a) + should.Nil(err) + should.Equal(str, "1") + a = uint8(1) + str, err = MarshalToString(a) + should.Nil(err) + should.Equal(str, "1") + a = json.RawMessage("abc") + MarshalToString(a) + str, err = MarshalToString(a) + should.Nil(err) + should.Equal(str, "abc") +} diff --git a/jsoniter_string_test.go b/jsoniter_string_test.go index 795e515..cefb168 100644 --- a/jsoniter_string_test.go +++ b/jsoniter_string_test.go @@ -94,7 +94,16 @@ func Test_read_normal_string(t *testing.T) { func Test_read_exotic_string(t *testing.T) { cases := map[string]string{ `"hel\"lo"`: `hel"lo`, - `"hel\nlo"`: "hel\nlo", + `"hel\\\/lo"`: `hel\/lo`, + `"hel\\blo"`: `hel\blo`, + `"hel\\\blo"`: "hel\\\blo", + `"hel\\nlo"`: `hel\nlo`, + `"hel\\\nlo"`: "hel\\\nlo", + `"hel\\tlo"`: `hel\tlo`, + `"hel\\flo"`: `hel\flo`, + `"hel\\\flo"`: "hel\\\flo", + `"hel\\\rlo"`: "hel\\\rlo", + `"hel\\\tlo"`: "hel\\\tlo", `"\u4e2d\u6587"`: "中文", `"\ud83d\udc4a"`: "\xf0\x9f\x91\x8a", // surrogate }