4
4
5
5
6
6
// Utility function
7
- function equalJSON ( json , string , description ) {
7
+ function testToJSON ( json , string , description ) {
8
8
equal ( $ . toJSON ( json ) , string , description || '' ) ;
9
9
}
10
10
11
11
module ( 'jQuery.toJSON' ) ;
12
12
13
13
test ( 'Basic toJSON usage' , function ( ) {
14
14
15
- equalJSON (
15
+ testToJSON (
16
16
'hi' ,
17
17
'"hi"' ,
18
18
'Strings should be wrapped in double quotes'
19
19
) ;
20
- equalJSON (
20
+ testToJSON (
21
21
{ apple : 2 } ,
22
22
'{"apple":2}' ,
23
23
'Objects'
24
24
) ;
25
- equalJSON (
25
+ testToJSON (
26
26
{ apple : { apple : 2 } } ,
27
27
'{"apple":{"apple":2}}' ,
28
28
'Objects inside objects'
29
29
) ;
30
- equalJSON (
30
+ testToJSON (
31
31
{ apple : 7 , pear : 5 } ,
32
32
'{"apple":7,"pear":5}' ,
33
33
'Objects with multiple members should be separated by a comma'
34
34
) ;
35
- equalJSON (
35
+ testToJSON (
36
36
2.5 ,
37
37
'2.5' ,
38
38
'Numbers with a decimal'
39
39
) ;
40
- equalJSON (
40
+ testToJSON (
41
41
25 ,
42
42
'25' ,
43
43
'Number'
44
44
) ;
45
- equalJSON (
45
+ testToJSON (
46
46
[ 2 , 5 ] ,
47
47
'[2,5]' ,
48
48
'Array of numbers'
49
49
) ;
50
- equalJSON (
50
+ testToJSON (
51
51
function ( ) { } ,
52
52
undefined ,
53
53
'Functions are not supported and should return undefined'
54
54
) ;
55
- equalJSON (
55
+ testToJSON (
56
56
'C:\\A.TXT' ,
57
57
'"C:\\\\A.TXT"' ,
58
58
'Slashes should be double escaped'
59
59
) ;
60
- equalJSON (
60
+ testToJSON (
61
61
'C:\\B.TXT' ,
62
62
'"C:\\\\B.TXT"' ,
63
63
'Slashes should be double escaped'
64
64
) ;
65
- equalJSON (
65
+ testToJSON (
66
66
[ 'C:\\A.TXT' , 'C:\\B.TXT' , 'C:\\C.TXT' , 'C:\\D.TXT' ] ,
67
67
'["C:\\\\A.TXT","C:\\\\B.TXT","C:\\\\C.TXT","C:\\\\D.TXT"]' ,
68
68
'Array of strings with slashes'
69
69
) ;
70
- equalJSON (
70
+ testToJSON (
71
71
{ 'dDefault' : '1.84467440737E+19' } ,
72
72
'{"dDefault":"1.84467440737E+19"}' ,
73
73
'Object with lower case key and value that should not be touched'
74
74
) ;
75
- equalJSON (
75
+ testToJSON (
76
76
[ 0 , false , function ( ) { } ] ,
77
77
'[0,false,null]' ,
78
78
'Resolve unsupported values (like functions) to null when encountered as object member values'
79
79
) ;
80
- equalJSON (
80
+ testToJSON (
81
81
0 ,
82
82
'0' ,
83
83
'Zero is zero'
84
84
) ;
85
- equalJSON (
85
+ testToJSON (
86
86
false ,
87
87
'false' ,
88
88
'False is false'
89
89
) ;
90
- equalJSON (
90
+ testToJSON (
91
91
null ,
92
92
'null' ,
93
93
'null is null'
94
94
) ;
95
- equalJSON (
95
+ testToJSON (
96
96
undefined ,
97
97
undefined ,
98
98
'undefined is not valid and should not return a string "undefined" but literally undefined'
@@ -105,7 +105,7 @@ test( 'Dates', function(){
105
105
// '1224892800000' is the Epoch timestamp of midnight October 25, 2008.
106
106
// Using that instead of Date(2008,10,25) to avoid errors when the user
107
107
// running the tests is not in a UTC +00:00 timezone (which is very likely)
108
- equalJSON (
108
+ testToJSON (
109
109
new Date ( 1224892800000 ) ,
110
110
'"2008-10-25T00:00:00.000Z"' ,
111
111
'Check date handling, likely the browser itself'
@@ -123,7 +123,7 @@ test( 'Dates', function(){
123
123
JSON . stringify = null ;
124
124
}
125
125
126
- equalJSON (
126
+ testToJSON (
127
127
new Date ( 1224892800000 ) ,
128
128
'"2008-10-25T00:00:00.000Z"' ,
129
129
'Testing fallback, any native browser handling disabled'
@@ -135,7 +135,7 @@ test( 'Dates', function(){
135
135
JSON . stringify = jsonStringify ;
136
136
}
137
137
138
- equalJSON (
138
+ testToJSON (
139
139
new Date ( 1224892800000 ) ,
140
140
'"2008-10-25T00:00:00.000Z"' ,
141
141
'Sanity check in case something screwed up'
@@ -146,7 +146,7 @@ test( 'Dates', function(){
146
146
test ( 'Function arguments object' , function ( ) {
147
147
148
148
function argTest ( one , two , three ) {
149
- equalJSON (
149
+ testToJSON (
150
150
arguments ,
151
151
'{"0":"foo","1":"bar","2":"baz"}' ,
152
152
'arguments, as instance of Arguments, should be treated as an object'
@@ -160,12 +160,12 @@ test( 'Function arguments object', function(){
160
160
test ( 'Undefined and null' , function ( ) {
161
161
162
162
163
- equalJSON (
163
+ testToJSON (
164
164
{ apple : undefined , pear : 5 } ,
165
165
'{"pear":5}' ,
166
166
'Objects with a member with value of type undefined should be removed'
167
167
) ;
168
- equalJSON (
168
+ testToJSON (
169
169
[ undefined , undefined , 1 , 2 ] ,
170
170
'[null,null,1,2]' ,
171
171
'Resolve undefined to null when encountered as object member values'
0 commit comments