X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/encoding/json
opt
/
golang
/
1.22.0
/
src
/
encoding
/
json
/
📁
..
📄
bench_test.go
(12.3 KB)
📄
decode.go
(35.01 KB)
📄
decode_test.go
(67.59 KB)
📄
encode.go
(35.96 KB)
📄
encode_test.go
(29.37 KB)
📄
example_marshaling_test.go
(1.23 KB)
📄
example_test.go
(6.05 KB)
📄
example_text_marshaling_test.go
(1.23 KB)
📄
fold.go
(1.06 KB)
📄
fold_test.go
(1.32 KB)
📄
fuzz_test.go
(1.29 KB)
📄
indent.go
(5.36 KB)
📄
number_test.go
(1.84 KB)
📄
scanner.go
(16.14 KB)
📄
scanner_test.go
(6.89 KB)
📄
stream.go
(12.87 KB)
📄
stream_test.go
(12.93 KB)
📄
tables.go
(4.16 KB)
📄
tagkey_test.go
(2.9 KB)
📄
tags.go
(972 B)
📄
tags_test.go
(583 B)
📁
testdata
Editing: number_test.go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package json import ( "regexp" "testing" ) func TestNumberIsValid(t *testing.T) { // From: https://stackoverflow.com/a/13340826 var jsonNumberRegexp = regexp.MustCompile(`^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$`) validTests := []string{ "0", "-0", "1", "-1", "0.1", "-0.1", "1234", "-1234", "12.34", "-12.34", "12E0", "12E1", "12e34", "12E-0", "12e+1", "12e-34", "-12E0", "-12E1", "-12e34", "-12E-0", "-12e+1", "-12e-34", "1.2E0", "1.2E1", "1.2e34", "1.2E-0", "1.2e+1", "1.2e-34", "-1.2E0", "-1.2E1", "-1.2e34", "-1.2E-0", "-1.2e+1", "-1.2e-34", "0E0", "0E1", "0e34", "0E-0", "0e+1", "0e-34", "-0E0", "-0E1", "-0e34", "-0E-0", "-0e+1", "-0e-34", } for _, test := range validTests { if !isValidNumber(test) { t.Errorf("%s should be valid", test) } var f float64 if err := Unmarshal([]byte(test), &f); err != nil { t.Errorf("%s should be valid but Unmarshal failed: %v", test, err) } if !jsonNumberRegexp.MatchString(test) { t.Errorf("%s should be valid but regexp does not match", test) } } invalidTests := []string{ "", "invalid", "1.0.1", "1..1", "-1-2", "012a42", "01.2", "012", "12E12.12", "1e2e3", "1e+-2", "1e--23", "1e", "e1", "1e+", "1ea", "1a", "1.a", "1.", "01", "1.e1", } for _, test := range invalidTests { if isValidNumber(test) { t.Errorf("%s should be invalid", test) } var f float64 if err := Unmarshal([]byte(test), &f); err == nil { t.Errorf("%s should be invalid but unmarshal wrote %v", test, f) } if jsonNumberRegexp.MatchString(test) { t.Errorf("%s should be invalid but matches regexp", test) } } }
Upload File
Create Folder