diff options
| author | Andy Hitchman | 2013-08-06 11:25:44 +1000 |
|---|---|---|
| committer | Igor Minar | 2013-08-09 00:17:34 -0700 |
| commit | 5cca077e4a40a26cc2deee2a86a215f575f25b22 (patch) | |
| tree | 5af5ddf4bb2ad93d499e10fcadd3f74465649210 /test/AngularSpec.js | |
| parent | e290aa8c13205009b763f65a661a7fbcabc867ab (diff) | |
| download | angular.js-5cca077e4a40a26cc2deee2a86a215f575f25b22.tar.bz2 | |
fix(angular.copy): change angular.copy to correcly clone RegExp
angular.copy previously copied RegExp as an empty object. Change detects
RegExp instance and clones into new RegExp. This change is based on a previous
fix to allow Date to be copied.
Closes #3473
Closes #3474
Diffstat (limited to 'test/AngularSpec.js')
| -rw-r--r-- | test/AngularSpec.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index a67eb8a6..5da22174 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -31,6 +31,29 @@ describe('angular', function() { expect(copy(date) === date).toBeFalsy(); }); + it("should copy RegExp", function() { + var re = new RegExp(".*"); + expect(copy(re) instanceof RegExp).toBeTruthy(); + expect(copy(re).source).toBe(".*"); + expect(copy(re) === re).toBe(false); + }); + + it("should copy literal RegExp", function() { + var re = /.*/; + expect(copy(re) instanceof RegExp).toBeTruthy(); + expect(copy(re).source).toEqual(".*"); + expect(copy(re) === re).toBeFalsy(); + }); + + it("should deeply copy literal RegExp", function() { + var objWithRegExp = { + re: /.*/ + }; + expect(copy(objWithRegExp).re instanceof RegExp).toBeTruthy(); + expect(copy(objWithRegExp).re.source).toEqual(".*"); + expect(copy(objWithRegExp.re) === objWithRegExp.re).toBeFalsy(); + }); + it("should deeply copy an array into an existing array", function() { var src = [1, {name:"value"}]; var dst = [{key:"v"}]; |
