From a357649da5d9f0633fa8e8a249f58dfc1105698e Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Mon, 20 May 2013 19:10:04 +0200 Subject: fix(angular.equals): add support for regular expressions Regular expression objects didn't used to be considered to be equal when using 'angular.equals'. Dirty checking therefore failed to recognize a property modification. Closes #2685 Conflicts: test/AngularSpec.js --- test/AngularSpec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 8e4fbb1a..bcb110d7 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -268,6 +268,17 @@ describe('angular', function() { expect(equals(new Date(0), 0)).toBe(false); expect(equals(0, new Date(0))).toBe(false); }); + + it('should compare regular expressions', function() { + expect(equals(/abc/, /abc/)).toBe(true); + expect(equals(/abc/i, new RegExp('abc', 'i'))).toBe(true); + expect(equals(new RegExp('abc', 'i'), new RegExp('abc', 'i'))).toBe(true); + expect(equals(new RegExp('abc', 'i'), new RegExp('abc'))).toBe(false); + expect(equals(/abc/i, /abc/)).toBe(false); + expect(equals(/abc/, /def/)).toBe(false); + expect(equals(/^abc/, /abc/)).toBe(false); + expect(equals(/^abc/, '/^abc/')).toBe(false); + }); }); describe('size', function() { @@ -625,6 +636,23 @@ describe('angular', function() { }); }); + + describe('isRegExp', function() { + it('should return true for RegExp object', function() { + expect(isRegExp(/^foobar$/)).toBe(true); + expect(isRegExp(new RegExp('^foobar$/'))).toBe(true); + }); + + it('should return false for non RegExp objects', function() { + expect(isRegExp([])).toBe(false); + expect(isRegExp('')).toBe(false); + expect(isRegExp(23)).toBe(false); + expect(isRegExp({})).toBe(false); + expect(isRegExp(new Date())).toBe(false); + }); + }); + + describe('compile', function() { it('should link to existing node and create scope', inject(function($rootScope, $compile) { var template = angular.element('