aboutsummaryrefslogtreecommitdiffstats
path: root/test/JsonSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2011-11-03 20:26:13 -0700
committerMisko Hevery2011-11-14 20:31:13 -0800
commit3972d2a89bfcfe177b12bb225302fc2937a1dbab (patch)
treedd761af120d5815898bd89982ca4a04db409b57a /test/JsonSpec.js
parentcb6f832f38b11499a6d1dd2caf14d15e68211635 (diff)
downloadangular.js-3972d2a89bfcfe177b12bb225302fc2937a1dbab.tar.bz2
refactor(json): break dependence on api.js
Diffstat (limited to 'test/JsonSpec.js')
-rw-r--r--test/JsonSpec.js59
1 files changed, 58 insertions, 1 deletions
diff --git a/test/JsonSpec.js b/test/JsonSpec.js
index d3f6de0f..736e6032 100644
--- a/test/JsonSpec.js
+++ b/test/JsonSpec.js
@@ -72,7 +72,7 @@ describe('json', function() {
});
it('should serialize UTC dates', function() {
- var date = angular.String.toDate("2009-10-09T01:02:03.027Z");
+ var date = jsonStringToDate("2009-10-09T01:02:03.027Z");
expect(toJson(date)).toEqual('"2009-10-09T01:02:03.027Z"');
expect(fromJson('"2009-10-09T01:02:03.027Z"').getTime()).toEqual(date.getTime());
});
@@ -219,4 +219,61 @@ describe('json', function() {
});
+
+ it('should read/write to date', function() {
+ var date = new Date("Sep 10 2003 13:02:03 GMT");
+ assertEquals("2003-09-10T13:02:03.000Z", jsonDateToString(date));
+ assertEquals(date.getTime(), jsonStringToDate(jsonDateToString(date)).getTime());
+ });
+
+
+ it('should convert to date', function() {
+ //full ISO8061
+ expect(jsonStringToDate("2003-09-10T13:02:03.000Z")).
+ toEqual(new Date("Sep 10 2003 13:02:03 GMT"));
+
+ //no millis
+ expect(jsonStringToDate("2003-09-10T13:02:03Z")).
+ toEqual(new Date("Sep 10 2003 13:02:03 GMT"));
+
+ //no seconds
+ expect(jsonStringToDate("2003-09-10T13:02Z")).
+ toEqual(new Date("Sep 10 2003 13:02:00 GMT"));
+
+ //no minutes
+ expect(jsonStringToDate("2003-09-10T13Z")).
+ toEqual(new Date("Sep 10 2003 13:00:00 GMT"));
+
+ //no time
+ expect(jsonStringToDate("2003-09-10")).
+ toEqual(new Date("Sep 10 2003 00:00:00 GMT"));
+ });
+
+
+ it('should parse date', function() {
+ var date = jsonStringToDate("2003-09-10T13:02:03.000Z");
+ assertEquals("2003-09-10T13:02:03.000Z", jsonDateToString(date));
+ assertEquals("str", jsonStringToDate("str"));
+ });
+
+
+ describe('string', function() {
+ it('should quote', function() {
+ assertEquals(quoteUnicode('a'), '"a"');
+ assertEquals(quoteUnicode('\\'), '"\\\\"');
+ assertEquals(quoteUnicode("'a'"), '"\'a\'"');
+ assertEquals(quoteUnicode('"a"'), '"\\"a\\""');
+ assertEquals(quoteUnicode('\n\f\r\t'), '"\\n\\f\\r\\t"');
+ });
+
+ it('should quote slashes', function() {
+ assertEquals('"7\\\\\\\"7"', quoteUnicode("7\\\"7"));
+ });
+
+ it('should quote unicode', function() {
+ assertEquals('"abc\\u00a0def"', quoteUnicode('abc\u00A0def'));
+ });
+
+ });
+
});