Skip to content
Browse files

fixed asp tests

  • Loading branch information...
1 parent e0cf550 commit 0977e71b7d66ed8f72722de0de6cc27dde46687e @smith committed
Showing with 40 additions and 2,178 deletions.
  1. +2 −0 src/lang/string.js
  2. +2 −18 test/unit/array_test.js
  3. +1 −1 test/unit/asp/array_test.asp
  4. +1 −1 test/unit/asp/class_test.asp
  5. +1 −1 test/unit/asp/date_test.asp
  6. +1 −1 test/unit/asp/enumerable_test.asp
  7. +1 −1 test/unit/asp/function_test.asp
  8. +1 −1 test/unit/asp/hash_test.asp
  9. +1 −1 test/unit/asp/number_test.asp
  10. +1 −1 test/unit/asp/object_test.asp
  11. +1 −1 test/unit/asp/range_test.asp
  12. +1 −1 test/unit/asp/regexp_test.asp
  13. +1 −1 test/unit/asp/string_test.asp
  14. 0 test/unit/asp/tests/.unittest
  15. +0 −194 test/unit/asp/tests/array_test.js
  16. +0 −45 test/unit/asp/tests/base_test.js
  17. +0 −130 test/unit/asp/tests/class_test.js
  18. +0 −5 test/unit/asp/tests/date_test.js
  19. +0 −271 test/unit/asp/tests/enumerable_test.js
  20. +0 −134 test/unit/asp/tests/function_test.js
  21. +0 −178 test/unit/asp/tests/hash_test.js
  22. +0 −44 test/unit/asp/tests/number_test.js
  23. +0 −182 test/unit/asp/tests/object_test.js
  24. +0 −45 test/unit/asp/tests/prototype_test.js
  25. +0 −58 test/unit/asp/tests/range_test.js
  26. +0 −42 test/unit/asp/tests/regexp_test.js
  27. +0 −536 test/unit/asp/tests/string_test.js
  28. +0 −150 test/unit/asp/tests/unittest_test.js
  29. +1 −1 test/unit/asp/unittest_test.asp
  30. +2 −2 test/unit/class_test.js
  31. +2 −2 test/unit/date_test.js
  32. +2 −5 test/unit/enumerable_test.js
  33. +2 −48 test/unit/function_test.js
  34. +2 −2 test/unit/hash_test.js
  35. +2 −2 test/unit/number_test.js
  36. +2 −25 test/unit/object_test.js
  37. +2 −2 test/unit/range_test.js
  38. +2 −2 test/unit/regexp_test.js
  39. +3 −3 test/unit/string_test.js
  40. +3 −41 test/unit/unittest_test.js
View
2 src/lang/string.js
@@ -491,6 +491,8 @@ Object.extend(String.prototype, (function() {
stripScripts: stripScripts,
extractScripts: extractScripts,
evalScripts: evalScripts,
+ escapeHTML: escapeHTML,
+ unescapeHTML: unescapeHTML,
toQueryParams: toQueryParams,
parseQuery: toQueryParams,
toArray: toArray,
View
20 test/unit/array_test.js
@@ -1,6 +1,6 @@
var globalArgsTest = 'nothing to see here';
-new Test.Unit.Runner({
+var testResults = new Test.Unit.Runner({
test$A: function(){
this.assertEnumEqual([], $A({}));
},
@@ -17,22 +17,6 @@ new Test.Unit.Runner({
this.assertEnumEqual(['foo','bar'], globalArgsTest);
},
- testToArrayOnNodeList: function(){
- // direct HTML
- this.assertEqual(3, $A($('test_node').childNodes).length);
-
- // DOM
- var element = document.createElement('div');
- element.appendChild(document.createTextNode('22'));
- (2).times(function(){ element.appendChild(document.createElement('span')) });
- this.assertEqual(3, $A(element.childNodes).length);
-
- // HTML String
- element = document.createElement('div');
- $(element).update('22<span></span><span></span');
- this.assertEqual(3, $A(element.childNodes).length);
- },
-
testToArrayOnPrimitive: function() {
this.assertEnumEqual(['a', 'b', 'c'], $A('abc'));
this.assertEnumEqual([], $A(''));
@@ -193,4 +177,4 @@ new Test.Unit.Runner({
var args = (function() { return [].concat(arguments) })(1, 2);
this.assertIdentical(1, args[0][0]);
}
-});
+});
View
2 test/unit/asp/array_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
- <script src="tests/array_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../array_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/class_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
<script src="fixtures/class.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
- <script src="tests/class_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../class_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/date_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
- <script src="tests/date_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../date_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/enumerable_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
<script src="fixtures/enumerable.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
- <script src="tests/enumerable_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../enumerable_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/function_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
<script src="fixtures/function.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
- <script src="tests/function_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../function_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/hash_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
<script src="fixtures/hash.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
- <script src="tests/hash_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../hash_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/number_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
- <script src="tests/number_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../number_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/object_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
<script src="fixtures/object.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
- <script src="tests/object_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../object_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/range_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
- <script src="tests/range_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../range_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/regexp_test.asp
@@ -9,7 +9,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
- <script src="tests/regexp_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../regexp_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
2 test/unit/asp/string_test.asp
@@ -10,7 +10,7 @@
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
<script src="fixtures/string.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
- <script src="tests/string_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
+ <script src="../string_test.js" type="text/javascript" charset="utf-8" language="javascript" runat="server"></script>
</head>
<body>
View
0 test/unit/asp/tests/.unittest
No changes.
View
194 test/unit/asp/tests/array_test.js
@@ -1,194 +0,0 @@
-var globalArgsTest = 'nothing to see here';
-
-var testResults = new Test.Unit.Runner({
- test$A: function(){
- this.assertEnumEqual([], $A({}));
- },
-
- testToArrayOnArguments: function(){
- function toArrayOnArguments(){
- globalArgsTest = $A(arguments);
- }
- toArrayOnArguments();
- this.assertEnumEqual([], globalArgsTest);
- toArrayOnArguments('foo');
- this.assertEnumEqual(['foo'], globalArgsTest);
- toArrayOnArguments('foo','bar');
- this.assertEnumEqual(['foo','bar'], globalArgsTest);
- },
-/*
- testToArrayOnNodeList: function(){
- // direct HTML
- this.assertEqual(3, $A($('test_node').childNodes).length);
-
- // DOM
- var element = document.createElement('div');
- element.appendChild(document.createTextNode('22'));
- (2).times(function(){ element.appendChild(document.createElement('span')) });
- this.assertEqual(3, $A(element.childNodes).length);
-
- // HTML String
- element = document.createElement('div');
- $(element).update('22<span></span><span></span');
- this.assertEqual(3, $A(element.childNodes).length);
- },
-*/
- testClear: function(){
- this.assertEnumEqual([], [].clear());
- this.assertEnumEqual([], [1].clear());
- this.assertEnumEqual([], [1,2].clear());
- },
-
- testClone: function(){
- this.assertEnumEqual([], [].clone());
- this.assertEnumEqual([1], [1].clone());
- this.assertEnumEqual([1,2], [1,2].clone());
- this.assertEnumEqual([0,1,2], [0,1,2].clone());
- var a = [0,1,2];
- var b = a;
- this.assertIdentical(a, b);
- b = a.clone();
- this.assertNotIdentical(a, b);
- },
-
- testFirst: function(){
- this.assertUndefined([].first());
- this.assertEqual(1, [1].first());
- this.assertEqual(1, [1,2].first());
- },
-
- testLast: function(){
- this.assertUndefined([].last());
- this.assertEqual(1, [1].last());
- this.assertEqual(2, [1,2].last());
- },
-
- testCompact: function(){
- this.assertEnumEqual([], [].compact());
- this.assertEnumEqual([1,2,3], [1,2,3].compact());
- this.assertEnumEqual([0,1,2,3], [0,null,1,2,undefined,3].compact());
- this.assertEnumEqual([1,2,3], [null,1,2,3,null].compact());
- },
-
- testFlatten: function(){
- this.assertEnumEqual([], [].flatten());
- this.assertEnumEqual([1,2,3], [1,2,3].flatten());
- this.assertEnumEqual([1,2,3], [1,[[[2,3]]]].flatten());
- this.assertEnumEqual([1,2,3], [[1],[2],[3]].flatten());
- this.assertEnumEqual([1,2,3], [[[[[[[1]]]]]],2,3].flatten());
- },
-
- testIndexOf: function(){
- this.assertEqual(-1, [].indexOf(1));
- this.assertEqual(-1, [0].indexOf(1));
- this.assertEqual(0, [1].indexOf(1));
- this.assertEqual(1, [0,1,2].indexOf(1));
- this.assertEqual(0, [1,2,1].indexOf(1));
- this.assertEqual(2, [1,2,1].indexOf(1, -1));
- this.assertEqual(1, [undefined,null].indexOf(null));
- },
-
- testLastIndexOf: function(){
- this.assertEqual(-1,[].lastIndexOf(1));
- this.assertEqual(-1, [0].lastIndexOf(1));
- this.assertEqual(0, [1].lastIndexOf(1));
- this.assertEqual(2, [0,2,4,6].lastIndexOf(4));
- this.assertEqual(3, [4,4,2,4,6].lastIndexOf(4));
- this.assertEqual(3, [0,2,4,6].lastIndexOf(6,3));
- this.assertEqual(-1, [0,2,4,6].lastIndexOf(6,2));
- this.assertEqual(0, [6,2,4,6].lastIndexOf(6,2));
-
- var fixture = [1,2,3,4,3];
- this.assertEqual(4, fixture.lastIndexOf(3));
- this.assertEnumEqual([1,2,3,4,3],fixture);
-
- //tests from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:lastIndexOf
- var array = [2, 5, 9, 2];
- this.assertEqual(3,array.lastIndexOf(2));
- this.assertEqual(-1,array.lastIndexOf(7));
- this.assertEqual(3,array.lastIndexOf(2,3));
- this.assertEqual(0,array.lastIndexOf(2,2));
- this.assertEqual(0,array.lastIndexOf(2,-2));
- this.assertEqual(3,array.lastIndexOf(2,-1));
- },
-
- testInspect: function(){
- this.assertEqual('[]',[].inspect());
- this.assertEqual('[1]',[1].inspect());
- this.assertEqual('[\'a\']',['a'].inspect());
- this.assertEqual('[\'a\', 1]',['a',1].inspect());
- },
-
- testIntersect: function(){
- this.assertEnumEqual([1,3], [1,1,3,5].intersect([1,2,3]));
- this.assertEnumEqual([1], [1,1].intersect([1,1]));
- this.assertEnumEqual([], [1,1,3,5].intersect([4]));
- this.assertEnumEqual([], [1].intersect(['1']));
-
- this.assertEnumEqual(
- ['B','C','D'],
- $R('A','Z').toArray().intersect($R('B','D').toArray())
- );
- },
-
- testToJSON: function(){
- this.assertEqual('[]', [].toJSON());
- this.assertEqual('[\"a\"]', ['a'].toJSON());
- this.assertEqual('[\"a\", 1]', ['a', 1].toJSON());
- this.assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON());
- },
-
- testReduce: function(){
- this.assertUndefined([].reduce());
- this.assertNull([null].reduce());
- this.assertEqual(1, [1].reduce());
- this.assertEnumEqual([1,2,3], [1,2,3].reduce());
- this.assertEnumEqual([1,null,3], [1,null,3].reduce());
- },
-
- testReverse: function(){
- this.assertEnumEqual([], [].reverse());
- this.assertEnumEqual([1], [1].reverse());
- this.assertEnumEqual([2,1], [1,2].reverse());
- this.assertEnumEqual([3,2,1], [1,2,3].reverse());
- },
-
- testSize: function(){
- this.assertEqual(4, [0, 1, 2, 3].size());
- this.assertEqual(0, [].size());
- },
-
- testUniq: function(){
- this.assertEnumEqual([1], [1, 1, 1].uniq());
- this.assertEnumEqual([1], [1].uniq());
- this.assertEnumEqual([], [].uniq());
- this.assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
- this.assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
- },
-
- testWithout: function(){
- this.assertEnumEqual([], [].without(0));
- this.assertEnumEqual([], [0].without(0));
- this.assertEnumEqual([1], [0,1].without(0));
- this.assertEnumEqual([1,2], [0,1,2].without(0));
- },
-
- test$w: function(){
- this.assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
- this.assertEnumEqual([], $w(' '));
- this.assertEnumEqual([], $w(''));
- this.assertEnumEqual([], $w(null));
- this.assertEnumEqual([], $w(undefined));
- this.assertEnumEqual([], $w());
- this.assertEnumEqual([], $w(10));
- this.assertEnumEqual(['a'], $w('a'));
- this.assertEnumEqual(['a'], $w('a '));
- this.assertEnumEqual(['a'], $w(' a'));
- this.assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
- },
-
- testConcat: function(){
- var args = (function() { return [].concat(arguments) })(1, 2);
- this.assertIdentical(1, args[0][0]);
- }
-});
View
45 test/unit/asp/tests/base_test.js
@@ -1,45 +0,0 @@
-var testResults = new Test.Unit.Runner({
-/*
- testBrowserDetection: function() {
- var results = $H(Prototype.Browser).map(function(engine){
- return engine;
- }).partition(function(engine){
- return engine[1] === true
- });
- var trues = results[0], falses = results[1];
-
- this.info('User agent string is: ' + navigator.userAgent);
-
- this.assert(trues.size() == 0 || trues.size() == 1,
- 'There should be only one or no browser detected.');
-
- // we should have definite trues or falses here
- trues.each(function(result) {
- this.assert(result[1] === true);
- }, this);
- falses.each(function(result) {
- this.assert(result[1] === false);
- }, this);
-
- if(navigator.userAgent.indexOf('AppleWebKit/') > -1) {
- this.info('Running on WebKit');
- this.assert(Prototype.Browser.WebKit);
- }
-
- if(!!window.opera) {
- this.info('Running on Opera');
- this.assert(Prototype.Browser.Opera);
- }
-
- if(!!(window.attachEvent && !window.opera)) {
- this.info('Running on IE');
- this.assert(Prototype.Browser.IE);
- }
-
- if(navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1) {
- this.info('Running on Gecko');
- this.assert(Prototype.Browser.Gecko);
- }
- }
-*/
-});
View
130 test/unit/asp/tests/class_test.js
@@ -1,130 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testClassCreate: function() {
- this.assert(Object.isFunction(Animal), 'Animal is not a constructor');
- this.assertEnumEqual([Cat, Mouse, Dog, Ox], Animal.subclasses);
- Animal.subclasses.each(function(subclass) {
- this.assertEqual(Animal, subclass.superclass);
- }, this);
-
- var Bird = Class.create(Animal);
- this.assertEqual(Bird, Animal.subclasses.last());
- // for..in loop (for some reason) doesn't iterate over the constructor property in top-level classes
- this.assertEnumEqual(Object.keys(new Animal).sort(), Object.keys(new Bird).without('constructor').sort());
- },
-
- testClassInstantiation: function() {
- var pet = new Animal("Nibbles");
- this.assertEqual("Nibbles", pet.name, "property not initialized");
- this.assertEqual('Nibbles: Hi!', pet.say('Hi!'));
- this.assertEqual(Animal, pet.constructor, "bad constructor reference");
- this.assertUndefined(pet.superclass);
-
- var Empty = Class.create();
- this.assert('object', typeof new Empty);
- },
-
- testInheritance: function() {
- var tom = new Cat('Tom');
- this.assertEqual(Cat, tom.constructor, "bad constructor reference");
- this.assertEqual(Animal, tom.constructor.superclass, 'bad superclass reference');
- this.assertEqual('Tom', tom.name);
- this.assertEqual('Tom: meow', tom.say('meow'));
- this.assertEqual('Tom: Yuk! I only eat mice.', tom.eat(new Animal));
- },
-
- testSuperclassMethodCall: function() {
- var tom = new Cat('Tom');
- this.assertEqual('Tom: Yum!', tom.eat(new Mouse));
-
- // augment the constructor and test
- var Dodo = Class.create(Animal, {
- initialize: function($super, name) {
- $super(name);
- this.extinct = true;
- },
-
- say: function($super, message) {
- return $super(message) + " honk honk";
- }
- });
-
- var gonzo = new Dodo('Gonzo');
- this.assertEqual('Gonzo', gonzo.name);
- this.assert(gonzo.extinct, 'Dodo birds should be extinct');
- this.assertEqual("Gonzo: hello honk honk", gonzo.say("hello"));
- },
-
- testClassAddMethods: function() {
- var tom = new Cat('Tom');
- var jerry = new Mouse('Jerry');
-
- Animal.addMethods({
- sleep: function() {
- return this.say('ZZZ');
- }
- });
-
- Mouse.addMethods({
- sleep: function($super) {
- return $super() + " ... no, can't sleep! Gotta steal cheese!";
- },
- escape: function(cat) {
- return this.say('(from a mousehole) Take that, ' + cat.name + '!');
- }
- });
-
- this.assertEqual('Tom: ZZZ', tom.sleep(), "added instance method not available to subclass");
- this.assertEqual("Jerry: ZZZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
- this.assertEqual("Jerry: (from a mousehole) Take that, Tom!", jerry.escape(tom));
- // insure that a method has not propagated *up* the prototype chain:
- this.assertUndefined(tom.escape);
- this.assertUndefined(new Animal().escape);
-
- Animal.addMethods({
- sleep: function() {
- return this.say('zZzZ');
- }
- });
-
- this.assertEqual("Jerry: zZzZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
- },
-
- testBaseClassWithMixin: function() {
- var grass = new Plant('grass', 3);
- this.assertRespondsTo('getValue', grass);
- this.assertEqual('#<Plant: grass>', grass.inspect());
- },
-
- testSubclassWithMixin: function() {
- var snoopy = new Dog('Snoopy', 12, 'male');
- this.assertRespondsTo('reproduce', snoopy);
- },
-
- testSubclassWithMixins: function() {
- var cow = new Ox('cow', 400, 'female');
- this.assertEqual('#<Ox: cow>', cow.inspect());
- this.assertRespondsTo('reproduce', cow);
- this.assertRespondsTo('getValue', cow);
- },
-
- testClassWithToStringAndValueOfMethods: function() {
- var Foo = Class.create({
- toString: function() { return "toString" },
- valueOf: function() { return "valueOf" }
- });
-
- var Parent = Class.create({
- m1: function(){ return 'm1' },
- m2: function(){ return 'm2' }
- });
- var Child = Class.create(Parent, {
- m1: function($super) { return 'm1 child' },
- m2: function($super) { return 'm2 child' }
- });
-
- this.assert(new Child().m1.toString().indexOf('m1 child') > -1);
-
- this.assertEqual("toString", new Foo().toString());
- this.assertEqual("valueOf", new Foo().valueOf());
- }
-});
View
5 test/unit/asp/tests/date_test.js
@@ -1,5 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testDateToJSON: function() {
- this.assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON());
- }
-});
View
271 test/unit/asp/tests/enumerable_test.js
@@ -1,271 +0,0 @@
-function prime(value) {
- for (var i = 2; i < value; i++)
- if (value % i == 0) return false;
- return true;
-}
-
-var testResults = new Test.Unit.Runner({
- testEachBreak: function() {
- var result = 0;
- Fixtures.Basic.each(function(value) {
- if ((result = value) == 2) throw $break;
- });
-
- this.assertEqual(2, result);
- },
-
- testEachReturnActsAsContinue: function() {
- var results = [];
- Fixtures.Basic.each(function(value) {
- if (value == 2) return;
- results.push(value);
- });
-
- this.assertEqual('1, 3', results.join(', '));
- },
-
- testEachChaining: function() {
- this.assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
- this.assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
- },
-
- testEnumContext: function() {
- var results = [];
- Fixtures.Basic.each(function(value) {
- results.push(value * this.i);
- }, { i: 2 });
-
- this.assertEqual('2 4 6', results.join(' '));
-
- this.assert(Fixtures.Basic.all(function(value){
- return value >= this.min && value <= this.max;
- }, { min: 1, max: 3 }));
- this.assert(!Fixtures.Basic.all(function(value){
- return value >= this.min && value <= this.max;
- }));
- this.assert(Fixtures.Basic.any(function(value){
- return value == this.target_value;
- }, { target_value: 2 }));
- },
-
- testAny: function() {
- this.assert(!([].any()));
-
- this.assert([true, true, true].any());
- this.assert([true, false, false].any());
- this.assert(![false, false, false].any());
-
- this.assert(Fixtures.Basic.any(function(value) {
- return value > 2;
- }));
- this.assert(!Fixtures.Basic.any(function(value) {
- return value > 5;
- }));
- },
-
- testAll: function() {
- this.assert([].all());
-
- this.assert([true, true, true].all());
- this.assert(![true, false, false].all());
- this.assert(![false, false, false].all());
-
- this.assert(Fixtures.Basic.all(function(value) {
- return value > 0;
- }));
- this.assert(!Fixtures.Basic.all(function(value) {
- return value > 1;
- }));
- },
-
- testCollect: function() {
- this.assertEqual(Fixtures.Nicknames.join(', '),
- Fixtures.People.collect(function(person) {
- return person.nickname;
- }).join(", "));
-
- this.assertEqual(26, Fixtures.Primes.map().length);
- },
-
- testDetect: function() {
- this.assertEqual('Marcel Molina Jr.',
- Fixtures.People.detect(function(person) {
- return person.nickname.match(/no/);
- }).name);
- },
-
- testEachSlice: function() {
- this.assertEnumEqual([], [].eachSlice(2));
- this.assertEqual(1, [1].eachSlice(1).length);
- this.assertEnumEqual([1], [1].eachSlice(1)[0]);
- this.assertEqual(2, Fixtures.Basic.eachSlice(2).length);
- this.assertEnumEqual(
- [3, 2, 1, 11, 7, 5, 19, 17, 13, 31, 29, 23, 43, 41, 37, 59, 53, 47, 71, 67, 61, 83, 79, 73, 97, 89],
- Fixtures.Primes.eachSlice( 3, function(slice){ return slice.reverse() }).flatten()
- );
- this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10));
- this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
- this.assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
- },
-
- testEachWithIndex: function() {
- var nicknames = [], indexes = [];
- Fixtures.People.each(function(person, index) {
- nicknames.push(person.nickname);
- indexes.push(index);
- });
-
- this.assertEqual(Fixtures.Nicknames.join(', '),
- nicknames.join(', '));
- this.assertEqual('0, 1, 2, 3', indexes.join(', '));
- },
-
- testFindAll: function() {
- this.assertEqual(Fixtures.Primes.join(', '),
- Fixtures.Z.findAll(prime).join(', '));
- },
-
- testGrep: function() {
- this.assertEqual('noradio, htonl',
- Fixtures.Nicknames.grep(/o/).join(", "));
-
- this.assertEqual('NORADIO, HTONL',
- Fixtures.Nicknames.grep(/o/, function(nickname) {
- return nickname.toUpperCase();
- }).join(", "))
-
- //this.assertEnumEqual($('grepHeader', 'grepCell'),
- //$('grepTable', 'grepTBody', 'grepRow', 'grepHeader', 'grepCell').grep(new Selector('.cell')));
-
- // troublesome characters
- this.assertEnumEqual(['?a', 'c?'], ['?a','b','c?'].grep('?'));
- this.assertEnumEqual(['*a', 'c*'], ['*a','b','c*'].grep('*'));
- this.assertEnumEqual(['+a', 'c+'], ['+a','b','c+'].grep('+'));
- this.assertEnumEqual(['{1}a', 'c{1}'], ['{1}a','b','c{1}'].grep('{1}'));
- this.assertEnumEqual(['(a', 'c('], ['(a','b','c('].grep('('));
- this.assertEnumEqual(['|a', 'c|'], ['|a','b','c|'].grep('|'));
- },
-
- testInclude: function() {
- this.assert(Fixtures.Nicknames.include('sam-'));
- this.assert(Fixtures.Nicknames.include('noradio'));
- this.assert(!Fixtures.Nicknames.include('gmosx'));
- this.assert(Fixtures.Basic.include(2));
- this.assert(Fixtures.Basic.include('2'));
- this.assert(!Fixtures.Basic.include('4'));
- },
-
- testInGroupsOf: function() {
- this.assertEnumEqual([], [].inGroupsOf(3));
-
- var arr = [1, 2, 3, 4, 5, 6].inGroupsOf(3);
- this.assertEqual(2, arr.length);
- this.assertEnumEqual([1, 2, 3], arr[0]);
- this.assertEnumEqual([4, 5, 6], arr[1]);
-
- arr = [1, 2, 3, 4, 5, 6].inGroupsOf(4);
- this.assertEqual(2, arr.length);
- this.assertEnumEqual([1, 2, 3, 4], arr[0]);
- this.assertEnumEqual([5, 6, null, null], arr[1]);
-
- var basic = Fixtures.Basic
-
- arr = basic.inGroupsOf(4,'x');
- this.assertEqual(1, arr.length);
- this.assertEnumEqual([1, 2, 3, 'x'], arr[0]);
-
- this.assertEnumEqual([1,2,3,'a'], basic.inGroupsOf(2, 'a').flatten());
-
- arr = basic.inGroupsOf(5, '');
- this.assertEqual(1, arr.length);
- this.assertEnumEqual([1, 2, 3, '', ''], arr[0]);
-
- this.assertEnumEqual([1,2,3,0], basic.inGroupsOf(2, 0).flatten());
- this.assertEnumEqual([1,2,3,false], basic.inGroupsOf(2, false).flatten());
- },
-
- testInject: function() {
- this.assertEqual(1061,
- Fixtures.Primes.inject(0, function(sum, value) {
- return sum + value;
- }));
- },
-
- testInvoke: function() {
- var result = [[2, 1, 3], [6, 5, 4]].invoke('sort');
- this.assertEqual(2, result.length);
- this.assertEqual('1, 2, 3', result[0].join(', '));
- this.assertEqual('4, 5, 6', result[1].join(', '));
-
- result = result.invoke('invoke', 'toString', 2);
- this.assertEqual('1, 10, 11', result[0].join(', '));
- this.assertEqual('100, 101, 110', result[1].join(', '));
- },
-
- testMax: function() {
- this.assertEqual(100, Fixtures.Z.max());
- this.assertEqual(97, Fixtures.Primes.max());
- this.assertEqual(2, [ -9, -8, -7, -6, -4, -3, -2, 0, -1, 2 ].max());
- this.assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
- },
-
- testMin: function() {
- this.assertEqual(1, Fixtures.Z.min());
- this.assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
- this.assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
- },
-
- testPartition: function() {
- var result = Fixtures.People.partition(function(person) {
- return person.name.length < 15;
- }).invoke('pluck', 'nickname');
-
- this.assertEqual(2, result.length);
- this.assertEqual('sam-, htonl', result[0].join(', '));
- this.assertEqual('noradio, Ulysses', result[1].join(', '));
- },
-
- testPluck: function() {
- this.assertEqual(Fixtures.Nicknames.join(', '),
- Fixtures.People.pluck('nickname').join(', '));
- },
-
- testReject: function() {
- this.assertEqual(0,
- Fixtures.Nicknames.reject(Prototype.K).length);
-
- this.assertEqual('sam-, noradio, htonl',
- Fixtures.Nicknames.reject(function(nickname) {
- return nickname != nickname.toLowerCase();
- }).join(', '));
- },
-
- testSortBy: function() {
- this.assertEqual('htonl, noradio, sam-, Ulysses',
- Fixtures.People.sortBy(function(value) {
- return value.nickname.toLowerCase();
- }).pluck('nickname').join(', '));
- },
-
- testToArray: function() {
- var result = Fixtures.People.toArray();
- this.assert(result != Fixtures.People); // they're different objects...
- this.assertEqual(Fixtures.Nicknames.join(', '),
- result.pluck('nickname').join(', ')); // but the values are the same
- },
-
- testZip: function() {
- var result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9]);
- this.assertEqual('[[1, 4, 7], [2, 5, 8], [3, 6, 9]]', result.inspect());
-
- result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9], function(array) { return array.reverse() });
- this.assertEqual('[[7, 4, 1], [8, 5, 2], [9, 6, 3]]', result.inspect());
- },
-
- testSize: function() {
- this.assertEqual(4, Fixtures.People.size());
- this.assertEqual(4, Fixtures.Nicknames.size());
- this.assertEqual(26, Fixtures.Primes.size());
- this.assertEqual(0, [].size());
- }
-});
View
134 test/unit/asp/tests/function_test.js
@@ -1,134 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testFunctionArgumentNames: function() {
- this.assertEnumEqual([], (function() {}).argumentNames());
- this.assertEnumEqual(["one"], (function(one) {}).argumentNames());
- this.assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames());
- this.assertEnumEqual(["one", "two", "three"], (function( one , two
- , three ) {}).argumentNames());
- this.assertEqual("$super", (function($super) {}).argumentNames().first());
-
- function named1() {};
- this.assertEnumEqual([], named1.argumentNames());
- function named2(one) {};
- this.assertEnumEqual(["one"], named2.argumentNames());
- function named3(one, two, three) {};
- this.assertEnumEqual(["one", "two", "three"], named3.argumentNames());
- function named4(one,
- two,
-
- three) {}
- this.assertEnumEqual($w('one two three'), named4.argumentNames());
- function named5(/*foo*/ foo, /* bar */ bar, /*****/ baz) {}
- this.assertEnumEqual($w("foo bar baz"), named5.argumentNames());
- function named6(
- /*foo*/ foo,
- /**/bar,
- /* baz */ /* baz */ baz,
- // Skip a line just to screw with the regex...
- /* thud */ thud) {}
- this.assertEnumEqual($w("foo bar baz thud"), named6.argumentNames());
- },
-
- testFunctionBind: function() {
- function methodWithoutArguments() { return this.hi };
- function methodWithArguments() { return this.hi + ',' + $A(arguments).join(',') };
- var func = Prototype.emptyFunction;
-
- this.assertIdentical(func, func.bind());
- this.assertIdentical(func, func.bind(undefined));
- this.assertNotIdentical(func, func.bind(null));
-
- this.assertEqual('without', methodWithoutArguments.bind({ hi: 'without' })());
- this.assertEqual('with,arg1,arg2', methodWithArguments.bind({ hi: 'with' })('arg1','arg2'));
- this.assertEqual('withBindArgs,arg1,arg2',
- methodWithArguments.bind({ hi: 'withBindArgs' }, 'arg1', 'arg2')());
- this.assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4',
- methodWithArguments.bind({ hi: 'withBindArgsAndArgs' }, 'arg1', 'arg2')('arg3', 'arg4'));
- },
-
- testFunctionCurry: function() {
- var split = function(delimiter, string) { return string.split(delimiter); };
- var splitOnColons = split.curry(":");
- this.assertNotIdentical(split, splitOnColons);
- this.assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5"));
- this.assertIdentical(split, split.curry());
- },
-/*
- testFunctionDelay: function() {
- window.delayed = undefined;
- var delayedFunction = function() { window.delayed = true; };
- var delayedFunctionWithArgs = function() { window.delayedWithArgs = $A(arguments).join(' '); };
- delayedFunction.delay(0.8);
- delayedFunctionWithArgs.delay(0.8, 'hello', 'world');
- this.assertUndefined(window.delayed);
- this.wait(1000, function() {
- this.assert(window.delayed);
- this.assertEqual('hello world', window.delayedWithArgs);
- });
- },
-*/
- testFunctionWrap: function() {
- function sayHello(){
- return 'hello world';
- };
-
- this.assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) {
- return proceed().toUpperCase();
- })());
-
- var temp = String.prototype.capitalize;
- String.prototype.capitalize = String.prototype.capitalize.wrap(function(proceed, eachWord) {
- if(eachWord && this.include(' ')) return this.split(' ').map(function(str){
- return str.capitalize();
- }).join(' ');
- return proceed();
- });
- this.assertEqual('Hello world', 'hello world'.capitalize());
- this.assertEqual('Hello World', 'hello world'.capitalize(true));
- this.assertEqual('Hello', 'hello'.capitalize());
- String.prototype.capitalize = temp;
- },
-/*
- testFunctionDefer: function() {
- window.deferred = undefined;
- var deferredFunction = function() { window.deferred = true; };
- deferredFunction.defer();
- this.assertUndefined(window.deferred);
- this.wait(50, function() {
- this.assert(window.deferred);
-
- window.deferredValue = 0;
- var deferredFunction2 = function(arg) { window.deferredValue = arg; };
- deferredFunction2.defer('test');
- this.wait(50, function() {
- this.assertEqual('test', window.deferredValue);
- });
- });
- },
-*/
- testFunctionMethodize: function() {
- var Foo = { bar: function(baz) { return baz } };
- var baz = { quux: Foo.bar.methodize() };
-
- this.assertEqual(Foo.bar.methodize(), baz.quux);
- this.assertEqual(baz, Foo.bar(baz));
- this.assertEqual(baz, baz.quux());
- }/*,
-
- testBindAsEventListener: function() {
- for( var i = 0; i < 10; ++i ){
- var div = document.createElement('div');
- div.setAttribute('id','test-'+i);
- document.body.appendChild(div);
- var tobj = new TestObj();
- var eventTest = { test: true };
- var call = tobj.assertingEventHandler.bindAsEventListener(tobj,
- this.assertEqual.bind(this, eventTest),
- this.assertEqual.bind(this, arg1),
- this.assertEqual.bind(this, arg2),
- this.assertEqual.bind(this, arg3), arg1, arg2, arg3 );
- call(eventTest);
- }
- }
-*/
-});
View
178 test/unit/asp/tests/hash_test.js
@@ -1,178 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testSet: function() {
- var h = $H({a: 'A'})
-
- this.assertEqual('B', h.set('b', 'B'));
- this.assertHashEqual({a: 'A', b: 'B'}, h);
-
- this.assertUndefined(h.set('c'));
- this.assertHashEqual({a: 'A', b: 'B', c: undefined}, h);
- },
-
- testGet: function() {
- var h = $H({a: 'A'});
- this.assertEqual('A', h.get('a'));
- this.assertUndefined(h.a);
- this.assertUndefined($H({}).get('a'));
-
- this.assertUndefined($H({}).get('toString'));
- this.assertUndefined($H({}).get('constructor'));
- },
-
- testUnset: function() {
- var hash = $H(Fixtures.many);
- this.assertEqual('B', hash.unset('b'));
- this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
- this.assertUndefined(hash.unset('z'));
- this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
- // not equivalent to Hash#remove
- this.assertEqual('A', hash.unset('a', 'c'));
- this.assertHashEqual({c: 'C', d:'D#'}, hash);
- },
-
- testToObject: function() {
- var hash = $H(Fixtures.many), object = hash.toObject();
- this.assertInstanceOf(Object, object);
- this.assertHashEqual(Fixtures.many, object);
- this.assertNotIdentical(Fixtures.many, object);
- hash.set('foo', 'bar');
- this.assertHashNotEqual(object, hash.toObject());
- },
-
- testConstruct: function() {
- var object = Object.clone(Fixtures.one);
- var h = new Hash(object), h2 = $H(object);
- this.assertInstanceOf(Hash, h);
- this.assertInstanceOf(Hash, h2);
-
- this.assertHashEqual({}, new Hash());
- this.assertHashEqual(object, h);
- this.assertHashEqual(object, h2);
-
- h.set('foo', 'bar');
- this.assertHashNotEqual(object, h);
-
- var clone = $H(h);
- this.assertInstanceOf(Hash, clone);
- this.assertHashEqual(h, clone);
- h.set('foo', 'foo');
- this.assertHashNotEqual(h, clone);
- this.assertIdentical($H, Hash.from);
- },
-
- testKeys: function() {
- this.assertEnumEqual([], $H({}).keys());
- this.assertEnumEqual(['a'], $H(Fixtures.one).keys());
- this.assertEnumEqual($w('a b c d'), $H(Fixtures.many).keys().sort());
- this.assertEnumEqual($w('plus quad'), $H(Fixtures.functions).keys().sort());
- },
-
- testValues: function() {
- this.assertEnumEqual([], $H({}).values());
- this.assertEnumEqual(['A#'], $H(Fixtures.one).values());
- this.assertEnumEqual($w('A B C D#'), $H(Fixtures.many).values().sort());
- this.assertEnumEqual($w('function function'),
- $H(Fixtures.functions).values().map(function(i){ return typeof i }));
- this.assertEqual(9, $H(Fixtures.functions).get('quad')(3));
- this.assertEqual(6, $H(Fixtures.functions).get('plus')(3));
- },
-
- testIndex: function() {
- this.assertUndefined($H().index('foo'));
-
- this.assert('a', $H(Fixtures.one).index('A#'));
- this.assert('a', $H(Fixtures.many).index('A'));
- this.assertUndefined($H(Fixtures.many).index('Z'))
-
- var hash = $H({a:1,b:'2',c:1});
- this.assert(['a','c'].include(hash.index(1)));
- this.assertUndefined(hash.index('1'));
- },
-
- testMerge: function() {
- var h = $H(Fixtures.many);
- this.assertNotIdentical(h, h.merge());
- this.assertNotIdentical(h, h.merge({}));
- this.assertInstanceOf(Hash, h.merge());
- this.assertInstanceOf(Hash, h.merge({}));
- this.assertHashEqual(h, h.merge());
- this.assertHashEqual(h, h.merge({}));
- this.assertHashEqual(h, h.merge($H()));
- this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.merge({aaa: 'AAA'}));
- this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#' }, h.merge(Fixtures.one));
- },
-
- testUpdate: function() {
- var h = $H(Fixtures.many);
- this.assertIdentical(h, h.update());
- this.assertIdentical(h, h.update({}));
- this.assertHashEqual(h, h.update());
- this.assertHashEqual(h, h.update({}));
- this.assertHashEqual(h, h.update($H()));
- this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update({aaa: 'AAA'}));
- this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update(Fixtures.one));
- },
-
- testToQueryString: function() {
- this.assertEqual('', $H({}).toQueryString());
- this.assertEqual('a%23=A', $H({'a#': 'A'}).toQueryString());
- this.assertEqual('a=A%23', $H(Fixtures.one).toQueryString());
- this.assertEqual('a=A&b=B&c=C&d=D%23', $H(Fixtures.many).toQueryString());
- this.assertEqual("a=b&c", $H(Fixtures.value_undefined).toQueryString());
- this.assertEqual("a=b&c", $H("a=b&c".toQueryParams()).toQueryString());
- this.assertEqual("a=b&c=", $H(Fixtures.value_null).toQueryString());
- this.assertEqual("a=b&c=0", $H(Fixtures.value_zero).toQueryString());
- this.assertEqual("color=r&color=g&color=b", $H(Fixtures.multiple).toQueryString());
- this.assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
- this.assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
- this.assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
- this.assertEqual("", $H({foo: {}, bar: {}}).toQueryString());
- this.assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
- this.assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
- this.assertIdentical(Object.toQueryString, Hash.toQueryString);
- },
-
- testInspect: function() {
- this.assertEqual('#<Hash:{}>', $H({}).inspect());
- this.assertEqual("#<Hash:{'a': 'A#'}>", $H(Fixtures.one).inspect());
- this.assertEqual("#<Hash:{'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D#'}>", $H(Fixtures.many).inspect());
- },
-
- testClone: function() {
- var h = $H(Fixtures.many);
- this.assertHashEqual(h, h.clone());
- this.assertInstanceOf(Hash, h.clone());
- this.assertNotIdentical(h, h.clone());
- },
-
- testToJSON: function() {
- this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
- $H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}).toJSON());
- },
-
- testAbilityToContainAnyKey: function() {
- var h = $H({ _each: 'E', map: 'M', keys: 'K', pluck: 'P', unset: 'U' });
- this.assertEnumEqual($w('_each keys map pluck unset'), h.keys().sort());
- this.assertEqual('U', h.unset('unset'));
- this.assertHashEqual({ _each: 'E', map: 'M', keys: 'K', pluck: 'P' }, h);
- },
-
- testHashToTemplateReplacements: function() {
- var template = new Template("#{a} #{b}"), hash = $H({ a: "hello", b: "world" });
- this.assertEqual("hello world", template.evaluate(hash.toObject()));
- this.assertEqual("hello world", template.evaluate(hash));
- this.assertEqual("hello", "#{a}".interpolate(hash));
- },
-
- testPreventIterationOverShadowedProperties: function() {
- // redundant now that object is systematically cloned.
- var FooMaker = function(value) {
- this.key = value;
- };
- FooMaker.prototype.key = 'foo';
- var foo = new FooMaker('bar');
- this.assertEqual("key=bar", new Hash(foo).toQueryString());
- this.assertEqual("key=bar", new Hash(new Hash(foo)).toQueryString());
- }
-
-});
View
44 test/unit/asp/tests/number_test.js
@@ -1,44 +0,0 @@
-var testResults = new Test.Unit.Runner({
-
- testNumberMathMethods: function() {
- this.assertEqual(1, (0.9).round());
- this.assertEqual(-2, (-1.9).floor());
- this.assertEqual(-1, (-1.9).ceil());
-
- $w('abs floor round ceil').each(function(method) {
- this.assertEqual(Math[method](Math.PI), Math.PI[method]());
- }, this);
- },
-
- testNumberToColorPart: function() {
- this.assertEqual('00', (0).toColorPart());
- this.assertEqual('0a', (10).toColorPart());
- this.assertEqual('ff', (255).toColorPart());
- },
-
- testNumberToPaddedString: function() {
- this.assertEqual('00', (0).toPaddedString(2, 16));
- this.assertEqual('0a', (10).toPaddedString(2, 16));
- this.assertEqual('ff', (255).toPaddedString(2, 16));
- this.assertEqual('000', (0).toPaddedString(3));
- this.assertEqual('010', (10).toPaddedString(3));
- this.assertEqual('100', (100).toPaddedString(3));
- this.assertEqual('1000', (1000).toPaddedString(3));
- },
-
- testNumberToJSON: function() {
- this.assertEqual('null', Number.NaN.toJSON());
- this.assertEqual('0', (0).toJSON());
- this.assertEqual('-293', (-293).toJSON());
- },
-
- testNumberTimes: function() {
- var results = [];
- (5).times(function(i) { results.push(i) });
- this.assertEnumEqual($R(0, 4), results);
-
- results = [];
- (5).times(function(i) { results.push(i * this.i) }, { i: 2 });
- this.assertEnumEqual([0, 2, 4, 6, 8], results);
- }
-});
View
182 test/unit/asp/tests/object_test.js
@@ -1,182 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testObjectExtend: function() {
- var object = {foo: 'foo', bar: [1, 2, 3]};
- this.assertIdentical(object, Object.extend(object));
- this.assertHashEqual({foo: 'foo', bar: [1, 2, 3]}, object);
- this.assertIdentical(object, Object.extend(object, {bla: 123}));
- this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: 123}, object);
- this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: null},
- Object.extend(object, {bla: null}));
- },
-
- testObjectToQueryString: function() {
- this.assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'}));
- },
-
- testObjectClone: function() {
- var object = {foo: 'foo', bar: [1, 2, 3]};
- this.assertNotIdentical(object, Object.clone(object));
- this.assertHashEqual(object, Object.clone(object));
- this.assertHashEqual({}, Object.clone());
- var clone = Object.clone(object);
- delete clone.bar;
- this.assertHashEqual({foo: 'foo'}, clone,
- "Optimizing Object.clone perf using prototyping doesn't allow properties to be deleted.");
- },
-
- testObjectInspect: function() {
- this.assertEqual('undefined', Object.inspect());
- this.assertEqual('undefined', Object.inspect(undefined));
- this.assertEqual('null', Object.inspect(null));
- this.assertEqual("'foo\\\\b\\\'ar'", Object.inspect('foo\\b\'ar'));
- this.assertEqual('[]', Object.inspect([]));
- //this.assertNothingRaised(function() { Object.inspect(window.Node) });
- },
-
- testObjectToJSON: function() {
- this.assertUndefined(Object.toJSON(undefined));
- this.assertUndefined(Object.toJSON(Prototype.K));
- this.assertEqual('\"\"', Object.toJSON(''));
- this.assertEqual('[]', Object.toJSON([]));
- this.assertEqual('[\"a\"]', Object.toJSON(['a']));
- this.assertEqual('[\"a\", 1]', Object.toJSON(['a', 1]));
- this.assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}]));
- this.assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'}));
- this.assertEqual('{}', Object.toJSON({}));
- this.assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K}));
- this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
- Object.toJSON({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}));
- this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
- Object.toJSON($H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}})));
- this.assertEqual('true', Object.toJSON(true));
- this.assertEqual('false', Object.toJSON(false));
- this.assertEqual('null', Object.toJSON(null));
- var sam = new Person('sam');
- this.assertEqual('-sam', Object.toJSON(sam));
- this.assertEqual('-sam', sam.toJSON());
- //var element = $('test');
- //this.assertUndefined(Object.toJSON(element));
- //element.toJSON = function(){return 'I\'m a div with id test'};
- //this.assertEqual('I\'m a div with id test', Object.toJSON(element));
- },
-
- testObjectToHTML: function() {
- this.assertIdentical('', Object.toHTML());
- this.assertIdentical('', Object.toHTML(''));
- this.assertIdentical('', Object.toHTML(null));
- this.assertIdentical('0', Object.toHTML(0));
- this.assertIdentical('123', Object.toHTML(123));
- this.assertEqual('hello world', Object.toHTML('hello world'));
- this.assertEqual('hello world', Object.toHTML({toHTML: function() { return 'hello world' }}));
- },
-
- testObjectIsArray: function() {
- this.assert(Object.isArray([]));
- this.assert(Object.isArray([0]));
- this.assert(Object.isArray([0, 1]));
- this.assert(!Object.isArray({}));
- //this.assert(!Object.isArray($('list').childNodes));
- this.assert(!Object.isArray());
- this.assert(!Object.isArray(''));
- this.assert(!Object.isArray('foo'));
- this.assert(!Object.isArray(0));
- this.assert(!Object.isArray(1));
- this.assert(!Object.isArray(null));
- this.assert(!Object.isArray(true));
- this.assert(!Object.isArray(false));
- this.assert(!Object.isArray(undefined));
- },
-
- testObjectIsHash: function() {
- this.assert(Object.isHash($H()));
- this.assert(Object.isHash(new Hash()));
- this.assert(!Object.isHash({}));
- this.assert(!Object.isHash(null));
- this.assert(!Object.isHash());
- this.assert(!Object.isHash(''));
- this.assert(!Object.isHash(2));
- this.assert(!Object.isHash(false));
- this.assert(!Object.isHash(true));
- this.assert(!Object.isHash([]));
- },
-/*
- testObjectIsElement: function() {
- this.assert(Object.isElement(document.createElement('div')));
- this.assert(Object.isElement(new Element('div')));
- this.assert(Object.isElement($('testlog')));
- this.assert(!Object.isElement(document.createTextNode('bla')));
-
- // falsy variables should not mess up return value type
- this.assertIdentical(false, Object.isElement(0));
- this.assertIdentical(false, Object.isElement(''));
- this.assertIdentical(false, Object.isElement(NaN));
- this.assertIdentical(false, Object.isElement(null));
- this.assertIdentical(false, Object.isElement(undefined));
- },
-*/
- testObjectIsFunction: function() {
- this.assert(Object.isFunction(function() { }));
- this.assert(Object.isFunction(Class.create()));
- this.assert(!Object.isFunction("a string"));
- //this.assert(!Object.isFunction($("testlog")));
- this.assert(!Object.isFunction([]));
- this.assert(!Object.isFunction({}));
- this.assert(!Object.isFunction(0));
- this.assert(!Object.isFunction(false));
- this.assert(!Object.isFunction(undefined));
- },
-
- testObjectIsString: function() {
- this.assert(!Object.isString(function() { }));
- this.assert(Object.isString("a string"));
- this.assert(Object.isString(new String("a string")));
- this.assert(!Object.isString(0));
- this.assert(!Object.isString([]));
- this.assert(!Object.isString({}));
- this.assert(!Object.isString(false));
- this.assert(!Object.isString(undefined));
- //this.assert(!Object.isString(document), 'host objects should return false rather than throw exceptions');
- this.assert(!Object.isString(Response), 'host objects should return false rather than throw exceptions');
- },
-
- testObjectIsNumber: function() {
- this.assert(Object.isNumber(0));
- this.assert(Object.isNumber(1.0));
- this.assert(Object.isNumber(new Number(0)));
- this.assert(Object.isNumber(new Number(1.0)));
- this.assert(!Object.isNumber(function() { }));
- this.assert(!Object.isNumber({ test: function() { return 3 } }));
- this.assert(!Object.isNumber("a string"));
- this.assert(!Object.isNumber([]));
- this.assert(!Object.isNumber({}));
- this.assert(!Object.isNumber(false));
- this.assert(!Object.isNumber(undefined));
- //this.assert(!Object.isNumber(document), 'host objects should return false rather than throw exceptions');
- this.assert(!Object.isNumber(Response), 'host objects should return false rather than throw exceptions');
- },
-
- testObjectIsUndefined: function() {
- this.assert(Object.isUndefined(undefined));
- this.assert(!Object.isUndefined(null));
- this.assert(!Object.isUndefined(false));
- this.assert(!Object.isUndefined(0));
- this.assert(!Object.isUndefined(""));
- this.assert(!Object.isUndefined(function() { }));
- this.assert(!Object.isUndefined([]));
- this.assert(!Object.isUndefined({}));
- },
-
- // sanity check
- testDoesntExtendObjectPrototype: function() {
- // for-in is supported with objects
- var iterations = 0, obj = { a: 1, b: 2, c: 3 };
- for(property in obj) iterations++;
- this.assertEqual(3, iterations);
-
- // for-in is not supported with arrays
- iterations = 0;
- var arr = [1,2,3];
- for(property in arr) iterations++;
- this.assert(iterations > 3);
- }
-});
View
45 test/unit/asp/tests/prototype_test.js
@@ -1,45 +0,0 @@
-var testResults = new Test.Unit.Runner({
-/*
- testBrowserDetection: function() {
- var results = $H(Prototype.Browser).map(function(engine){
- return engine;
- }).partition(function(engine){
- return engine[1] === true
- });
- var trues = results[0], falses = results[1];
-
- this.info('User agent string is: ' + navigator.userAgent);
-
- this.assert(trues.size() == 0 || trues.size() == 1,
- 'There should be only one or no browser detected.');
-
- // we should have definite trues or falses here
- trues.each(function(result) {
- this.assert(result[1] === true);
- }, this);
- falses.each(function(result) {
- this.assert(result[1] === false);
- }, this);
-
- if(navigator.userAgent.indexOf('AppleWebKit/') > -1) {
- this.info('Running on WebKit');
- this.assert(Prototype.Browser.WebKit);
- }
-
- if(!!window.opera) {
- this.info('Running on Opera');
- this.assert(Prototype.Browser.Opera);
- }
-
- if(!!(window.attachEvent && !window.opera)) {
- this.info('Running on IE');
- this.assert(Prototype.Browser.IE);
- }
-
- if(navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1) {
- this.info('Running on Gecko');
- this.assert(Prototype.Browser.Gecko);
- }
- }
-*/
-});
View
58 test/unit/asp/tests/range_test.js
@@ -1,58 +0,0 @@
-var testResults = new Test.Unit.Runner({
-
- testInclude: function() {
- this.assert(!$R(0, 0, true).include(0));
- this.assert($R(0, 0, false).include(0));
-
- this.assert($R(0, 5, true).include(0));
- this.assert($R(0, 5, true).include(4));
- this.assert(!$R(0, 5, true).include(5));
-
- this.assert($R(0, 5, false).include(0));
- this.assert($R(0, 5, false).include(5));
- this.assert(!$R(0, 5, false).include(6));
- },
-
- testEach: function() {
- var results = [];
- $R(0, 0, true).each(function(value) {
- results.push(value);
- });
-
- this.assertEnumEqual([], results);
-
- results = [];
- $R(0, 3, false).each(function(value) {
- results.push(value);
- });
-
- this.assertEnumEqual([0, 1, 2, 3], results);
- },
-
- testAny: function() {
- this.assert(!$R(1, 1, true).any());
- this.assert($R(0, 3, false).any(function(value) {
- return value == 3;
- }));
- },
-
- testAll: function() {
- this.assert($R(1, 1, true).all());
- this.assert($R(0, 3, false).all(function(value) {
- return value <= 3;
- }));
- },
-
- testToArray: function() {
- this.assertEnumEqual([], $R(0, 0, true).toArray());
- this.assertEnumEqual([0], $R(0, 0, false).toArray());
- this.assertEnumEqual([0], $R(0, 1, true).toArray());
- this.assertEnumEqual([0, 1], $R(0, 1, false).toArray());
- this.assertEnumEqual([-3, -2, -1, 0, 1, 2], $R(-3, 3, true).toArray());
- this.assertEnumEqual([-3, -2, -1, 0, 1, 2, 3], $R(-3, 3, false).toArray());
- },
-
- testDefaultsToNotExclusive: function() {
- this.assertEnumEqual($R(-3,3), $R(-3,3,false));
- }
-});
View
42 test/unit/asp/tests/regexp_test.js
@@ -1,42 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testRegExpEscape: function() {
- this.assertEqual('word', RegExp.escape('word'));
- this.assertEqual('\\/slashes\\/', RegExp.escape('/slashes/'));
- this.assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\'));
- this.assertEqual('\\\\border of word', RegExp.escape('\\border of word'));
-
- this.assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)'));
- this.assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]);
-
- this.assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)'));
- this.assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]);
-
- this.assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)'));
- this.assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]);
-
- this.assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)'));
- this.assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]);
-
- this.assertEqual('\\(\\?<\\!negative-lookbehind\\)', RegExp.escape('(?<!negative-lookbehind)'));
- this.assertEqual('negative-lookbehind', new RegExp(RegExp.escape('(?<!') + '([^)]+)').exec('(?<!negative-lookbehind)')[1]);
-
- this.assertEqual('\\[\\\\w\\]\\+', RegExp.escape('[\\w]+'));
- this.assertEqual('character class', new RegExp(RegExp.escape('[') + '([^\\]]+)').exec('[character class]')[1]);
-
- this.assertEqual('<div>', new RegExp(RegExp.escape('<div>')).exec('<td><div></td>')[0]);
-
- this.assertEqual('false', RegExp.escape(false));
- this.assertEqual('undefined', RegExp.escape());
- this.assertEqual('null', RegExp.escape(null));
- this.assertEqual('42', RegExp.escape(42));
-
- this.assertEqual('\\\\n\\\\r\\\\t', RegExp.escape('\\n\\r\\t'));
- this.assertEqual('\n\r\t', RegExp.escape('\n\r\t'));
- this.assertEqual('\\{5,2\\}', RegExp.escape('{5,2}'));
-
- this.assertEqual(
- '\\/\\(\\[\\.\\*\\+\\?\\^\\=\\!\\:\\$\\{\\}\\(\\)\\|\\[\\\\\\]\\\\\\\/\\\\\\\\\\]\\)\\/g',
- RegExp.escape('/([.*+?^=!:${}()|[\\]\\/\\\\])/g')
- );
- }
-});
View
536 test/unit/asp/tests/string_test.js
@@ -1,536 +0,0 @@
-var testResults = new Test.Unit.Runner({
- testInterpret: function(){
- this.assertIdentical('true', String.interpret(true));
- this.assertIdentical('123', String.interpret(123));
- this.assertIdentical('foo bar', String.interpret('foo bar'));
- this.assertIdentical(
- 'object string',
- String.interpret({ toString: function(){ return 'object string' } }));
-
- this.assertIdentical('0', String.interpret(0));
- this.assertIdentical('false', String.interpret(false));
- this.assertIdentical('', String.interpret(undefined));
- this.assertIdentical('', String.interpret(null));
- this.assertIdentical('', String.interpret(''));
- },
-
- testGsubWithReplacementFunction: function() {
- var source = 'foo boo boz';
-
- this.assertEqual('Foo Boo BoZ',
- source.gsub(/[^o]+/, function(match) {
- return match[0].toUpperCase()
- }));
- this.assertEqual('f2 b2 b1z',
- source.gsub(/o+/, function(match) {
- return match[0].length;
- }));
- this.assertEqual('f0 b0 b1z',
- source.gsub(/o+/, function(match) {
- return match[0].length % 2;
- }));
-
- },
-
- testGsubWithReplacementString: function() {
- var source = 'foo boo boz';
-
- this.assertEqual('foobooboz',
- source.gsub(/\s+/, ''));
- this.assertEqual(' z',
- source.gsub(/(.)(o+)/, ''));
-
- this.assertEqual('ウィメンズ2007<br/>クルーズコレクション',
- 'ウィメンズ2007\nクルーズコレクション'.gsub(/\n/,'<br/>'));
- this.assertEqual('ウィメンズ2007<br/>クルーズコレクション',
- 'ウィメンズ2007\nクルーズコレクション'.gsub('\n','<br/>'));
-
- this.assertEqual('barfbarobarobar barbbarobarobar barbbarobarzbar',
- source.gsub('', 'bar'));
- this.assertEqual('barfbarobarobar barbbarobarobar barbbarobarzbar',
- source.gsub(new RegExp(''), 'bar'));
- },
-
- testGsubWithReplacementTemplateString: function() {
- var source = 'foo boo boz';
-
- this.assertEqual('-oo-#{1}- -oo-#{1}- -o-#{1}-z',
- source.gsub(/(.)(o+)/, '-#{2}-\\#{1}-'));
- this.assertEqual('-foo-f- -boo-b- -bo-b-z',
- source.gsub(/(.)(o+)/, '-#{0}-#{1}-'));
- this.assertEqual('-oo-f- -oo-b- -o-b-z',
- source.gsub(/(.)(o+)/, '-#{2}-#{1}-'));
- this.assertEqual(' z',
- source.gsub(/(.)(o+)/, '#{3}'));
- },
-
- testSubWithReplacementFunction: function() {
- var source = 'foo boo boz';
-
- this.assertEqual('Foo boo boz',
- source.sub(/[^o]+/, function(match) {
- return match[0].toUpperCase()
- }), 1);
- this.assertEqual('Foo Boo boz',
- source.sub(/[^o]+/, function(match) {
- return match[0].toUpperCase()
- }, 2), 2);
- this.assertEqual(source,
- source.sub(/[^o]+/, function(match) {
- return match[0].toUpperCase()
- }, 0), 0);
- this.assertEqual(source,
- source.sub(/[^o]+/, function(match) {
- return match[0].toUpperCase()
- }, -1), -1);
- },
-
- testSubWithReplacementString: function() {
- var source = 'foo boo boz';
-
- this.assertEqual('oo boo boz',
- source.sub(/[^o]+/, ''));
- this.assertEqual('oooo boz',
- source.sub(/[^o]+/, '', 2));
- this.assertEqual('-f-oo boo boz',
- source.sub(/[^o]+/, '-#{0}-'));
- this.assertEqual('-f-oo- b-oo boz',
- source.sub(/[^o]+/, '-#{0}-', 2));
- },
-
- testScan: function() {
- var source = 'foo boo boz', results = [];
- var str = source.scan(/[o]+/, function(match) {
- results.push(match[0].length);
- });
- this.assertEnumEqual([2, 2, 1], results);
- this.assertEqual(source, source.scan(/x/, this.fail));
- this.assert(typeof str == 'string');
- },
-
- testToArray: function() {
- this.assertEnumEqual([],''.toArray());
- this.assertEnumEqual(['a'],'a'.toArray());
- this.assertEnumEqual(['a','b'],'ab'.toArray());
- this.assertEnumEqual(['f','o','o'],'foo'.toArray());
- },
-
- /*
- Note that camelize() differs from its Rails counterpart,
- as it is optimized for dealing with JavaScript object
- properties in conjunction with CSS property names:
- - Looks for dashes, not underscores
- - CamelCases first word if there is a front dash
- */
- testCamelize: function() {
- this.assertEqual('', ''.camelize());
- this.assertEqual('', '-'.camelize());
- this.assertEqual('foo', 'foo'.camelize());
- this.assertEqual('foo_bar', 'foo_bar'.camelize());
- this.assertEqual('FooBar', '-foo-bar'.camelize());
- this.assertEqual('FooBar', 'FooBar'.camelize());
-
- this.assertEqual('fooBar', 'foo-bar'.camelize());
- this.assertEqual('borderBottomWidth', 'border-bottom-width'.camelize());
-
- this.assertEqual('classNameTest','class-name-test'.camelize());
- this.assertEqual('classNameTest','className-test'.camelize());
- this.assertEqual('classNameTest','class-nameTest'.camelize());
-
- /* this.benchmark(function(){
- 'class-name-test'.camelize();
- },10000); */
- },
-
- testCapitalize: function() {
- this.assertEqual('',''.capitalize());
- this.assertEqual('Ä','ä'.capitalize());
- this.assertEqual('A','A'.capitalize());
- this.assertEqual('Hello','hello'.capitalize());
- this.assertEqual('Hello','HELLO'.capitalize());
- this.assertEqual('Hello','Hello'.capitalize());
- this.assertEqual('Hello world','hello WORLD'.capitalize());
- },
-
- testUnderscore: function() {
- this.assertEqual('', ''.underscore());
- this.assertEqual('_', '-'.underscore());
- this.assertEqual('foo', 'foo'.underscore());
- this.assertEqual('foo', 'Foo'.underscore());
- this.assertEqual('foo_bar', 'foo_bar'.underscore());
- this.assertEqual('border_bottom', 'borderBottom'.underscore());
- this.assertEqual('border_bottom_width', 'borderBottomWidth'.underscore());
- this.assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore());
- },
-
- testDasherize: function() {
- this.assertEqual('', ''.dasherize());
- this.assertEqual('foo', 'foo'.dasherize());
- this.assertEqual('Foo', 'Foo'.dasherize());
- this.assertEqual('foo-bar', 'foo-bar'.dasherize());
- this.assertEqual('border-bottom-width', 'border_bottom_width'.dasherize());
- },
-
- testTruncate: function() {
- var source = 'foo boo boz foo boo boz foo boo boz foo boo boz';
- this.assertEqual(source, source.truncate(source.length));
- this.assertEqual('foo boo boz foo boo boz foo...', source.truncate(0));
- this.assertEqual('fo...', source.truncate(5));
- this.assertEqual('foo b', source.truncate(5, ''));
-
- this.assert(typeof 'foo'.truncate(5) == 'string');
- this.assert(typeof 'foo bar baz'.truncate(5) == 'string');
- },
-
- testStrip: function() {
- this.assertEqual('hello world', ' hello world '.strip());
- this.assertEqual('hello world', 'hello world'.strip());
- this.assertEqual('hello \n world', ' hello \n world '.strip());
- this.assertEqual('', ' '.strip());
- },
-
- testStripTags: function() {
- this.assertEqual('hello world', 'hello world'.stripTags());
- this.assertEqual('hello world', 'hello <span>world</span>'.stripTags());
- this.assertEqual('hello world', '<a href="#" onclick="moo!">hello</a> world'.stripTags());
- this.assertEqual('hello world', 'h<b><em>e</em></b>l<i>l</i>o w<span class="moo" id="x"><b>o</b></span>rld'.stripTags());
- this.assertEqual('1\n2', '1\n2'.stripTags());
- },
-
- testStripScripts: function() {
- this.assertEqual('foo bar', 'foo bar'.stripScripts());
- this.assertEqual('foo bar', ('foo <script>boo();<'+'/script>bar').stripScripts());
- this.assertEqual('foo bar', ('foo <script type="text/javascript">boo();\nmoo();<'+'/script>bar').stripScripts());
- },
-
- testExtractScripts: function() {
- this.assertEnumEqual([], 'foo bar'.extractScripts());
- this.assertEnumEqual(['boo();'], ('foo <script>boo();<'+'/script>bar').extractScripts());
- this.assertEnumEqual(['boo();','boo();\nmoo();'],
- ('foo <script>boo();<'+'/script><script type="text/javascript">boo();\nmoo();<'+'/script>bar').extractScripts());
- this.assertEnumEqual(['boo();','boo();\nmoo();'],
- ('foo <script>boo();<'+'/script>blub\nblub<script type="text/javascript">boo();\nmoo();<'+'/script>bar').extractScripts());
- },
-
- testEvalScripts: function() {
- this.assertEqual(0, evalScriptsCounter);
-
- ('foo <script>evalScriptsCounter++<'+'/script>bar').evalScripts();
- this.assertEqual(1, evalScriptsCounter);
-
- var stringWithScripts = '';
- (3).times(function(){ stringWithScripts += 'foo <script>evalScriptsCounter++<'+'/script>bar' });
- stringWithScripts.evalScripts();
- this.assertEqual(4, evalScriptsCounter);
- },
-
- testEscapeHTML: function() {
- this.assertEqual('foo bar', 'foo bar'.escapeHTML());
- this.assertEqual('foo &lt;span&gt;bar&lt;/span&gt;', 'foo <span>bar</span>'.escapeHTML());
- this.assertEqual('foo ß bar', 'foo ß bar'.escapeHTML());
-
- this.assertEqual('ウィメンズ2007\nクルーズコレクション',
- 'ウィメンズ2007\nクルーズコレクション'.escapeHTML());
-
- this.assertEqual('a&lt;a href="blah"&gt;blub&lt;/a&gt;b&lt;span&gt;&lt;div&gt;&lt;/div&gt;&lt;/span&gt;cdef&lt;strong&gt;!!!!&lt;/strong&gt;g',
- 'a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g'.escapeHTML());
-
- this.assertEqual(largeTextEscaped, largeTextUnescaped.escapeHTML());
-
- this.assertEqual('1\n2', '1\n2'.escapeHTML());
-
- this.benchmark(function() { largeTextUnescaped.escapeHTML() }, 1000);
- },
-
- testUnescapeHTML: function() {
- this.assertEqual('foo bar', 'foo bar'.unescapeHTML());
- this.assertEqual('foo <span>bar</span>', 'foo &lt;span&gt;bar&lt;/span&gt;'.unescapeHTML());
- this.assertEqual('foo ß bar', 'foo ß bar'.unescapeHTML());
-
- this.assertEqual('a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g',
- 'a&lt;a href="blah"&gt;blub&lt;/a&gt;b&lt;span&gt;&lt;div&gt;&lt;/div&gt;&lt;/span&gt;cdef&lt;strong&gt;!!!!&lt;/strong&gt;g'.unescapeHTML());
-
- this.assertEqual(largeTextUnescaped, largeTextEscaped.unescapeHTML());
-
- this.assertEqual('1\n2', '1\n2'.unescapeHTML());
- this.assertEqual('Pride & Prejudice', '<h1>Pride &amp; Prejudice</h1>'.unescapeHTML());
-
- this.assertIdentical('&lt;', '&amp;lt;'.unescapeHTML());
-
- this.benchmark(function() { largeTextEscaped.unescapeHTML() }, 1000);
-
- },
-
- testTemplateEvaluation: function() {
- var source = '<tr><td>#{name}</td><td>#{age}</td></tr>';
- var person = {name: 'Sam', age: 21};
- var template = new Template(source);
-
- this.assertEqual('<tr><td>Sam</td><td>21</td></tr>',
- template.evaluate(person));
- this.assertEqual('<tr><td></td><td></td></tr>',
- template.evaluate({}));
- },
-
- testTemplateEvaluationWithEmptyReplacement: function() {
- var template = new Template('##{}');
- this.assertEqual('#', template.evaluate({}));
- this.assertEqual('#', template.evaluate({foo: 'bar'}));
-
- template = new Template('#{}');
- this.assertEqual('', template.evaluate({}));
- },
-
- testTemplateEvaluationWithFalses: function() {
- var source = '<tr><td>#{zero}</td><td>#{_false}</td><td>#{undef}</td><td>#{_null}</td><td>#{empty}</td></tr>';
- var falses = {zero:0, _false:false, undef:undefined, _null:null, empty:""};
- var template = new Template(source);
-
- this.assertEqual('<tr><td>0</td><td>false</td><td></td><td></td><td></td></tr>',
- template.evaluate(falses));
- },
-
- testTemplateEvaluationWithNested: function() {
- var source = '#{name} #{manager.name} #{manager.age} #{manager.undef} #{manager.age.undef} #{colleagues.first.name}';
- var subject = { manager: { name: 'John', age: 29 }, name: 'Stephan', age: 22, colleagues: { first: { name: 'Mark' }} };
- this.assertEqual('Stephan', new Template('#{name}').evaluate(subject));
- this.assertEqual('John', new Template('#{manager.name}').evaluate(subject));
- this.assertEqual('29', new Template('#{manager.age}').evaluate(subject));
- this.assertEqual('', new Template('#{manager.undef}').evaluate(subject));
- this.assertEqual('', new Template('#{manager.age.undef}').evaluate(subject));
- this.assertEqual('Mark', new Template('#{colleagues.first.name}').evaluate(subject));
- this.assertEqual('Stephan John 29 Mark', new Template(source).evaluate(subject));
- },
-
- testTemplateEvaluationWithIndexing: function() {
- var source = '#{0} = #{[0]} - #{1} = #{[1]} - #{[2][0]} - #{[2].name} - #{first[0]} - #{[first][0]} - #{[\\]]} - #{first[\\]]}';
- var subject = [ 'zero', 'one', [ 'two-zero' ] ];
- subject[2].name = 'two-zero-name';
- subject.first = subject[2];
- subject[']'] = '\\';
- subject.first[']'] = 'first\\';
- this.assertEqual('zero', new Template('#{[0]}').evaluate(subject));
- this.assertEqual('one', new Template('#{[1]}').evaluate(subject));
- this.assertEqual('two-zero', new Template('#{[2][0]}').evaluate(subject));
- this.assertEqual('two-zero-name', new Template('#{[2].name}').evaluate(subject));
- this.assertEqual('two-zero', new Template('#{first[0]}').evaluate(subject));
- this.assertEqual('\\', new Template('#{[\\]]}').evaluate(subject));
- this.assertEqual('first\\', new Template('#{first[\\]]}').evaluate(subject));
- this.assertEqual('empty - empty2', new Template('#{[]} - #{m[]}').evaluate({ '': 'empty', m: {'': 'empty2'}}));
- this.assertEqual('zero = zero - one = one - two-zero - two-zero-name - two-zero - two-zero - \\ - first\\', new Template(source).evaluate(subject));
- },
-
- testTemplateToTemplateReplacements: function() {
- var source = 'My name is #{name}, my job is #{job}';
- var subject = {
- name: 'Stephan',
- getJob: function() { return 'Web developer'; },
- toTemplateReplacements: function() { return { name: this.name, job: this.getJob() } }
- };
- this.assertEqual('My name is Stephan, my job is Web developer', new Template(source).evaluate(subject));
- },
-
- testTemplateEvaluationCombined: function() {
- var source = '#{name} is #{age} years old, managed by #{manager.name}, #{manager.age}.\n' +
- 'Colleagues include #{colleagues[0].name} and #{colleagues[1].name}.';
- var subject = {
- name: 'Stephan', age: 22,
- manager: { name: 'John', age: 29 },
- colleagues: [ { name: 'Mark' }, { name: 'Indy' } ]
- };
- this.assertEqual('Stephan is 22 years old, managed by John, 29.\n' +
- 'Colleagues include Mark and Indy.',
- new Template(source).evaluate(subject));
- },
-
- testInterpolate: function() {
- var subject = { name: 'Stephan' };
- var pattern = /(^|.|\r|\n)(#\((.*?)\))/;
- this.assertEqual('#{name}: Stephan', '\\#{name}: #{name}'.interpolate(subject));
- this.assertEqual('#(name): Stephan', '\\#(name): #(name)'.interpolate(subject, pattern));
- },
-
- testToQueryParams: function() {
- // only the query part
- var result = {a:undefined, b:'c'};
- this.assertHashEqual({}, ''.toQueryParams(), 'empty query');
- this.assertHashEqual({}, 'foo?'.toQueryParams(), 'empty query with URL'