Browse Source

test case for string literal

v2ray 9 years ago
parent
commit
a0e35673cb
1 changed files with 29 additions and 0 deletions
  1. 29 0
      common/serial/string_json_test.go

+ 29 - 0
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")
+}