Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 2a7043f

Browse files
zachsnowpetebacondarwin
authored andcommitted
test($parse): improve clarity of ternary tests
1 parent 8f69ffc commit 2a7043f

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

test/ng/parseSpec.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ describe('parser', function() {
230230
});
231231

232232
it('should parse ternary', function(){
233-
var f = scope.f = function(){ return true; };
234-
var g = scope.g = function(){ return false; };
235-
var h = scope.h = function(){ return 'asd'; };
236-
var i = scope.i = function(){ return 123; };
237-
var id = scope.id = function(x){ return x; };
233+
var returnTrue = scope.returnTrue = function(){ return true; };
234+
var returnFalse = scope.returnFalse = function(){ return false; };
235+
var returnString = scope.returnString = function(){ return 'asd'; };
236+
var returnInt = scope.returnInt = function(){ return 123; };
237+
var identity = scope.identity = function(x){ return x; };
238238

239239
// Simple.
240240
expect(scope.$eval('0?0:2')).toEqual(0?0:2);
@@ -264,15 +264,33 @@ describe('parser', function() {
264264

265265
// Precedence with respect to logical operators.
266266
expect(scope.$eval('0&&1?0:1')).toEqual(0&&1?0:1);
267-
expect(scope.$eval('0&&1?0:1')).toEqual((0&&1)?0:1);
268267
expect(scope.$eval('1||0?0:0')).toEqual(1||0?0:0);
269-
expect(scope.$eval('1||0?0:0')).toEqual((1||0)?0:0);
268+
269+
expect(scope.$eval('0?0&&1:2')).toEqual(0?0&&1:2);
270+
expect(scope.$eval('0?1&&1:2')).toEqual(0?1&&1:2);
271+
expect(scope.$eval('0?0||0:1')).toEqual(0?0||0:1);
272+
expect(scope.$eval('0?0||1:2')).toEqual(0?0||1:2);
273+
274+
expect(scope.$eval('1?0&&1:2')).toEqual(1?0&&1:2);
275+
expect(scope.$eval('1?1&&1:2')).toEqual(1?1&&1:2);
276+
expect(scope.$eval('1?0||0:1')).toEqual(1?0||0:1);
277+
expect(scope.$eval('1?0||1:2')).toEqual(1?0||1:2);
278+
279+
expect(scope.$eval('0?1:0&&1')).toEqual(0?1:0&&1);
280+
expect(scope.$eval('0?2:1&&1')).toEqual(0?2:1&&1);
281+
expect(scope.$eval('0?1:0||0')).toEqual(0?1:0||0);
282+
expect(scope.$eval('0?2:0||1')).toEqual(0?2:0||1);
283+
284+
expect(scope.$eval('1?1:0&&1')).toEqual(1?1:0&&1);
285+
expect(scope.$eval('1?2:1&&1')).toEqual(1?2:1&&1);
286+
expect(scope.$eval('1?1:0||0')).toEqual(1?1:0||0);
287+
expect(scope.$eval('1?2:0||1')).toEqual(1?2:0||1);
270288

271289
// Function calls.
272-
expect(scope.$eval('f() ? h() : i()')).toEqual(f() ? h() : i());
273-
expect(scope.$eval('g() ? h() : i()')).toEqual(g() ? h() : i());
274-
expect(scope.$eval('f() ? h() : i()')).toEqual(f() ? h() : i());
275-
expect(scope.$eval('id(g() ? h() : i())')).toEqual(id(g() ? h() : i()));
290+
expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
291+
expect(scope.$eval('returnFalse() ? returnString() : returnInt()')).toEqual(returnFalse() ? returnString() : returnInt());
292+
expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
293+
expect(scope.$eval('identity(returnFalse() ? returnString() : returnInt())')).toEqual(identity(returnFalse() ? returnString() : returnInt()));
276294
});
277295

278296
it('should parse string', function() {

0 commit comments

Comments
 (0)