mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-19 20:01:52 +00:00
parent
baf52e902d
commit
0d52ff0f10
2 changed files with 35 additions and 1 deletions
|
|
@ -5,7 +5,15 @@ var OPERATORS = {
|
||||||
'true':function(){return true;},
|
'true':function(){return true;},
|
||||||
'false':function(){return false;},
|
'false':function(){return false;},
|
||||||
undefined:noop,
|
undefined:noop,
|
||||||
'+':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
|
'+':function(self, locals, a,b){
|
||||||
|
a=a(self, locals); b=b(self, locals);
|
||||||
|
if (isDefined(a)) {
|
||||||
|
if (isDefined(b)) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
return isDefined(b)?b:undefined;},
|
||||||
'-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
|
'-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
|
||||||
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
|
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
|
||||||
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},
|
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ describe('$interpolate', function() {
|
||||||
|
|
||||||
it('should suppress falsy objects', inject(function($interpolate) {
|
it('should suppress falsy objects', inject(function($interpolate) {
|
||||||
expect($interpolate('{{undefined}}')()).toEqual('');
|
expect($interpolate('{{undefined}}')()).toEqual('');
|
||||||
|
expect($interpolate('{{undefined+undefined}}')()).toEqual('');
|
||||||
expect($interpolate('{{null}}')()).toEqual('');
|
expect($interpolate('{{null}}')()).toEqual('');
|
||||||
expect($interpolate('{{a.b}}')()).toEqual('');
|
expect($interpolate('{{a.b}}')()).toEqual('');
|
||||||
}));
|
}));
|
||||||
|
|
@ -32,6 +33,31 @@ describe('$interpolate', function() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should ignore undefined model', inject(function($interpolate) {
|
||||||
|
expect($interpolate("Hello {{'World' + foo}}")()).toEqual('Hello World');
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should ignore undefined return value', inject(function($interpolate, $rootScope) {
|
||||||
|
$rootScope.foo = function() {return undefined};
|
||||||
|
expect($interpolate("Hello {{'World' + foo()}}")($rootScope)).toEqual('Hello World');
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
describe('provider', function() {
|
||||||
|
beforeEach(module(function($interpolateProvider) {
|
||||||
|
$interpolateProvider.startSymbol('--');
|
||||||
|
$interpolateProvider.endSymbol('--');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not get confused with same markers', inject(function($interpolate) {
|
||||||
|
expect($interpolate('---').parts).toEqual(['---']);
|
||||||
|
expect($interpolate('----')()).toEqual('');
|
||||||
|
expect($interpolate('--1--')()).toEqual('1');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('parseBindings', function() {
|
describe('parseBindings', function() {
|
||||||
it('should Parse Text With No Bindings', inject(function($interpolate) {
|
it('should Parse Text With No Bindings', inject(function($interpolate) {
|
||||||
var parts = $interpolate("a").parts;
|
var parts = $interpolate("a").parts;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue