as3corelib 0.1.0 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/Gemfile +1 -4
  2. data/Gemfile.lock +7 -4
  3. data/README.textile +20 -10
  4. data/Rakefile +32 -2
  5. data/as3corelib.gemspec +13 -11
  6. data/lib/as3corelib.rb +10 -4
  7. data/lib/as3corelib/version.rb +4 -0
  8. metadata +31 -121
  9. data/build/build.properties +0 -48
  10. data/build/build.xml +0 -104
  11. data/examples/JSONExample/JSONExample.mxml +0 -73
  12. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
  13. data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
  14. data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
  15. data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
  16. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
  17. data/src/com/adobe/air/logging/FileTarget.as +0 -95
  18. data/src/com/adobe/air/net/ResourceCache.as +0 -165
  19. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
  20. data/src/com/adobe/crypto/HMAC.as +0 -127
  21. data/src/com/adobe/crypto/MD5.as +0 -281
  22. data/src/com/adobe/crypto/MD5Stream.as +0 -402
  23. data/src/com/adobe/crypto/SHA1.as +0 -289
  24. data/src/com/adobe/crypto/SHA224.as +0 -257
  25. data/src/com/adobe/crypto/SHA256.as +0 -261
  26. data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
  27. data/src/com/adobe/errors/IllegalStateError.as +0 -63
  28. data/src/com/adobe/fileformats/vcard/Address.as +0 -47
  29. data/src/com/adobe/fileformats/vcard/Email.as +0 -39
  30. data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
  31. data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
  32. data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
  33. data/src/com/adobe/images/BitString.as +0 -39
  34. data/src/com/adobe/images/JPGEncoder.as +0 -648
  35. data/src/com/adobe/images/PNGEncoder.as +0 -141
  36. data/src/com/adobe/net/DynamicURLLoader.as +0 -55
  37. data/src/com/adobe/net/IURIResolver.as +0 -76
  38. data/src/com/adobe/net/MimeTypeMap.as +0 -200
  39. data/src/com/adobe/net/URI.as +0 -2466
  40. data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
  41. data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
  42. data/src/com/adobe/protocols/dict/Database.as +0 -66
  43. data/src/com/adobe/protocols/dict/Definition.as +0 -71
  44. data/src/com/adobe/protocols/dict/Dict.as +0 -360
  45. data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
  46. data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
  47. data/src/com/adobe/protocols/dict/Response.as +0 -71
  48. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
  49. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
  50. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
  51. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
  52. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
  53. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
  54. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
  55. data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
  56. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
  57. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
  58. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
  59. data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
  60. data/src/com/adobe/serialization/json/JSON.as +0 -86
  61. data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
  62. data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
  63. data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
  64. data/src/com/adobe/serialization/json/JSONToken.as +0 -104
  65. data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
  66. data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
  67. data/src/com/adobe/utils/ArrayUtil.as +0 -187
  68. data/src/com/adobe/utils/DateUtil.as +0 -701
  69. data/src/com/adobe/utils/DictionaryUtil.as +0 -87
  70. data/src/com/adobe/utils/IntUtil.as +0 -99
  71. data/src/com/adobe/utils/NumberFormatter.as +0 -74
  72. data/src/com/adobe/utils/StringUtil.as +0 -239
  73. data/src/com/adobe/utils/XMLUtil.as +0 -168
  74. data/src/com/adobe/webapis/ServiceBase.as +0 -48
  75. data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
  76. data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
  77. data/tests/src/CoreLibTestRunner-app.xml +0 -135
  78. data/tests/src/CoreLibTestRunner.as +0 -138
  79. data/tests/src/CoreLibTestRunner.mxml +0 -46
  80. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
  81. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
  82. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
  83. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
  84. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
  85. data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
  86. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
  87. data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
  88. data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
  89. data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
  90. data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
  91. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
  92. data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
  93. data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
  94. data/tests/src/com/adobe/net/URITest.as +0 -589
  95. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
  96. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
  97. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
  98. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
  99. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
  100. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
  101. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
  102. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
  103. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
  104. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
  105. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
  106. data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
  107. data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
  108. data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
  109. data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
  110. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
  111. data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
  112. data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
  113. data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
  114. data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
  115. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
@@ -1,61 +0,0 @@
1
- /*
2
- Copyright (c) 2009, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.protocols.events
34
- {
35
- import com.adobe.protocols.dict.events.MatchStrategiesEvent;
36
-
37
- import flexunit.framework.TestCase;
38
-
39
- public class MatchStrategiesEventTest extends TestCase
40
- {
41
- public function MatchStrategiesEventTest(methodName:String=null)
42
- {
43
- super(methodName);
44
- }
45
-
46
- public function test_clone():void
47
- {
48
- var e1:MatchStrategiesEvent = new MatchStrategiesEvent(MatchStrategiesEvent.MATCH_STRATEGIES);
49
- e1.strategies = new Array();
50
-
51
- var e2:MatchStrategiesEvent = MatchStrategiesEvent(e1.clone());
52
-
53
- assertTrue("e1 != e2", e1 != e2);
54
- assertTrue("e1.cancelable == e2.cancelable", e1.cancelable == e2.cancelable);
55
- assertTrue("e1.bubbles == e2.bubbles", e1.bubbles == e2.bubbles);
56
- assertTrue("e1.type == e2.type", e1.type == e2.type);
57
- assertTrue("e1.strategies == e2.strategies", e1.strategies == e2.strategies);
58
- }
59
-
60
- }
61
- }
@@ -1,58 +0,0 @@
1
- /*
2
- Copyright (c) 2009, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.protocols.events
34
- {
35
- import com.adobe.protocols.dict.events.NoMatchEvent;
36
-
37
- import flexunit.framework.TestCase;
38
-
39
- public class NoMatchEventTest extends TestCase
40
- {
41
- public function NoMatchEventTest(methodName:String=null)
42
- {
43
- super(methodName);
44
- }
45
-
46
- public function test_clone():void
47
- {
48
- var e1:NoMatchEvent = new NoMatchEvent(NoMatchEvent.NO_MATCH);
49
-
50
- var e2:NoMatchEvent = NoMatchEvent(e1.clone());
51
-
52
- assertTrue("e1 != e2", e1 != e2);
53
- assertTrue("e1.cancelable == e2.cancelable", e1.cancelable == e2.cancelable);
54
- assertTrue("e1.bubbles == e2.bubbles", e1.bubbles == e2.bubbles);
55
- assertTrue("e1.type == e2.type", e1.type == e2.type);
56
- }
57
- }
58
- }
@@ -1,60 +0,0 @@
1
- /*
2
- Copyright (c) 2009, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.protocols.util
34
- {
35
- import com.adobe.protocols.dict.util.CompleteResponseEvent;
36
-
37
- import flexunit.framework.TestCase;
38
-
39
- public class CompletedResponseEventTest extends TestCase
40
- {
41
- public function CompletedResponseEventTest(methodName:String=null)
42
- {
43
- super(methodName);
44
- }
45
-
46
- public function test_clone():void
47
- {
48
- var e1:CompleteResponseEvent = new CompleteResponseEvent(CompleteResponseEvent.COMPLETE_RESPONSE);
49
- e1.response = "foo";
50
-
51
- var e2:CompleteResponseEvent = CompleteResponseEvent(e1.clone());
52
-
53
- assertTrue("e1 != e2", e1 != e2);
54
- assertTrue("e1.cancelable == e2.cancelable", e1.cancelable == e2.cancelable);
55
- assertTrue("e1.bubbles == e2.bubbles", e1.bubbles == e2.bubbles);
56
- assertTrue("e1.type == e2.type", e1.type == e2.type);
57
- assertTrue("e1.response == e2.response", e1.response == e2.response);
58
- }
59
- }
60
- }
@@ -1,522 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.serialization.json
34
- {
35
- import flexunit.framework.TestCase;
36
-
37
- public class JSONTest extends TestCase
38
- {
39
-
40
- public function JSONTest( methodName:String = null )
41
- {
42
- super( methodName );
43
- }
44
-
45
- /**
46
- * Helper method to verify whether or not a given input correctly
47
- * throws a JSONParseError
48
- */
49
- protected function expectParseError( jsonString:String, strict:Boolean = true ):void
50
- {
51
- var parseError:JSONParseError = null;
52
-
53
- try
54
- {
55
- var o:* = JSON.decode( jsonString, strict );
56
- fail( "Expecting parse error but one was not thrown" );
57
- }
58
- catch ( e:JSONParseError )
59
- {
60
- parseError = e;
61
- }
62
- catch ( e:Error )
63
- {
64
- throw e;
65
- }
66
-
67
- // Make sure we catch a parse error since 0xZ is an invalid number
68
- assertNotNull( parseError );
69
- }
70
-
71
- /**
72
- * Test for the JSON string true decoded to boolean true.
73
- */
74
- public function testDecodeTrue():void
75
- {
76
- var o:* = JSON.decode( "true" ) as Boolean;
77
- assertTrue( "Expected decoded true", o );
78
- }
79
-
80
- public function testDecodeFalse():void
81
- {
82
- var o:* = JSON.decode( "false" ) as Boolean;
83
- assertFalse( "Expected decoded false", o );
84
- }
85
-
86
- public function testDecodeNull():void
87
- {
88
- var o:* = JSON.decode( "null " );
89
- assertNull( "Expected decoded null", o );
90
- }
91
-
92
- public function testDecodeString():void
93
- {
94
- var string:String = "this \"is\" \t a \/ string \b \f \r \h \\ \n with \' ch\\u0061rs that should be { } http://escaped.com/";
95
- assertEquals( string, JSON.decode( JSON.encode( string ) ) );
96
-
97
- var o:String = JSON.decode( "\"http:\/\/digg.com\/security\/Simple_Digg_Hack\"" ) as String;
98
- assertEquals( "String not decoded correctly", "http://digg.com/security/Simple_Digg_Hack", o );
99
-
100
- expectParseError( "\"unterminated string" );
101
- }
102
-
103
- public function testDecodeStringWithInvalidUnicodeEscape():void
104
- {
105
- // No characters after the u
106
- expectParseError( "\"\\u\"" );
107
-
108
- // Not a hex character after the u
109
- expectParseError( "\"\\ut\"" );
110
-
111
- // Not enough characters after the u
112
- expectParseError( "\"\\u123\"" );
113
-
114
- // Unicode decodes correctly
115
- assertEquals( "a", JSON.decode( "\"\\u0061\"" ) );
116
- }
117
-
118
- // Issue #104 - http://code.google.com/p/as3corelib/issues/detail?id=104
119
- public function testDecodeStringWithControlCharacters():void
120
- {
121
- var i:int;
122
-
123
- // In strict mode, we expect an error when we try to decode a string that
124
- // contains unescaped control characters.
125
- for ( i = 0x00; i <= 0x1F; i++ )
126
- {
127
- expectParseError( "\"string with control char " + i + ": " + String.fromCharCode( i ) + "\"", true );
128
- }
129
-
130
- // In non-strict mode, we don't expect any errors
131
- for ( i = 0x00; i <= 0x1F; i++ )
132
- {
133
- var string:String = "control char " + i + ": " + String.fromCharCode( i ) + ""
134
- assertEquals( string,
135
- JSON.decode( "\"" + string + "\"", false ) );
136
- }
137
- }
138
-
139
- public function testDecodeZero():void
140
- {
141
- var n:Number = JSON.decode( "0" ) as Number;
142
- assertEquals( n, 0 );
143
- }
144
-
145
- public function testDecodeZeroWithDigitsAfterIt():void
146
- {
147
- expectParseError( "02" );
148
- }
149
-
150
- public function testDecodePositiveInt():void
151
- {
152
- var n:int = JSON.decode( "123871" ) as int;
153
- assertEquals( n, 123871 );
154
- }
155
-
156
- public function testDecodeNegativeInt():void
157
- {
158
- var n:int = JSON.decode( "-97123" ) as int;
159
- assertEquals( n, -97123 );
160
- }
161
-
162
- public function testDecodePositiveFloat():void
163
- {
164
- var n:Number = JSON.decode( "12.987324" ) as Number;
165
- assertEquals( n, 12.987324 );
166
- }
167
-
168
- public function testDecodeNegativeFloat():void
169
- {
170
- var n:Number = JSON.decode( "-1298.7324" ) as Number;
171
- assertEquals( n, -1298.7324 );
172
- }
173
-
174
- public function testDecodeFloatLeadingZeroError():void
175
- {
176
- expectParseError( "-.2" );
177
- }
178
-
179
- public function testDecodeFloatDecimalMissingError():void
180
- {
181
- expectParseError( "1." );
182
- }
183
-
184
- public function testDecodeScientificRegularExponent():void
185
- {
186
- var n:Number = JSON.decode( "6.02e2" ) as Number;
187
- assertEquals( n, 602 );
188
-
189
- n = JSON.decode( "-2e10" );
190
- assertEquals( n, -20000000000 );
191
- assertEquals( n, -2 * Math.pow( 10, 10 ) );
192
- }
193
-
194
- public function testDecodeScientificPositiveExponent():void
195
- {
196
- var n:Number = JSON.decode( "2E+9" ) as Number;
197
- assertEquals( n, 2 * Math.pow( 10, 9 ) );
198
-
199
- n = JSON.decode( "-2.2E+23" ) as Number;
200
- assertEquals( n, -2.2 * Math.pow( 10, 23 ) );
201
- }
202
-
203
- public function testDecodeScientificNegativeExponent():void
204
- {
205
- var n:Number = JSON.decode( "6.02e-23" ) as Number;
206
- assertEquals( n, 6.02 * Math.pow( 10, -23 ) );
207
-
208
- n = JSON.decode( "-4e-9" ) as Number;
209
- assertEquals( n, -4 * Math.pow( 10, -9 ) );
210
-
211
- n = JSON.decode( "0E-2" ) as Number;
212
- assertEquals( n, 0 );
213
- }
214
-
215
- public function testDecodeScientificExponentError():void
216
- {
217
- expectParseError( "1e" );
218
- }
219
-
220
- /**
221
- * In non-strict mode, we can interpret hex values as numbers
222
- */
223
- public function testDecodeHex():void
224
- {
225
- var n:Number = JSON.decode( "0xFF0033", false );
226
- assertEquals( 0xFF0033, n );
227
-
228
- // Verify invalid hex format throws error
229
- expectParseError( "0x", false );
230
-
231
- // Verify invalid hex format throws error
232
- expectParseError( "0xZ", false );
233
- expectParseError( "0xz", false );
234
-
235
- // Verify that strict mode errors
236
- expectParseError( "0xFF0033" );
237
- }
238
-
239
- /**
240
- * Non-strict mode allows for NaN as a valid token
241
- */
242
- public function testDecodeNaN():void
243
- {
244
- var n:Number = JSON.decode( "NaN", false ) as Number;
245
- assertTrue( isNaN( n ) );
246
-
247
- var o:Object = JSON.decode( "{ \"num\": NaN }", false );
248
- assertNotNull( o );
249
- assertTrue( isNaN( o.num ) );
250
-
251
- // Verify that strict mode throws an error
252
- expectParseError( "NaN" );
253
- expectParseError( "{ \"num\": NaN }" );
254
- }
255
-
256
- public function testDecodeObject():void
257
- {
258
- var o:* = JSON.decode( " { \"test\": true, \"test2\": -12356732.12 } " ) as Object;
259
- assertNotNull( o );
260
-
261
- assertEquals( "Expected decoded object.test = true", true, o.test );
262
- assertEquals( "Expected decoded object.test2 = -12356732.12", -12356732.12, o.test2 );
263
- }
264
-
265
- /**
266
- * In non-strict mode, the object can have a trailing comma after
267
- * the last member and not throw an error.
268
- */
269
- public function testDecodeObjectWithTrailingComma():void
270
- {
271
- var o:Object = JSON.decode( "{\"p1\":true,\"p2\":false,}", false );
272
- assertNotNull( o );
273
- assertTrue( o.p1 );
274
- assertFalse( o.p2 );
275
-
276
- o = JSON.decode( "{,}", false );
277
- assertNotNull( o );
278
-
279
- // Verify strict mode throws error with trailing comma
280
- expectParseError( "{\"p1\":true,\"p2\":false,}" );
281
- expectParseError( "{,}" );
282
- }
283
-
284
- /**
285
- * Leading comma is not supported (yet? should they be?)
286
- */
287
- public function testDecodeObjectWithLeadingCommaFails():void
288
- {
289
- expectParseError( "[,\"p1\":true}", false );
290
- }
291
-
292
- public function testDecodeArray():void
293
- {
294
- var o:* = JSON.decode( " [ null, true, false, 100, -100, \"test\", { \"foo\": \"bar\" } ] " ) as Array;
295
- assertNull( "Expected decoded array[0] == null", o[0] );
296
- assertTrue( "Expected decoded array[1] == true", o[1] );
297
- assertFalse( "Expected decoded array[2] == false", o[2] );
298
- assertEquals( "Expected decoded array[3] == 100", 100, o[3] );
299
- assertEquals( "Expected decoded array[4] == -100", -100, o[4] );
300
- assertEquals( "Expected decoded array[5] == \"test\"", "test", o[5] );
301
- assertEquals( "Expected decoded array[6].foo == \"bar\"", "bar", o[6].foo );
302
- }
303
-
304
- public function testDecodeArrayWithNewlines():void
305
- {
306
- var o:Array = JSON.decode( "\n [ \nnull, \n \r \t \r true \n ] \r \t \r \n" ) as Array;
307
-
308
- assertNull( "Expected decoded with newlines array[0] == null", o[0] );
309
- assertTrue( "Expected decoded with newlines array[1] == true", o[1] );
310
- }
311
-
312
- /**
313
- * In non-strict mode, the array can have a trailing comma after
314
- * the last element and not throw an error.
315
- */
316
- public function testDecodeArrayWithTrailingComma():void
317
- {
318
- var o:Array = JSON.decode( "[0,1,]", false ) as Array;
319
- assertEquals( 0, o[0] );
320
- assertEquals( 1, o[1] );
321
-
322
- o = JSON.decode( "[,]", false ) as Array;
323
- assertNotNull( o );
324
- assertEquals( 0, o.length );
325
-
326
- // Verify strict mode throws error with trailing comma
327
- expectParseError( "[0,1,]" );
328
- expectParseError( "[,]" );
329
- }
330
-
331
- /**
332
- * Leading comma is not supported (yet? should they be?)
333
- */
334
- public function testDecodeArrayWithLeadingCommaFails():void
335
- {
336
- expectParseError( "[,10]", false );
337
- }
338
-
339
- public function testDecodeComments():void
340
- {
341
- expectParseError( "/*" );
342
- expectParseError( "/*/" );
343
- expectParseError( "//" );
344
-
345
- var n:Number = JSON.decode( "// this is a number\n12" );
346
- assertEquals( 12, n );
347
-
348
- n = JSON.decode( "/* \n\n multiine com//ment *///\n14" );
349
- assertEquals( 14, n )
350
- }
351
-
352
- public function testDecodeSuccessiveComments():void
353
- {
354
- var jsonString:String = " // test comment"
355
- + "\n // test comment line 2"
356
- + "\nfalse";
357
- var o:* = JSON.decode( jsonString );
358
- assertEquals( false, o );
359
- }
360
-
361
- public function testDecodeEmptyStringError():void
362
- {
363
- expectParseError( "" );
364
- }
365
-
366
- public function testDecodeWhiteSpace():void
367
- {
368
- var n:Number;
369
- var nbsp:String = String.fromCharCode( 160 ); // non-breaking space
370
-
371
- n = JSON.decode( " 1 " );
372
- assertEquals( 1, n );
373
-
374
- n = JSON.decode( "\t2\t" );
375
- assertEquals( 2, n );
376
-
377
- n = JSON.decode( "\r3\r" );
378
- assertEquals( 3, n );
379
-
380
- n = JSON.decode( "\n4\n" );
381
- assertEquals( 4, n );
382
-
383
- // Verify combined before/after spacing
384
- n = JSON.decode( "\t \n\n\r \r\n\t 100 \r\n\t\r\r\r\n \n" ) as Number
385
- assertEquals( 100, n );
386
-
387
- // In non-strict mode, we should also accept non breaking space
388
- n = JSON.decode( "\t \n"
389
- + nbsp
390
- + "\n\r \r\n\t 100 \r\n\t\r\r\r\n"
391
- + nbsp
392
- + " \n", false ) as Number
393
- assertEquals( 100, n );
394
-
395
- // In strict mode, we do NOT accept non breaking space, so expect a parse error
396
- expectParseError( "\t \n" + nbsp + "\n\r \r\n\t 100 \r\n\t\r\r\r\n" + nbsp + " \n" );
397
- }
398
-
399
- public function testDecodeWithCharactersLeftInInputString():void
400
- {
401
- // strict mode throws errors
402
- expectParseError( "[ 1 ] true" );
403
- expectParseError( "0xZ" );
404
- expectParseError( "true Z" );
405
-
406
- // non-strict mode will not throw errors
407
- var a:Array = JSON.decode( "[ 1 ] true", false ) as Array;
408
- assertEquals( 1, a[0] );
409
-
410
- var n:Number = JSON.decode( "1Z", false ) as Number;
411
- assertEquals( 1, n );
412
-
413
- var b:Boolean = JSON.decode( "true Z", false ) as Boolean;
414
- assertTrue( b );
415
- }
416
-
417
- public function testEncodeTrue():void
418
- {
419
- var o:String = JSON.encode( true );
420
- assertEquals( "Expected encoded true", "true", o );
421
- }
422
-
423
- public function testEncodeFalse():void
424
- {
425
- var o:String = JSON.encode( false );
426
- assertEquals( "Expected encoded false", "false", o );
427
- }
428
-
429
- public function testEncodeNull():void
430
- {
431
- var o:String = JSON.encode( null );
432
- assertEquals( "Expected encoded null", "null", o );
433
- }
434
-
435
- public function testEncodeString():void
436
- {
437
- var o:String = JSON.encode( "this is a \n \"string\"" );
438
- assertEquals( "Expected encoded string", "\"this is a \\n \\\"string\\\"\"", o );
439
-
440
- o = JSON.encode( "myString" );
441
- assertEquals( "\"myString\"", o );
442
- }
443
-
444
- public function testEncodeArrayEmpty():void
445
- {
446
- var o:String = JSON.encode( [] );
447
- assertEquals( "Expected encoded []", "[]", o );
448
- }
449
-
450
- public function testEncodeArray():void
451
- {
452
- var o:String = JSON.encode( [ true, false, -10, null, Number.NEGATIVE_INFINITY ] );
453
- assertTrue( "Expected encoded array", "[true,false,-10,null,null]", o );
454
- }
455
-
456
- public function testEncodeObjectEmpty():void
457
- {
458
- var o:String = JSON.encode( {} );
459
- assertTrue( "Expected encoded {}", "{}", o );
460
- }
461
-
462
- public function testEncodeObject():void
463
- {
464
- // Note: because order cannot be guaranteed when decoding
465
- // into a string, we can't reliably test an object with
466
- // multiple properties, so instead we test multiple
467
- // smaller objects
468
- //var obj:Object = new Object();
469
- //obj.test1 = true;
470
- //obj["test 2"] = false;
471
- //obj[" test _3" ] = { foo: "bar" };
472
-
473
- //var o:String = JSON.encode( obj );
474
- //assertTrue( "Expected encoded object", o == "{\"test1\":true,\"test 2\":false,\" test _3\":{\"foo\":\"bar\"}}" );
475
-
476
- var obj:Object = { foo: { foo2: { foo3: { foo4: "bar" } } } };
477
- var s:String = JSON.encode( obj );
478
- assertEquals( "Deeply nested", "{\"foo\":{\"foo2\":{\"foo3\":{\"foo4\":\"bar\"}}}}", s );
479
-
480
- obj = new Object();
481
- obj[" prop with spaces "] = true;
482
- s = JSON.encode( obj );
483
- assertEquals( "Prop with spaces", "{\" prop with spaces \":true}", s );
484
- }
485
-
486
- public function testEncodeClassInstance():void
487
- {
488
- var customObject:SimpleClass = new SimpleClass();
489
- customObject.transientVar = "Should not be encoded";
490
-
491
- var s:String = JSON.encode( customObject );
492
-
493
- assertTrue( "Has length", s.length > 0 );
494
- // Make sure the transient variable was not encoded
495
- assertEquals( "Should not find transient var in string", -1, s.indexOf( "\"transientVar\":\"Should not be encoded\"" ) );
496
-
497
- // Decode the string so we can verify that it has the properties
498
- var o:Object = JSON.decode( s );
499
-
500
- assertNotNull( o );
501
- assertNotNull( o.publicVar1 );
502
- assertNotNull( o.publicVar2 );
503
- assertNotNull( o.accessor1 );
504
- assertNotNull( o.accessor2 );
505
- assertNull( o.transientVar );
506
- assertEquals( 17, o.publicVar1 );
507
- assertEquals( 20, o.publicVar2 );
508
- assertEquals( 25, o.accessor1 );
509
- assertEquals( 30, o.accessor2 );
510
-
511
- // Make sure o only has 4 properties
512
- var count:int = 0;
513
- for ( var key:String in o )
514
- {
515
- count++;
516
- }
517
- assertEquals( 4, count );
518
- }
519
-
520
- }
521
-
522
- }