From 9998b8dcbb2674ac680fd6598aea0840e69c0e1b Mon Sep 17 00:00:00 2001
From: Kai Compagner
Date: Wed, 14 Jul 2010 12:08:55 -0700
Subject: fix undefine style
---
src/directives.js | 2 +-
test/directivesSpec.js | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/directives.js b/src/directives.js
index a333c4c4..6b81d864 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -255,7 +255,7 @@ angularDirective("ng:hide", function(expression, element){
angularDirective("ng:style", function(expression, element){
return function(element){
this.$onEval(function(){
- element.css(this.$eval(expression));
+ element.css(this.$eval(expression) || {});
}, element);
};
});
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index df0b5b94..ef4814bf 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -174,6 +174,13 @@ describe("directives", function(){
expect(element.css('color')).toEqual('red');
});
+ it('should silently ignore undefined ng:style', function() {
+ var scope = compile('
');
+ scope.$eval();
+ dump(sortedHtml(element));
+ expect(element.hasClass('ng-exception')).toBeFalsy();
+ });
+
it('should ng:show', function(){
var scope = compile('');
scope.$eval();
--
cgit v1.2.3
From e7b90956552bc129935e7b8dec947eb3e30f3c29 Mon Sep 17 00:00:00 2001
From: Shyam Seshadri
Date: Tue, 10 Aug 2010 19:10:43 -0700
Subject: Change repeater dsl to collect and return an array of string contents
based on match
---
src/scenario/DSL.js | 39 ++++++++++++++++++------------
test/scenario/DSLSpec.js | 63 +++++++++++++++++++++++++++++++++---------------
2 files changed, 67 insertions(+), 35 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index 96447aaf..2dd37250 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -43,6 +43,8 @@ angular.scenario.dsl.input = function(selector) {
};
},
+angular.scenario.dsl.NG_BIND_PATTERN =/\{\{[^\}]+\}\}/;
+
angular.scenario.dsl.repeater = function(selector) {
var namePrefix = "repeater '" + selector + "'";
return {
@@ -51,23 +53,30 @@ angular.scenario.dsl.repeater = function(selector) {
done(this.testDocument.find(selector).size());
});
},
- collect: function() {
- return $scenario.addFuture(namePrefix + ' collect', function(done) {
+ collect: function(collectSelector) {
+ return $scenario.addFuture(
+ namePrefix + " collect '" + collectSelector + "'",
+ function(done) {
var self = this;
var doCollect = bind(this, function() {
- var repeaterArray = [];
+ var repeaterArray = [], ngBindPattern;
+ var startIndex = collectSelector.search(
+ angular.scenario.dsl.NG_BIND_PATTERN);
+ if (startIndex >= 0) {
+ ngBindPattern = collectSelector.substring(
+ startIndex + 2, collectSelector.length - 2);
+ collectSelector = '*';
+
+ }
this.testDocument.find(selector).each(function() {
- var element = angular.extend(self.jQuery(this),
- {bindings: [],
- boundTo: function(name) { return this.bindings[name]; }}
- );
- element.find('*').each(function() {
- var bindName = self.jQuery(this).attr('ng:bind');
- if (bindName) {
- element.bindings[bindName] = self.jQuery(this).text();
- }
+ var element = self.jQuery(this);
+ element.find(collectSelector).
+ each(function() {
+ var foundElem = self.jQuery(this);
+ if (foundElem.attr('ng:bind') == ngBindPattern) {
+ repeaterArray.push(foundElem.text());
+ }
});
- repeaterArray[index] = element;
});
return repeaterArray;
});
@@ -86,9 +95,9 @@ angular.scenario.dsl.element = function(selector) {
boundTo: function(name) { return this.bindings[name]; }
});
element.find('*').each(function() {
- var bindName = self.jQuery(elem).attr('ng:bind');
+ var bindName = self.jQuery(this).attr('ng:bind');
if (bindName) {
- element.bindings[bindName] = self.jQuery(elem).text();
+ element.bindings[bindName] = self.jQuery(this).text();
}
});
done(element);
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 62de9d6c..f414db6d 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -42,6 +42,27 @@ describe("DSL", function() {
describe('repeater', function() {
var repeater = angular.scenario.dsl.repeater;
+ var html;
+ beforeEach(function() {
+ html = "" +
+ "" +
+ "| " +
+ "John Marston" +
+ " | " +
+ "" +
+ "Red Dead Redemption" +
+ " | " +
+ "
" +
+ "" +
+ "| " +
+ "Nathan Drake" +
+ " | " +
+ "" +
+ "Uncharted" +
+ " | " +
+ "
" +
+ "
";
+ });
it('should count', function() {
var future = repeater('.repeater-row').count();
expect(future.name).toEqual("repeater '.repeater-row' count");
@@ -55,29 +76,31 @@ describe("DSL", function() {
expect(future.value).toEqual(2);
});
- it('should collect', function() {
- var future = repeater('.epic').collect();
- expect(future.name).toEqual("repeater '.epic' collect");
- executeFuture(future,
- "" +
- "" +
- "| John Marston | " +
- "Red Dead Redemption | " +
- "
" +
- "" +
- "| Nathan Drake | " +
- "Uncharted 2 | " +
- "
" +
- "
",
- function(value) {
- future.fulfill(value);
+ function assertFutureState(future, expectedName, expectedValue) {
+ expect(future.name).toEqual(expectedName);
+ executeFuture(future, html, function(value) {
+ future.fulfill(value);
});
expect(future.fulfilled).toBeTruthy();
- expect(future.value[0].boundTo('hero')).toEqual('John Marston');
- expect(future.value[0].boundTo('game')).toEqual('Red Dead Redemption');
- expect(future.value[1].boundTo('hero')).toEqual('Nathan Drake');
- expect(future.value[1].boundTo('game')).toEqual('Uncharted 2');
+ expect(future.value).toEqual(expectedValue);
+ }
+ it('should collect bindings', function() {
+ assertFutureState(repeater('.epic').collect('{{hero}}'),
+ "repeater '.epic' collect '{{hero}}'",
+ ['John Marston', 'Nathan Drake']);
+ assertFutureState(repeater('.epic').collect('{{game}}'),
+ "repeater '.epic' collect '{{game}}'",
+ ['Red Dead Redemption', 'Uncharted']);
+ });
+ it('should collect normal selectors', function() {
+ assertFutureState(repeater('.epic').collect('.hero-name'),
+ "repeater '.epic' collect '.hero-name'",
+ ['John Marston', 'Nathan Drake']);
+ assertFutureState(repeater('.epic').collect('.game-name'),
+ "repeater '.epic' collect '.game-name'",
+ ['Red Dead Redemption', 'Uncharted']);
});
+ it('should collect normal attributes', function() {});
});
describe('element', function() {
--
cgit v1.2.3
From 567341c10fc7f74d5333f27514bb2201f1dbee42 Mon Sep 17 00:00:00 2001
From: Shyam Seshadri
Date: Wed, 11 Aug 2010 10:54:11 -0700
Subject: modify element dsl to understand angular bindings and return jquery
object for further checking
---
src/scenario/DSL.js | 23 +++++++++++------------
test/scenario/DSLSpec.js | 25 ++++++++++++++-----------
2 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index 2dd37250..3b049dc6 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -89,17 +89,16 @@ angular.scenario.dsl.repeater = function(selector) {
angular.scenario.dsl.element = function(selector) {
var nameSuffix = "element '" + selector + "'";
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
- var self = this;
- var element = angular.extend(this.testDocument.find(selector), {
- bindings: [],
- boundTo: function(name) { return this.bindings[name]; }
- });
- element.find('*').each(function() {
- var bindName = self.jQuery(this).attr('ng:bind');
- if (bindName) {
- element.bindings[bindName] = self.jQuery(this).text();
- }
- });
- done(element);
+ var self = this, repeaterArray = [], ngBindPattern;
+ var startIndex = selector.search(angular.scenario.dsl.NG_BIND_PATTERN);
+ if (startIndex >= 0) {
+ ngBindPattern = selector.substring(startIndex + 2, selector.length - 2);
+ var element = this.testDocument.find('*').filter(function() {
+ return self.jQuery(this).attr('ng:bind') == ngBindPattern;
+ });
+ done(element);
+ } else {
+ done(this.testDocument.find(selector));
+ }
});
};
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index f414db6d..c8e30917 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -100,7 +100,9 @@ describe("DSL", function() {
"repeater '.epic' collect '.game-name'",
['Red Dead Redemption', 'Uncharted']);
});
- it('should collect normal attributes', function() {});
+ it('should collect normal attributes', function() {
+ //TODO(shyamseshadri) : Left as an exercise to the user
+ });
});
describe('element', function() {
@@ -118,24 +120,25 @@ describe("DSL", function() {
'' +
'';
});
+ function timeTravel(future) {
+ executeFuture(future, html, function(value) { future.fulfill(value); });
+ expect(future.fulfilled).toBeTruthy();
+ }
it('should find elements on the page and provide jquery api', function() {
var future = element('.reports-detail');
expect(future.name).toEqual("Find element '.reports-detail'");
- executeFuture(future, html, function(value) { future.fulfill(value); });
- expect(future.fulfilled).toBeTruthy();
+ timeTravel(future);
expect(future.value.text()).
toEqual('Description : Details...Date created: 01/01/01');
expect(future.value.find('.desc').text()).
toEqual('Description : Details...');
});
- it('should know how to find ng:bind elements on page', function() {
- var future = element('.reports-detail');
- expect(future.name).toEqual("Find element '.reports-detail'");
- executeFuture(future, html, function(value) { future.fulfill(value); });
- expect(future.fulfilled).toBeTruthy();
- expect(future.value.boundTo('report.description')).toEqual('Details...');
- expect(future.value.boundTo('report.creationDate')).toEqual('01/01/01');
- expect(future.value.boundTo('doesnotexist')).not.toBeDefined();
+ it('should find elements with angular syntax', function() {
+ var future = element('{{report.description}}');
+ expect(future.name).toEqual("Find element '{{report.description}}'");
+ timeTravel(future);
+ expect(future.value.text()).toEqual('Details...');
+ expect(future.value.attr('ng:bind')).toEqual('report.description');
});
});
});
--
cgit v1.2.3
From 412f05977c41fbda46278b637c4d1a84996d48d1 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Wed, 11 Aug 2010 11:17:55 -0700
Subject: removed google charts and few other filters, switched to simple
optimization for compiler
---
Rakefile | 4 +-
perf/startup.html | 30 +++++
src/Angular.js | 8 --
src/filters.js | 358 ++++++++++------------------------------------------
test/FiltersTest.js | 73 -----------
5 files changed, 97 insertions(+), 376 deletions(-)
create mode 100644 perf/startup.html
diff --git a/Rakefile b/Rakefile
index bf37edce..de1f7527 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,4 @@
-include FileUtils
+ include FileUtils
task :default => [:compile, :test]
@@ -91,7 +91,7 @@ task :compile do
f.close
%x(java -jar lib/compiler-closure/compiler.jar \
- --compilation_level ADVANCED_OPTIMIZATIONS \
+ --compilation_level SIMPLE_OPTIMIZATIONS \
--js angular-debug.js \
--externs externs.js \
--create_source_map ./angular-minified.map \
diff --git a/perf/startup.html b/perf/startup.html
new file mode 100644
index 00000000..2fc948ef
--- /dev/null
+++ b/perf/startup.html
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+ READY
+
+
diff --git a/src/Angular.js b/src/Angular.js
index e11a0679..902ae013 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -307,14 +307,6 @@ function bind(_this, _function) {
}
}
-function outerHTML(node) {
- var temp = document.createElement('div');
- temp.appendChild(node);
- var outerHTML = temp.innerHTML;
- temp.removeChild(node);
- return outerHTML;
-}
-
function toBoolean(value) {
if (value && value.length !== 0) {
var v = lowercase("" + value);
diff --git a/src/filters.js b/src/filters.js
index 99d17405..27e3deca 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -1,302 +1,74 @@
-var angularFilterGoogleChartApi;
-
-foreach({
- 'currency': function(amount){
- this.$element.toggleClass('ng:format-negative', amount < 0);
- return '$' + angularFilter['number'].apply(this, [amount, 2]);
- },
-
- 'number': function(amount, fractionSize){
- if (isNaN(amount) || !isFinite(amount)) {
- return '';
- }
- fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize;
- var isNegative = amount < 0;
- amount = Math.abs(amount);
- var pow = Math.pow(10, fractionSize);
- var text = "" + Math.round(amount * pow);
- var whole = text.substring(0, text.length - fractionSize);
- whole = whole || '0';
- var frc = text.substring(text.length - fractionSize);
- text = isNegative ? '-' : '';
- for (var i = 0; i < whole.length; i++) {
- if ((whole.length - i)%3 === 0 && i !== 0) {
- text += ',';
- }
- text += whole.charAt(i);
- }
- if (fractionSize > 0) {
- for (var j = frc.length; j < fractionSize; j++) {
- frc += '0';
- }
- text += '.' + frc.substring(0, fractionSize);
- }
- return text;
- },
-
- 'date': function(date) {
- if (date instanceof Date)
- return date.toLocaleDateString();
- else
- return date;
- },
-
- 'json': function(object) {
- this.$element.addClass("ng-monospace");
- return toJson(object, true);
- },
-
- 'trackPackage': (function(){
- var MATCHERS = [
- { name: "UPS",
- url: "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_US&track.x=0&track.y=0&InquiryNumber1=",
- regexp: [
- /^1Z[0-9A-Z]{16}$/i]},
- { name: "FedEx",
- url: "http://www.fedex.com/Tracking?tracknumbers=",
- regexp: [
- /^96\d{10}?$/i,
- /^96\d{17}?$/i,
- /^96\d{20}?$/i,
- /^\d{15}$/i,
- /^\d{12}$/i]},
- { name: "USPS",
- url: "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=",
- regexp: [
- /^(91\d{20})$/i,
- /^(91\d{18})$/i]}];
- return function(trackingNo, noMatch) {
- trackingNo = trim(trackingNo);
- var tNo = trackingNo.replace(/ /g, '');
- var returnValue;
- foreach(MATCHERS, function(carrier){
- foreach(carrier.regexp, function(regexp){
- if (!returnValue && regexp.test(tNo)) {
- var text = carrier.name + ": " + trackingNo;
- var url = carrier.url + trackingNo;
- returnValue = jqLite('');
- returnValue.text(text);
- returnValue.attr('href', url);
- }
- });
- });
- if (returnValue)
- return returnValue;
- else if (trackingNo)
- return noMatch || trackingNo + " is not recognized";
- else
- return null;
- };})(),
-
- 'link': function(obj, title) {
- if (obj) {
- var text = title || obj.text || obj;
- var url = obj.url || obj;
- if (url) {
- if (angular.validator.email(url) === null) {
- url = "mailto:" + url;
- }
- var a = jqLite('');
- a.attr('href', url);
- a.text(text);
- return a;
- }
- }
- return obj;
- },
-
-
- 'bytes': (function(){
- var SUFFIX = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
- return function(size) {
- if(size === null) return "";
-
- var suffix = 0;
- while (size > 1000) {
- size = size / 1024;
- suffix++;
- }
- var txt = "" + size;
- var dot = txt.indexOf('.');
- if (dot > -1 && dot + 2 < txt.length) {
- txt = txt.substring(0, dot + 2);
- }
- return txt + " " + SUFFIX[suffix];
- };
- })(),
-
- 'image': function(obj, width, height) {
- if (obj && obj.url) {
- var style = "", img = jqLite('
');
- if (width) {
- img.css('max-width', width + 'px');
- img.css('max-height', (height || width) + 'px');
- }
- img.attr('src', obj.url);
- return img;
+angularFilter.currency = function(amount){
+ this.$element.toggleClass('ng:format-negative', amount < 0);
+ return '$' + angularFilter['number'].apply(this, [amount, 2]);
+};
+
+angularFilter.number = function(amount, fractionSize){
+ if (isNaN(amount) || !isFinite(amount)) {
+ return '';
+ }
+ fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize;
+ var isNegative = amount < 0;
+ amount = Math.abs(amount);
+ var pow = Math.pow(10, fractionSize);
+ var text = "" + Math.round(amount * pow);
+ var whole = text.substring(0, text.length - fractionSize);
+ whole = whole || '0';
+ var frc = text.substring(text.length - fractionSize);
+ text = isNegative ? '-' : '';
+ for (var i = 0; i < whole.length; i++) {
+ if ((whole.length - i)%3 === 0 && i !== 0) {
+ text += ',';
}
- return null;
- },
-
- 'lowercase': lowercase,
-
- 'uppercase': uppercase,
-
- 'linecount': function (obj) {
- if (isString(obj)) {
- if (obj==='') return 1;
- return obj.split(/\n|\f/).length;
+ text += whole.charAt(i);
+ }
+ if (fractionSize > 0) {
+ for (var j = frc.length; j < fractionSize; j++) {
+ frc += '0';
}
- return 1;
- },
-
- 'if': function (result, expression) {
- return expression ? result : undefined;
- },
-
- 'unless': function (result, expression) {
- return expression ? undefined : result;
- },
-
- 'googleChartApi': extend(
- function(type, data, width, height) {
- data = data || {};
- var chart = {
- 'cht':type,
- 'chco':angularFilterGoogleChartApi['collect'](data, 'color'),
- 'chtt':angularFilterGoogleChartApi['title'](data),
- 'chdl':angularFilterGoogleChartApi['collect'](data, 'label'),
- 'chd':angularFilterGoogleChartApi['values'](data),
- 'chf':'bg,s,FFFFFF00'
- };
- if (_.isArray(data['xLabels'])) {
- chart['chxt']='x';
- chart['chxl']='0:|' + data.xLabels.join('|');
- }
- return angularFilterGoogleChartApi['encode'](chart, width, height);
- },
- {
- 'values': function(data){
- var seriesValues = [];
- foreach(data['series']||[], function(serie){
- var values = [];
- foreach(serie['values']||[], function(value){
- values.push(value);
- });
- seriesValues.push(values.join(','));
- });
- var values = seriesValues.join('|');
- return values === "" ? null : "t:" + values;
- },
-
- 'title': function(data){
- var titles = [];
- var title = data['title'] || [];
- foreach(_.isArray(title)?title:[title], function(text){
- titles.push(encodeURIComponent(text));
- });
- return titles.join('|');
- },
+ text += '.' + frc.substring(0, fractionSize);
+ }
+ return text;
+};
- 'collect': function(data, key){
- var outterValues = [];
- var count = 0;
- foreach(data['series']||[], function(serie){
- var innerValues = [];
- var value = serie[key] || [];
- foreach(_.isArray(value)?value:[value], function(color){
- innerValues.push(encodeURIComponent(color));
- count++;
- });
- outterValues.push(innerValues.join('|'));
- });
- return count?outterValues.join(','):null;
- },
+angularFilter.date = function(date) {
+ if (date instanceof Date)
+ return date.toLocaleDateString();
+ else
+ return date;
+};
- 'encode': function(params, width, height) {
- width = width || 200;
- height = height || width;
- var url = "http://chart.apis.google.com/chart?",
- urlParam = [],
- img = jqLite('
');
- params['chs'] = width + "x" + height;
- foreach(params, function(value, key){
- if (value) {
- urlParam.push(key + "=" + value);
- }
- });
- urlParam.sort();
- url += urlParam.join("&");
- img.attr('src', url);
- img.css({width: width + 'px', height: height + 'px'});
- return img;
- }
- }
- ),
+angularFilter.json = function(object) {
+ this.$element.addClass("ng-monospace");
+ return toJson(object, true);
+};
+angularFilter.lowercase = lowercase;
- 'qrcode': function(value, width, height) {
- return angularFilterGoogleChartApi['encode']({
- 'cht':'qr', 'chl':encodeURIComponent(value)}, width, height);
- },
- 'chart': {
- 'pie':function(data, width, height) {
- return angularFilterGoogleChartApi('p', data, width, height);
- },
- 'pie3d':function(data, width, height) {
- return angularFilterGoogleChartApi('p3', data, width, height);
- },
- 'pieConcentric':function(data, width, height) {
- return angularFilterGoogleChartApi('pc', data, width, height);
- },
- 'barHorizontalStacked':function(data, width, height) {
- return angularFilterGoogleChartApi('bhs', data, width, height);
- },
- 'barHorizontalGrouped':function(data, width, height) {
- return angularFilterGoogleChartApi('bhg', data, width, height);
- },
- 'barVerticalStacked':function(data, width, height) {
- return angularFilterGoogleChartApi('bvs', data, width, height);
- },
- 'barVerticalGrouped':function(data, width, height) {
- return angularFilterGoogleChartApi('bvg', data, width, height);
- },
- 'line':function(data, width, height) {
- return angularFilterGoogleChartApi('lc', data, width, height);
- },
- 'sparkline':function(data, width, height) {
- return angularFilterGoogleChartApi('ls', data, width, height);
- },
- 'scatter':function(data, width, height) {
- return angularFilterGoogleChartApi('s', data, width, height);
- }
- },
+angularFilter.uppercase = uppercase;
- 'html': function(html){
- return new HTML(html);
- },
+angularFilter.html = function(html){
+ return new HTML(html);
+};
- 'linky': function(text){
- if (!text) return text;
- function regExpEscape(text) {
- return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1');
- }
- var URL = /(ftp|http|https|mailto):\/\/([^\(\)|\s]+)/;
- var match;
- var raw = text;
- var html = [];
- while (match=raw.match(URL)) {
- var url = match[0].replace(/[\.\;\,\(\)\{\}\<\>]$/,'');
- var i = raw.indexOf(url);
- html.push(escapeHtml(raw.substr(0, i)));
- html.push('');
- html.push(url);
- html.push('');
- raw = raw.substring(i + url.length);
- }
- html.push(escapeHtml(raw));
- return new HTML(html.join(''));
+angularFilter.linky = function(text){
+ if (!text) return text;
+ function regExpEscape(text) {
+ return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1');
}
-}, function(v,k){angularFilter[k] = v;});
-
-angularFilterGoogleChartApi = angularFilter['googleChartApi'];
+ var URL = /(ftp|http|https|mailto):\/\/([^\(\)|\s]+)/;
+ var match;
+ var raw = text;
+ var html = [];
+ while (match=raw.match(URL)) {
+ var url = match[0].replace(/[\.\;\,\(\)\{\}\<\>]$/,'');
+ var i = raw.indexOf(url);
+ html.push(escapeHtml(raw.substr(0, i)));
+ html.push('');
+ html.push(url);
+ html.push('');
+ raw = raw.substring(i + url.length);
+ }
+ html.push(escapeHtml(raw));
+ return new HTML(html.join(''));
+};
diff --git a/test/FiltersTest.js b/test/FiltersTest.js
index 903a7a2f..d5484fd0 100644
--- a/test/FiltersTest.js
+++ b/test/FiltersTest.js
@@ -41,54 +41,6 @@ FiltersTest.prototype.testJson = function () {
assertEquals(toJson({a:"b"}, true), angular.filter.json.call({$element:jqLite('')}, {a:"b"}));
};
-FiltersTest.prototype.testPackageTracking = function () {
- var assert = function(title, trackingNo) {
- var val = angular.filter.trackPackage(trackingNo, title);
- assertNotNull("Did Not Match: " + trackingNo, val);
- assertEquals(title + ": " + trim(trackingNo), val.text());
- assertNotNull(val.attr('href'));
- };
- assert('UPS', ' 1Z 999 999 99 9999 999 9 ');
- assert('UPS', '1ZW5w5220379084747');
-
- assert('FedEx', '418822131061812');
- assert('FedEx', '9612019 5935 3267 2473 738');
- assert('FedEx', '9612019593532672473738');
- assert('FedEx', '235354667129449');
- assert('FedEx', '915368880571');
- assert('FedEx', '901712142390');
- assert('FedEx', '297391510063413');
-
- assert('USPS', '9101 8052 1390 7402 4335 49');
- assert('USPS', '9101010521297963339560');
- assert('USPS', '9102901001301038667029');
- assert('USPS', '910 27974 4490 3000 8916 56');
- assert('USPS', '9102801438635051633253');
-};
-
-FiltersTest.prototype.testLink = function() {
- var assert = function(text, url, obj){
- var val = angular.filter.link(obj);
- assertEquals('' + text + '', sortedHtml(val));
- };
- assert("url", "url", "url");
- assert("hello", "url", {text:"hello", url:"url"});
- assert("a@b.com", "mailto:a@b.com", "a@b.com");
-};
-
-FiltersTest.prototype.testImage = function(){
- assertEquals(null, angular.filter.image());
- assertEquals(null, angular.filter.image({}));
- assertEquals(null, angular.filter.image(""));
- assertEquals('http://localhost/abc', angular.filter.image({url:"http://localhost/abc"}).attr('src'));
-};
-
-FiltersTest.prototype.testQRcode = function() {
- assertEquals(
- 'http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr',
- angular.filter.qrcode('Hello world').attr('src'));
-};
-
FiltersTest.prototype.testLowercase = function() {
assertEquals('abc', angular.filter.lowercase('AbC'));
assertEquals(null, angular.filter.lowercase(null));
@@ -99,30 +51,6 @@ FiltersTest.prototype.testUppercase = function() {
assertEquals(null, angular.filter.uppercase(null));
};
-FiltersTest.prototype.testLineCount = function() {
- assertEquals(1, angular.filter.linecount(null));
- assertEquals(1, angular.filter.linecount(''));
- assertEquals(1, angular.filter.linecount('a'));
- assertEquals(2, angular.filter.linecount('a\nb'));
- assertEquals(3, angular.filter.linecount('a\nb\nc'));
-};
-
-FiltersTest.prototype.testIf = function() {
- assertEquals('A', angular.filter['if']('A', true));
- assertEquals(undefined, angular.filter['if']('A', false));
-};
-
-FiltersTest.prototype.testUnless = function() {
- assertEquals('A', angular.filter.unless('A', false));
- assertEquals(undefined, angular.filter.unless('A', true));
-};
-
-FiltersTest.prototype.testGoogleChartApiEncode = function() {
- assertEquals(
- 'http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr',
- angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).attr('src'));
-};
-
FiltersTest.prototype.testHtml = function() {
var html = angular.filter.html("acd");
expect(html instanceof HTML).toBeTruthy();
@@ -140,4 +68,3 @@ FiltersTest.prototype.testLinky = function() {
assertEquals(undefined, linky(undefined));
};
-
--
cgit v1.2.3
From b27fb8a6448b7c8d59b533fe2df9497170fbaa70 Mon Sep 17 00:00:00 2001
From: Shyam Seshadri
Date: Wed, 11 Aug 2010 11:42:04 -0700
Subject: Fix toEqual matcher to use angular.equals instead of simple ==
comparison, which breaks down for arrays and objects
---
jsTestDriver.conf | 2 +-
src/scenario/Matcher.js | 2 +-
test/scenario/MatcherSpec.js | 8 ++++++++
test/testabilityPatch.js | 15 +++++++++------
4 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/jsTestDriver.conf b/jsTestDriver.conf
index bcd01694..c7d74b75 100644
--- a/jsTestDriver.conf
+++ b/jsTestDriver.conf
@@ -8,9 +8,9 @@ load:
- src/Angular.js
- src/JSON.js
- src/*.js
+ - test/testabilityPatch.js
- src/scenario/Runner.js
- src/scenario/*.js
- - test/testabilityPatch.js
- test/angular-mocks.js
- test/scenario/*.js
- test/*.js
diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js
index 62f094c8..a9c86571 100644
--- a/src/scenario/Matcher.js
+++ b/src/scenario/Matcher.js
@@ -18,4 +18,4 @@ Matcher.addMatcher = function(name, matcher) {
};
};
-Matcher.addMatcher('toEqual', function(a,b) { return a == b; });
+Matcher.addMatcher('toEqual', angular.equals);
diff --git a/test/scenario/MatcherSpec.js b/test/scenario/MatcherSpec.js
index c47f0c25..2eddd2bc 100644
--- a/test/scenario/MatcherSpec.js
+++ b/test/scenario/MatcherSpec.js
@@ -27,4 +27,12 @@ describe('Matcher', function () {
expect(e).toEqual('Expected 456 but was 123');
}
});
+ it('should correctly match arrays', function() {
+ var future = $scenario.addFuture('Calculate first future', function(done) {
+ done(['a', 'b']);
+ });
+ matcher = new Matcher(this, future);
+ matcher.toEqual(['a', 'b']);
+ executeFutures();
+ });
});
\ No newline at end of file
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index 5d0df780..e9a88b67 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -35,22 +35,25 @@ function childNode(element, index) {
}
extend(angular, {
- 'bind': bind,
+ 'element': jqLite,
'compile': compile,
+ 'scope': createScope,
'copy': copy,
- 'element': jqLite,
'extend': extend,
+ 'equals': equals,
'foreach': foreach,
+ 'noop':noop,
+ 'bind':bind,
+ 'toJson': toJson,
+ 'fromJson': fromJson,
'identity':identity,
'isUndefined': isUndefined,
'isDefined': isDefined,
- 'isObject': isObject,
'isString': isString,
'isFunction': isFunction,
+ 'isObject': isObject,
'isNumber': isNumber,
- 'isArray': isArray,
- 'noop':noop,
- 'scope': createScope
+ 'isArray': isArray
});
--
cgit v1.2.3
From 3d5719cd44868f89352ebbedd0e1b1f2575520cb Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Wed, 11 Aug 2010 11:44:12 -0700
Subject: removed undocumented/unneeded methods from Array API
---
src/Angular.js | 20 +++++++---------
src/apis.js | 71 -------------------------------------------------------
test/ApiTest.js | 73 ---------------------------------------------------------
3 files changed, 9 insertions(+), 155 deletions(-)
diff --git a/src/Angular.js b/src/Angular.js
index 902ae013..3970f762 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -291,19 +291,17 @@ function escapeAttr(html) {
'"');
}
-function bind(_this, _function) {
- var curryArgs = slice.call(arguments, 2, arguments.length);
- if (typeof _function == 'function') {
- return curryArgs.length == 0 ?
- function() {
- return _function.apply(_this, arguments);
- } :
- function() {
- return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
- };
+function bind(self, fn) {
+ var curryArgs = arguments.length > 2 ? slice.call(arguments, 2, arguments.length) : [];
+ if (typeof fn == 'function') {
+ return curryArgs.length ? function() {
+ return arguments.length ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0, arguments.length))) : fn.apply(self, curryArgs);
+ }: function() {
+ return arguments.length ? fn.apply(self, arguments) : fn.call(self);
+ };
} else {
// in IE, native methods ore not functions and so they can not be bound (but they don't need to be)
- return _function;
+ return fn;
}
}
diff --git a/src/apis.js b/src/apis.js
index 136473b6..0cf24016 100644
--- a/src/apis.js
+++ b/src/apis.js
@@ -21,17 +21,6 @@ var angularObject = {
};
var angularArray = {
'indexOf': indexOf,
- 'include': includes,
- 'includeIf':function(array, value, condition) {
- var index = indexOf(array, value);
- if (condition) {
- if (index == -1)
- array.push(value);
- } else {
- array.splice(index, 1);
- }
- return array;
- },
'sum':function(array, expression) {
var fn = angular['Function']['compile'](expression);
var sum = 0;
@@ -49,20 +38,6 @@ var angularArray = {
array.splice(index, 1);
return value;
},
- 'find':function(array, condition, defaultValue) {
- if (!condition) return undefined;
- var fn = angular['Function']['compile'](condition);
- foreach(array, function($){
- if (fn($)){
- defaultValue = $;
- return true;
- }
- });
- return defaultValue;
- },
- 'findById':function(array, id) {
- return angular.Array.find(array, function($){return $.$id == id;}, null);
- },
'filter':function(array, expression) {
var predicates = [];
predicates.check = function(value) {
@@ -195,52 +170,6 @@ var angularArray = {
var arrayCopy = [];
for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
return arrayCopy.sort(reverse(comparator, descend));
- },
- 'orderByToggle':function(predicate, attribute) {
- var STRIP = /^([+|-])?(.*)/;
- var ascending = false;
- var index = -1;
- foreach(predicate, function($, i){
- if (index == -1) {
- if ($ == attribute) {
- ascending = true;
- index = i;
- return true;
- }
- if (($.charAt(0)=='+'||$.charAt(0)=='-') && $.substring(1) == attribute) {
- ascending = $.charAt(0) == '+';
- index = i;
- return true;
- }
- }
- });
- if (index >= 0) {
- predicate.splice(index, 1);
- }
- predicate.unshift((ascending ? "-" : "+") + attribute);
- return predicate;
- },
- 'orderByDirection':function(predicate, attribute, ascend, descend) {
- ascend = ascend || 'ng-ascend';
- descend = descend || 'ng-descend';
- var att = predicate[0] || '';
- var direction = true;
- if (att.charAt(0) == '-') {
- att = att.substring(1);
- direction = false;
- } else if(att.charAt(0) == '+') {
- att = att.substring(1);
- }
- return att == attribute ? (direction ? ascend : descend) : "";
- },
- 'merge':function(array, index, mergeValue) {
- var value = array[index];
- if (!value) {
- value = {};
- array[index] = value;
- }
- merge(mergeValue, value);
- return array;
}
};
diff --git a/test/ApiTest.js b/test/ApiTest.js
index 4035cdbb..9f09773d 100644
--- a/test/ApiTest.js
+++ b/test/ApiTest.js
@@ -18,27 +18,6 @@ ApiTest.prototype.testItShouldReturnSize = function(){
assertEquals(1, angular.Array.size([0]));
};
-ApiTest.prototype.testIncludeIf = function() {
- var array = [];
- var obj = {};
-
- angular.Array.includeIf(array, obj, true);
- angular.Array.includeIf(array, obj, true);
- assertTrue(includes(array, obj));
- assertEquals(1, array.length);
-
- angular.Array.includeIf(array, obj, false);
- assertFalse(includes(array, obj));
- assertEquals(0, array.length);
-
- angular.Array.includeIf(array, obj, 'x');
- assertTrue(includes(array, obj));
- assertEquals(1, array.length);
- angular.Array.includeIf(array, obj, '');
- assertFalse(includes(array, obj));
- assertEquals(0, array.length);
-};
-
ApiTest.prototype.testSum = function(){
assertEquals(3, angular.Array.sum([{a:"1"}, {a:"2"}], 'a'));
};
@@ -48,13 +27,6 @@ ApiTest.prototype.testSumContainingNaN = function(){
assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], function($){return $.a;}));
};
-ApiTest.prototype.testInclude = function(){
- assertTrue(angular.Array.include(['a'], 'a'));
- assertTrue(angular.Array.include(['a', 'b'], 'a'));
- assertTrue(!angular.Array.include(['c'], 'a'));
- assertTrue(!angular.Array.include(['c', 'b'], 'a'));
-};
-
ApiTest.prototype.testIndex = function(){
assertEquals(angular.Array.indexOf(['a'], 'a'), 0);
assertEquals(angular.Array.indexOf(['a', 'b'], 'a'), 0);
@@ -80,14 +52,6 @@ ApiTest.prototype.testRemove = function(){
assertEquals(items.length, 0);
};
-ApiTest.prototype.testFindById = function() {
- var items = [{$id:1}, {$id:2}, {$id:3}];
- assertNull(angular.Array.findById(items, 0));
- assertEquals(items[0], angular.Array.findById(items, 1));
- assertEquals(items[1], angular.Array.findById(items, 2));
- assertEquals(items[2], angular.Array.findById(items, 3));
-};
-
ApiTest.prototype.testFilter = function() {
var items = ["MIsKO", {name:"shyam"}, ["adam"], 1234];
assertEquals(4, angular.Array.filter(items, "").length);
@@ -161,16 +125,6 @@ ApiTest.prototype.testCount = function() {
assertEquals(1, angular.Array.count(array, 'name=="a"'));
};
-ApiTest.prototype.testFind = function() {
- var array = [{name:'a'},{name:'b'},{name:''}];
- var obj = {};
-
- assertEquals(undefined, angular.Array.find(array, 'false'));
- assertEquals('default', angular.Array.find(array, 'false', 'default'));
- assertEquals('a', angular.Array.find(array, 'name == "a"').name);
- assertEquals('', angular.Array.find(array, 'name == ""').name);
-};
-
ApiTest.prototype.testItShouldSortArray = function() {
assertEquals([2,15], angular.Array.orderBy([15,2]));
assertEquals(["a","B", "c"], angular.Array.orderBy(["c","B", "a"]));
@@ -211,33 +165,6 @@ ApiTest.prototype.testQuoteUnicode = function(){
assertEquals('"abc\\u00a0def"', angular.String.quoteUnicode('abc\u00A0def'));
};
-ApiTest.prototype.testMerge = function() {
- var array = [{name:"misko"}];
- angular.Array.merge(array, 0, {name:"", email:"email1"});
- angular.Array.merge(array, 1, {name:"adam", email:"email2"});
- assertJsonEquals([{"email":"email1","name":"misko"},{"email":"email2","name":"adam"}], array);
-};
-
-ApiTest.prototype.testOrderByToggle = function() {
- var orderByToggle = angular.Array.orderByToggle;
- var predicate = [];
- assertEquals(['+a'], orderByToggle(predicate, 'a'));
- assertEquals(['-a'], orderByToggle(predicate, 'a'));
-
- assertEquals(['-a', '-b'], orderByToggle(['-b', 'a'], 'a'));
-};
-
-ApiTest.prototype.testOrderByToggle = function() {
- var orderByDirection = angular.Array.orderByDirection;
- assertEquals("", orderByDirection(['+a','b'], 'x'));
- assertEquals("", orderByDirection(['+a','b'], 'b'));
- assertEquals('ng-ascend', orderByDirection(['a','b'], 'a'));
- assertEquals('ng-ascend', orderByDirection(['+a','b'], 'a'));
- assertEquals('ng-descend', orderByDirection(['-a','b'], 'a'));
- assertEquals('up', orderByDirection(['+a','b'], 'a', 'up', 'down'));
- assertEquals('down', orderByDirection(['-a','b'], 'a', 'up', 'down'));
-};
-
ApiTest.prototype.testDateToUTC = function(){
var date = new Date("Sep 10 2003 13:02:03 GMT");
assertEquals("date", angular.Object.typeOf(date));
--
cgit v1.2.3
From 044ecb91c10753c14e1521f95b5f0cd52ff5bf87 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Wed, 11 Aug 2010 12:04:02 -0700
Subject: clean up for better obfuscation
---
perf/startup.html | 2 ++
src/JSON.js | 6 +-----
src/Scope.js | 9 ++++-----
src/formatters.js | 49 +++++++++++++++++++++++--------------------------
src/jqLite.js | 27 ++++++++++-----------------
src/services.js | 7 ++++---
6 files changed, 44 insertions(+), 56 deletions(-)
diff --git a/perf/startup.html b/perf/startup.html
index 2fc948ef..91a46898 100644
--- a/perf/startup.html
+++ b/perf/startup.html
@@ -25,6 +25,8 @@
+ reload
+
READY