From a0e35673cb52d0d2addfe5ab4d574cb596319a24 Mon Sep 17 00:00:00 2001 From: v2ray Date: Thu, 4 Feb 2016 17:45:16 +0100 Subject: [PATCH] test case for string literal --- common/serial/string_json_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 common/serial/string_json_test.go diff --git a/common/serial/string_json_test.go b/common/serial/string_json_test.go new file mode 100644 index 000000000..c2917fa7f --- /dev/null +++ b/common/serial/string_json_test.go @@ -0,0 +1,29 @@ +// +build json + +package serial_test + +import ( + "encoding/json" + "testing" + + . "github.com/v2ray/v2ray-core/common/serial" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" +) + +func TestInvalidStringLiteralJson(t *testing.T) { + v2testing.Current(t) + + var s StringLiteral + err := json.Unmarshal([]byte("1"), &s) + assert.Error(err).IsNotNil() +} + +func TestStringLiteralParsing(t *testing.T) { + v2testing.Current(t) + + var s StringLiteral + err := json.Unmarshal([]byte("\"1\""), &s) + assert.Error(err).IsNil() + assert.String(s).Equals("1") +}