diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ApiSpecs.js | 54 | ||||
| -rw-r--r-- | test/JsonSpec.js | 59 | ||||
| -rw-r--r-- | test/angular-mocksSpec.js | 2 |
3 files changed, 59 insertions, 56 deletions
diff --git a/test/ApiSpecs.js b/test/ApiSpecs.js index 208169df..7b4a04fb 100644 --- a/test/ApiSpecs.js +++ b/test/ApiSpecs.js @@ -270,59 +270,5 @@ describe('api', function() { }); - - describe('string', function() { - it('should quote', function() { - assertEquals(angular.String.quote('a'), '"a"'); - assertEquals(angular.String.quote('\\'), '"\\\\"'); - assertEquals(angular.String.quote("'a'"), '"\'a\'"'); - assertEquals(angular.String.quote('"a"'), '"\\"a\\""'); - assertEquals(angular.String.quote('\n\f\r\t'), '"\\n\\f\\r\\t"'); - }); - - it('should quote slashes', function() { - assertEquals('"7\\\\\\\"7"', angular.String.quote("7\\\"7")); - }); - - it('should quote unicode', function() { - assertEquals('"abc\\u00a0def"', angular.String.quoteUnicode('abc\u00A0def')); - }); - - it('should read/write to date', function() { - var date = new Date("Sep 10 2003 13:02:03 GMT"); - assertEquals("date", angular.Object.typeOf(date)); - assertEquals("2003-09-10T13:02:03.000Z", angular.Date.toString(date)); - assertEquals(date.getTime(), angular.String.toDate(angular.Date.toString(date)).getTime()); - }); - - it('should convert to date', function() { - //full ISO8061 - expect(angular.String.toDate("2003-09-10T13:02:03.000Z")). - toEqual(new Date("Sep 10 2003 13:02:03 GMT")); - - //no millis - expect(angular.String.toDate("2003-09-10T13:02:03Z")). - toEqual(new Date("Sep 10 2003 13:02:03 GMT")); - - //no seconds - expect(angular.String.toDate("2003-09-10T13:02Z")). - toEqual(new Date("Sep 10 2003 13:02:00 GMT")); - - //no minutes - expect(angular.String.toDate("2003-09-10T13Z")). - toEqual(new Date("Sep 10 2003 13:00:00 GMT")); - - //no time - expect(angular.String.toDate("2003-09-10")). - toEqual(new Date("Sep 10 2003 00:00:00 GMT")); - }); - - it('should parse date', function() { - var date = angular.String.toDate("2003-09-10T13:02:03.000Z"); - assertEquals("date", angular.Object.typeOf(date)); - assertEquals("2003-09-10T13:02:03.000Z", angular.Date.toString(date)); - assertEquals("str", angular.String.toDate("str")); - }); - }); }); 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')); + }); + + }); + }); diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index 343be966..b4ceb275 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -113,7 +113,7 @@ describe('mocks', function() { //from when created from millis - var date2 = new angular.mock.TzDate(-1, angular.String.toDate('2009-12-31T23:00:00.000Z').getTime()); + var date2 = new angular.mock.TzDate(-1, date1.getTime()); expect(date2.getUTCFullYear()).toBe(2009); expect(date2.getUTCMonth()).toBe(11); expect(date2.getUTCDate()).toBe(31); |
