Permalink
Browse files

Import some of my old tests.

  • Loading branch information...
1 parent 1f8727c commit c82b04ead8fa94e9326ca44a936d5618bd3b12d7 @Ms2ger Ms2ger committed Mar 15, 2013
View
@@ -0,0 +1 @@
+evaluator-constructor.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>XPathEvaluator constructor</title>
+<link rel=help href="http://wiki.whatwg.org/wiki/DOM_XPath">
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+<script>
+test(function() {
+ var x = new XPathEvaluator();
+ assert_true(x instanceof XPathEvaluator);
+}, "Constructor with 'new'");
+test(function() {
+ var x = XPathEvaluator();
+ assert_true(x instanceof XPathEvaluator);
+}, "Constructor without 'new'");
+</script>
@@ -0,0 +1,24 @@
+<!doctype html>
+<title>Array.[[DefineOwnProperty]]</title>
+<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.4.5.1>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+<script>
+test(function() {
+ var arr = new Array;
+ assert_equals(arr.length, 0);
+
+ var called = 0;
+ Object.defineProperty(arr, 0, { get: function() { ++called; return 7 } });
+ assert_equals(arr.length, 1);
+ assert_equals(called, 0);
+
+ assert_equals(arr[0], 7);
+ assert_equals(called, 1);
+
+ assert_equals(String(arr), "7");
+ assert_equals(called, 2);
+});
+</script>
@@ -0,0 +1,86 @@
+<!doctype html>
+<title>Array.prototype.join</title>
+<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.4.4.5>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script>
+var test_error = { name: "test" };
+
+// Step 1.
+test(function() {
+ assert_throws(new TypeError(), function() {
+ [].join.call(null, {
+ toString: function() { assert_unreached(); }
+ });
+ });
+ assert_throws(new TypeError(), function() {
+ [].join.call(undefined, {
+ toString: function() { assert_unreached(); }
+ });
+ });
+}, "Array.prototype.join must call ToObject before looking at the separator argument.")
+
+var generateTest = function(throwing_getter, getter_name) {
+ var throwing_object = {};
+ var interfaces = [Boolean, Number];
+
+ var objects = interfaces.map(function(p) { return p.prototype; });
+ objects.push(throwing_object);
+ objects.forEach(function(object) {
+ Object.defineProperty(object, "length", {
+ get: throwing_getter,
+ configurable: true
+ });
+ });
+
+ [throwing_object, true, false, 0, 1, Math.PI].forEach(function(that) {
+ test(function() {
+ assert_throws(test_error, function() {
+ [].join.call(that, ",");
+ });
+ }, "Array.prototype.join must forward the exception from the this " +
+ "object's length property with this=" + format_value(that) + " and " +
+ "getter " + getter_name + ".")
+ test(function() {
+ assert_throws(test_error, function() {
+ [].join.call(that, {
+ toString: function() { assert_unreached(); }
+ });
+ });
+ }, "Array.prototype.join must get the this object's length property " +
+ "before looking at the separator argument with this=" +
+ format_value(that) + " and getter " + getter_name + ".")
+ });
+ interfaces.forEach(function(iface) {
+ delete iface.length;
+ });
+}
+
+// Step 2.
+test(function() {
+ generateTest(function() { throw test_error; }, "function");
+}, "Step 2.");
+
+// Step 3.
+test(function() {
+ generateTest(function() {
+ return {
+ valueOf: function() { throw test_error; }
+ };
+ }, "valueOf");
+ generateTest(function() {
+ return {
+ toString: function() { throw test_error; }
+ };
+ }, "toString");
+ generateTest(function() {
+ return {
+ valueOf: function() { throw test_error; },
+ toString: function() { assert_notreached("toString should not be invoked if valueOf exists"); }
+ };
+ }, "valueOf and toString");
+}, "Step 3.");
+</script>
View
@@ -0,0 +1,7 @@
+Array.DefineOwnProperty.html
+Array.prototype.join-order.html
+Math.max.html
+support Math.maxmin.js
+Math.min.html
+Object.prototype.hasOwnProperty-order.html
+WeakMap.prototype-properties.html
View
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>Math.max</title>
+<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.8.2>
+<link rel=help href=http://es5.github.com/#x15.8.2.11>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script src=Math.maxmin.js></script>
+<script>
+testMathMaxMin("max");
+</script>
View
@@ -0,0 +1,57 @@
+function testMathMaxMin(aFun) {
+ var test_error = { name: "test" };
+ test(function() {
+ assert_throws(test_error, function() {
+ Math[aFun](NaN, {
+ valueOf: function() {
+ throw test_error;
+ }
+ });
+ });
+ }, "ToNumber should be called on all arguments: NaN.");
+ test(function() {
+ assert_throws(test_error, function() {
+ Math[aFun](-Infinity, {
+ valueOf: function() {
+ throw test_error;
+ }
+ });
+ });
+ }, "ToNumber should be called on all arguments: -Infinity.");
+ test(function() {
+ assert_throws(test_error, function() {
+ Math[aFun](Infinity, {
+ valueOf: function() {
+ throw test_error;
+ }
+ });
+ });
+ }, "ToNumber should be called on all arguments: Infinity.");
+ test(function() {
+ assert_throws(test_error, function() {
+ Math[aFun]({
+ valueOf: function() {
+ throw test_error;
+ }
+ },
+ {
+ valueOf: function() {
+ throw 7;
+ }
+ });
+ });
+ }, "ToNumber should be called left to right.");
+ test(function() {
+ assert_equals(Math[aFun]("1"), 1);
+ }, "Should return a number.");
+ test(function() {
+ var expected = {
+ "max": 0,
+ "min": -0
+ }
+ assert_equals(Math[aFun](0, -0), expected[aFun]);
+ assert_equals(Math[aFun](-0, 0), expected[aFun]);
+ assert_equals(Math[aFun](0, 0), 0);
+ assert_equals(Math[aFun](-0, -0), -0);
+ }, "Should handle negative zero correctly.");
+}
View
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>Math.min</title>
+<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.8.2>
+<link rel=help href=http://es5.github.com/#x15.8.2.12>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script src=Math.maxmin.js></script>
+<script>
+testMathMaxMin("min");
+</script>
@@ -0,0 +1,21 @@
+<!doctype html>
+<title>Object.prototype.hasOwnProperty</title>
+<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.4.4.5>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script>
+var test_error = { name: "test" };
+
+test(function() {
+ [null, undefined, {}].forEach(function(that) {
+ test(function() {
+ assert_throws(test_error, function() {
+ ({}).hasOwnProperty.call(that, { toString: function() { throw test_error; } });
+ });
+ });
+ });
+});
+</script>
@@ -0,0 +1,121 @@
+<!doctype html>
+<title>WeakMap.prototype</title>
+<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger>
+<link rel=help href=http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.15.5>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+<script>
+function assert_propdesc(obj, prop, Writable, Enumerable, Configurable) {
+ var propdesc = Object.getOwnPropertyDescriptor(obj, prop);
+ assert_equals(typeof propdesc, "object");
+ assert_equals(propdesc.writable, Writable, "[[Writable]]");
+ assert_equals(propdesc.enumerable, Enumerable, "[[Enumerable]]");
+ assert_equals(propdesc.configurable, Configurable, "[[Configurable]]");
+}
+
+function test_length(fun, expected) {
+ test(function() {
+ assert_propdesc(WeakMap.prototype[fun], "length", false, false, false);
+ assert_equals(WeakMap.prototype[fun].length, expected);
+ }, "WeakMap.prototype." + fun + ".length")
+}
+
+function test_thisval(fun, args) {
+ // Step 1-2
+ test(function() {
+ assert_throws(new TypeError(), function() {
+ WeakMap.prototype[fun].apply(null, args);
+ });
+ assert_throws(new TypeError(), function() {
+ WeakMap.prototype[fun].apply(undefined, args);
+ });
+ }, "WeakMap.prototype." + fun + ": ToObject on this")
+ // Step 3
+ test(function() {
+ assert_throws(new TypeError(), function() {
+ WeakMap.prototype[fun].apply({}, args);
+ });
+ }, "WeakMap.prototype." + fun + ": this has no [[WeakMapData]] internal property")
+}
+
+// In every case, the length property of a built-in Function object described
+// in this clause has the attributes { [[Writable]]: false, [[Enumerable]]:
+// false, [[Configurable]]: false }. Every other property described in this
+// clause has the attributes { [[Writable]]: true, [[Enumerable]]: false,
+// [[Configurable]]: true } unless otherwise specified.
+
+test(function() {
+ assert_equals(Object.getPrototypeOf(WeakMap.prototype), Object.prototype);
+}, "The value of the [[Prototype]] internal property of the WeakMap prototype object is the standard built-in Object prototype object (15.2.4).")
+
+// 15.15.5.1 WeakMap.prototype.constructor
+test(function() {
+ assert_equals(WeakMap.prototype.constructor, WeakMap);
+ assert_propdesc(WeakMap.prototype, "constructor", true, false, true);
+}, "The initial value of WeakMap.prototype.constructor is the built-in WeakMap constructor.")
+
+// 15.15.5.2 WeakMap.prototype.clear ()
+test(function() {
+ assert_propdesc(WeakMap.prototype, "clear", true, false, true);
+ test_length("clear", 0);
+ // Step 1-3
+ test_thisval("clear", null);
+ // Step 4-5
+ test(function() {
+ var wm = new WeakMap();
+ var key = {};
+ wm.set(key, "fail");
+ assert_true(wm.has(key));
+ var res = wm.clear();
+ assert_equals(res, undefined);
+ assert_false(wm.has(key));
+ }, "WeakMap.prototype.clear: basic functionality");
+}, "WeakMap.prototype.clear")
+
+// 15.15.5.3 WeakMap.prototype.delete ( key )
+test(function() {
+ assert_propdesc(WeakMap.prototype, "delete", true, false, true);
+ test_length("delete", 1);
+ // Step 1-3
+ test_thisval("delete", [{}]);
+}, "WeakMap.prototype.delete")
+
+// 15.15.5.4 WeakMap.prototype.get ( key )
+test(function() {
+ assert_propdesc(WeakMap.prototype, "get", true, false, true);
+ test_length("get", 1);
+ // Step 1-3
+ test_thisval("get", [{}]);
+
+ // Step 8
+ test(function() {
+ var wm = new WeakMap();
+ var key = {};
+ var res = wm.get({}, {});
+ assert_equals(res, undefined);
+ }, "WeakMap.prototype.get: return undefined");
+}, "WeakMap.prototype.get")
+
+// 15.14.5.5 Map.prototype.has ( key )
+test(function() {
+ assert_propdesc(WeakMap.prototype, "has", true, false, true);
+ test_length("has", 1);
+ // Step 1-3
+ test_thisval("has", [{}]);
+}, "WeakMap.prototype.has")
+
+// 15.14.5.6 Map.prototype.set ( key , value )
+test(function() {
+ assert_propdesc(WeakMap.prototype, "set", true, false, true);
+ test_length("set", 2);
+ // Step 1-3
+ test_thisval("set", [{}, {}]);
+}, "WeakMap.prototype.set")
+
+// 15.15.5.7 Map.prototype.@@toStringTag
+test(function() {
+ assert_class_string(new WeakMap(), "WeakMap");
+ assert_class_string(WeakMap.prototype, "WeakMap");
+}, "WeakMap.prototype.@@toStringTag")
+</script>
View
@@ -0,0 +1 @@
+constructors.html
Oops, something went wrong.

0 comments on commit c82b04e

Please sign in to comment.