aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/parseSpec.js
diff options
context:
space:
mode:
authorZach Snow2013-05-12 13:12:37 -0700
committerPete Bacon Darwin2013-05-17 06:46:09 +0100
commit2a7043fa2327ecb681f306612a96dbf29ec499e7 (patch)
tree1c243298f9642947c4cfe674d57055508a4052a9 /test/ng/parseSpec.js
parent8f69ffce473f3294623d01a2c0d00ab135821396 (diff)
downloadangular.js-2a7043fa2327ecb681f306612a96dbf29ec499e7.tar.bz2
test($parse): improve clarity of ternary tests
Diffstat (limited to 'test/ng/parseSpec.js')
-rw-r--r--test/ng/parseSpec.js40
1 files changed, 29 insertions, 11 deletions
diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js
index 113ec051..7d3315b3 100644
--- a/test/ng/parseSpec.js
+++ b/test/ng/parseSpec.js
@@ -230,11 +230,11 @@ describe('parser', function() {
});
it('should parse ternary', function(){
- var f = scope.f = function(){ return true; };
- var g = scope.g = function(){ return false; };
- var h = scope.h = function(){ return 'asd'; };
- var i = scope.i = function(){ return 123; };
- var id = scope.id = function(x){ return x; };
+ var returnTrue = scope.returnTrue = function(){ return true; };
+ var returnFalse = scope.returnFalse = function(){ return false; };
+ var returnString = scope.returnString = function(){ return 'asd'; };
+ var returnInt = scope.returnInt = function(){ return 123; };
+ var identity = scope.identity = function(x){ return x; };
// Simple.
expect(scope.$eval('0?0:2')).toEqual(0?0:2);
@@ -264,15 +264,33 @@ describe('parser', function() {
// Precedence with respect to logical operators.
expect(scope.$eval('0&&1?0:1')).toEqual(0&&1?0:1);
- expect(scope.$eval('0&&1?0:1')).toEqual((0&&1)?0:1);
expect(scope.$eval('1||0?0:0')).toEqual(1||0?0:0);
- expect(scope.$eval('1||0?0:0')).toEqual((1||0)?0:0);
+
+ expect(scope.$eval('0?0&&1:2')).toEqual(0?0&&1:2);
+ expect(scope.$eval('0?1&&1:2')).toEqual(0?1&&1:2);
+ expect(scope.$eval('0?0||0:1')).toEqual(0?0||0:1);
+ expect(scope.$eval('0?0||1:2')).toEqual(0?0||1:2);
+
+ expect(scope.$eval('1?0&&1:2')).toEqual(1?0&&1:2);
+ expect(scope.$eval('1?1&&1:2')).toEqual(1?1&&1:2);
+ expect(scope.$eval('1?0||0:1')).toEqual(1?0||0:1);
+ expect(scope.$eval('1?0||1:2')).toEqual(1?0||1:2);
+
+ expect(scope.$eval('0?1:0&&1')).toEqual(0?1:0&&1);
+ expect(scope.$eval('0?2:1&&1')).toEqual(0?2:1&&1);
+ expect(scope.$eval('0?1:0||0')).toEqual(0?1:0||0);
+ expect(scope.$eval('0?2:0||1')).toEqual(0?2:0||1);
+
+ expect(scope.$eval('1?1:0&&1')).toEqual(1?1:0&&1);
+ expect(scope.$eval('1?2:1&&1')).toEqual(1?2:1&&1);
+ expect(scope.$eval('1?1:0||0')).toEqual(1?1:0||0);
+ expect(scope.$eval('1?2:0||1')).toEqual(1?2:0||1);
// Function calls.
- expect(scope.$eval('f() ? h() : i()')).toEqual(f() ? h() : i());
- expect(scope.$eval('g() ? h() : i()')).toEqual(g() ? h() : i());
- expect(scope.$eval('f() ? h() : i()')).toEqual(f() ? h() : i());
- expect(scope.$eval('id(g() ? h() : i())')).toEqual(id(g() ? h() : i()));
+ expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
+ expect(scope.$eval('returnFalse() ? returnString() : returnInt()')).toEqual(returnFalse() ? returnString() : returnInt());
+ expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
+ expect(scope.$eval('identity(returnFalse() ? returnString() : returnInt())')).toEqual(identity(returnFalse() ? returnString() : returnInt()));
});
it('should parse string', function() {