| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   isPresent, | 
					
						
							|  |  |  |   RegExpWrapper, | 
					
						
							|  |  |  |   RegExpMatcherWrapper, | 
					
						
							|  |  |  |   StringWrapper, | 
					
						
							|  |  |  |   CONST_EXPR, | 
					
						
							|  |  |  |   hasConstructor, | 
					
						
							|  |  |  |   resolveEnumToken | 
					
						
							|  |  |  | } from 'angular2/src/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 16:38:50 -08:00
										 |  |  | enum UsefulEnum { | 
					
						
							|  |  |  |   MyToken, | 
					
						
							|  |  |  |   MyOtherToken | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 17:46:38 -08:00
										 |  |  | class MySuperclass {} | 
					
						
							|  |  |  | class MySubclass extends MySuperclass {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2015-06-02 17:07:13 +02:00
										 |  |  |   describe('RegExp', () => { | 
					
						
							|  |  |  |     it('should expose the index for each match', () => { | 
					
						
							| 
									
										
										
										
											2015-06-23 12:46:38 +02:00
										 |  |  |       var re = /(!)/g; | 
					
						
							| 
									
										
										
										
											2015-06-02 17:07:13 +02:00
										 |  |  |       var matcher = RegExpWrapper.matcher(re, '0!23!567!!'); | 
					
						
							|  |  |  |       var indexes = []; | 
					
						
							|  |  |  |       var m; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       while (isPresent(m = RegExpMatcherWrapper.next(matcher))) { | 
					
						
							| 
									
										
										
										
											2015-06-17 11:17:21 -07:00
										 |  |  |         indexes.push(m.index); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:07:13 +02:00
										 |  |  |         expect(m[0]).toEqual('!'); | 
					
						
							|  |  |  |         expect(m[1]).toEqual('!'); | 
					
						
							|  |  |  |         expect(m.length).toBe(2); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(indexes).toEqual([1, 4, 8, 9]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-07-28 18:38:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should reset before it is reused', () => { | 
					
						
							|  |  |  |       var re = /^['"]/g; | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       var str = "'"; | 
					
						
							| 
									
										
										
										
											2015-07-28 18:38:35 -07:00
										 |  |  |       expect(RegExpWrapper.test(re, str)).toEqual(true); | 
					
						
							|  |  |  |       // If not reset, the second attempt to test results in false
 | 
					
						
							|  |  |  |       expect(RegExpWrapper.test(re, str)).toEqual(true); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-03-23 13:41:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |     it("should implement replace all", () => { | 
					
						
							| 
									
										
										
										
											2016-03-23 13:41:18 -07:00
										 |  |  |       let re = /(\d)+/g; | 
					
						
							|  |  |  |       let m = RegExpWrapper.replaceAll(re, 'a1b2c', (match) => `!${match[1]}!`); | 
					
						
							|  |  |  |       expect(m).toEqual('a!1!b!2!c'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:07:13 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('const', () => { | 
					
						
							|  |  |  |     it('should support const expressions both in TS and Dart', () => { | 
					
						
							|  |  |  |       const numbers = CONST_EXPR([1, 2, 3]); | 
					
						
							|  |  |  |       expect(numbers).toEqual([1, 2, 3]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('String', () => { | 
					
						
							| 
									
										
										
										
											2015-10-31 13:04:26 -07:00
										 |  |  |     var s; | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('slice', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       beforeEach(() => { s = "abcdefghij"; }); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should return the whole string if neither start nor end are specified', | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          () => { expect(StringWrapper.slice(s)).toEqual("abcdefghij"); }); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should return up to the end if end is not specified', | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          () => { expect(StringWrapper.slice(s, 1)).toEqual("bcdefghij"); }); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should support negative start', | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          () => { expect(StringWrapper.slice(s, -1)).toEqual("j"); }); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should support negative end', | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |          () => { expect(StringWrapper.slice(s, -3, -1)).toEqual("hi"); }); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-30 17:05:02 -07:00
										 |  |  |       it('should return empty string if start is greater than end', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         expect(StringWrapper.slice(s, 4, 2)).toEqual(""); | 
					
						
							|  |  |  |         expect(StringWrapper.slice(s, -2, -4)).toEqual(""); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:05:02 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-08-30 17:04:15 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |     describe('stripLeft', () => { | 
					
						
							|  |  |  |       it('should strip the first character of the string if it matches the provided input', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         var input = "~angular2 is amazing"; | 
					
						
							|  |  |  |         var expectedOutput = "angular2 is amazing"; | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         expect(StringWrapper.stripLeft(input, "~")).toEqual(expectedOutput); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should keep stripping characters from the start until the first unmatched character', | 
					
						
							|  |  |  |          () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |            var input = "#####hello"; | 
					
						
							|  |  |  |            var expectedOutput = "hello"; | 
					
						
							|  |  |  |            expect(StringWrapper.stripLeft(input, "#")).toEqual(expectedOutput); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-16 15:47:48 +08:00
										 |  |  |       it('should not alter the provided input if the first character does not match the provided input', | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |          () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |            var input = "+angular2 is amazing"; | 
					
						
							|  |  |  |            expect(StringWrapper.stripLeft(input, "*")).toEqual(input); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not do any alterations when an empty string or null value is passed in', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         expect(StringWrapper.stripLeft("", "S")).toEqual(""); | 
					
						
							|  |  |  |         expect(StringWrapper.stripLeft(null, "S")).toEqual(null); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('stripRight', () => { | 
					
						
							|  |  |  |       it('should strip the first character of the string if it matches the provided input', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         var input = "angular2 is amazing!"; | 
					
						
							|  |  |  |         var expectedOutput = "angular2 is amazing"; | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         expect(StringWrapper.stripRight(input, "!")).toEqual(expectedOutput); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-16 15:47:48 +08:00
										 |  |  |       it('should not alter the provided input if the first character does not match the provided input', | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |          () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |            var input = "angular2 is amazing+"; | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |            expect(StringWrapper.stripRight(input, "*")).toEqual(input); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should keep stripping characters from the end until the first unmatched character', | 
					
						
							|  |  |  |          () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |            var input = "hi&!&&&&&"; | 
					
						
							|  |  |  |            var expectedOutput = "hi&!"; | 
					
						
							|  |  |  |            expect(StringWrapper.stripRight(input, "&")).toEqual(expectedOutput); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not do any alterations when an empty string or null value is passed in', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |         expect(StringWrapper.stripRight("", "S")).toEqual(""); | 
					
						
							|  |  |  |         expect(StringWrapper.stripRight(null, "S")).toEqual(null); | 
					
						
							| 
									
										
										
										
											2015-12-05 02:21:38 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-02-09 17:46:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 16:38:50 -08:00
										 |  |  |     describe('resolveEnumToken', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       it("should resolve a token given an enum and index values", () => { | 
					
						
							| 
									
										
										
										
											2016-03-08 16:38:50 -08:00
										 |  |  |         var token = UsefulEnum.MyToken; | 
					
						
							|  |  |  |         expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyToken'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         token = UsefulEnum.MyOtherToken; | 
					
						
							|  |  |  |         expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyOtherToken'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 17:46:38 -08:00
										 |  |  |     describe('hasConstructor', () => { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       it("should be true when the type matches", | 
					
						
							| 
									
										
										
										
											2016-02-09 17:46:38 -08:00
										 |  |  |          () => { expect(hasConstructor(new MySuperclass(), MySuperclass)).toEqual(true); }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       it("should be false for subtypes", | 
					
						
							| 
									
										
										
										
											2016-02-09 17:46:38 -08:00
										 |  |  |          () => { expect(hasConstructor(new MySubclass(), MySuperclass)).toEqual(false); }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |