2018-10-29 01:49:45 +03:00
|
|
|
package server
|
2016-03-05 02:08:16 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkJSONString(t *testing.B) {
|
|
|
|
var s = "the need for mead"
|
|
|
|
for i := 0; i < t.N; i++ {
|
|
|
|
jsonString(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkJSONMarshal(t *testing.B) {
|
|
|
|
var s = "the need for mead"
|
|
|
|
for i := 0; i < t.N; i++ {
|
|
|
|
json.Marshal(s)
|
|
|
|
}
|
|
|
|
}
|
2019-10-27 05:33:35 +03:00
|
|
|
|
|
|
|
func TestIsJsonNumber(t *testing.T) {
|
|
|
|
test := func(expected bool, val string) {
|
2019-10-30 20:17:59 +03:00
|
|
|
actual := isJSONNumber(val)
|
2019-10-27 05:33:35 +03:00
|
|
|
if expected != actual {
|
|
|
|
t.Fatalf("Expected %t == isJsonNumber(\"%s\") but was %t", expected, val, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test(false, "")
|
|
|
|
test(false, "-")
|
|
|
|
test(false, "foo")
|
|
|
|
test(false, "0123")
|
|
|
|
test(false, "1.")
|
|
|
|
test(false, "1.0e")
|
|
|
|
test(false, "1.0e-")
|
|
|
|
test(false, "1.0E10NaN")
|
|
|
|
test(false, "1.0ENaN")
|
|
|
|
test(true, "-1")
|
|
|
|
test(true, "0")
|
|
|
|
test(true, "0.0")
|
|
|
|
test(true, "42")
|
|
|
|
test(true, "1.0E10")
|
|
|
|
test(true, "1.0e10")
|
|
|
|
test(true, "1E+5")
|
|
|
|
test(true, "1E-10")
|
2019-10-30 20:17:59 +03:00
|
|
|
}
|