Skip to content

Commit 8a40a41

Browse files
committed
Run more closure tests; Compatible handling of +/- Infinity in fromNumber, see dcodeIO#50
1 parent bc96a70 commit 8a40a41

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

dist/long.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/long.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/long.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Long.fromInt = fromInt;
139139
* @inner
140140
*/
141141
function fromNumber(value, unsigned) {
142-
if (isNaN(value) || !isFinite(value))
142+
if (isNaN(value))
143143
return unsigned ? UZERO : ZERO;
144144
if (unsigned) {
145145
if (value < 0)

tests/goog/base.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ goog.provide("goog.global");
2323

2424
goog.provide("goog.asserts");
2525

26+
var assert = require("assert");
2627
goog.asserts.assert = function(condition, opt_message, var_args) {
27-
if (!condition)
28-
throw Error("Assertion error: " + opt_message + " " + Array.prototype.slice.call(arguments, 2));
28+
assert(condition, opt_message, Array.prototype.slice.call(arguments, 2));
2929
};
3030

3131
global.assertEquals = function(expected, actual) { goog.asserts.assert(expected === actual); }
3232

3333
global.assertTrue = function(value) { goog.asserts.assert(value === true); }
3434

35+
global.assertNotNull = function(value) { goog.asserts.assert(value !== null); }
36+
3537
goog.provide("goog.reflect");
3638

3739
goog.reflect.cache = function(cacheObj, key, valueFn, opt_keyFn) {

tests/goog/index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
require("./base");
22

3+
function runTests() {
4+
Object.keys(goog.global).forEach(function(key) {
5+
if (/^test/.test(key) && typeof goog.global[key] === "function") {
6+
console.log("- " + key);
7+
var fn = goog.global[key];
8+
delete goog.global[key];
9+
try {
10+
fn();
11+
} catch (e) {
12+
console.log("\nERROR: " + e + "\n");
13+
process.exitCode = 1;
14+
}
15+
}
16+
});
17+
}
18+
319
require("./initial/long");
420
require("./initial/long_test");
521

622
console.log("Testing initial goog.math.long.js ...");
7-
Object.keys(goog.global).forEach(function(key) {
8-
if (typeof goog.global[key] === "function") {
9-
console.log("Running '" + key + "' ...");
10-
goog.global[key]();
11-
}
12-
});
13-
goog.global = {};
23+
runTests();
1424

1525
require("./recent/long");
1626
require("./recent/long_test");
1727

1828
console.log("\nTesting (more) recent goog.math.long.js ...");
19-
Object.keys(goog.global).forEach(function(key) {
20-
if (typeof goog.global[key] === "function") {
21-
console.log("Running '" + key + "' ...");
22-
goog.global[key]();
23-
}
24-
});
29+
runTests();

tests/goog/recent/long_test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,10 +1615,35 @@ function testIsStringInRange() {
16151615
}
16161616
}
16171617

1618-
// goog.global['testIsStringInRange' + i] = testIsStringInRange(i);
1619-
16201618
// Regression test for
16211619
// https://github.com/google/closure-library/pull/498
16221620
function testBase36ToString() {
16231621
assertEquals('zzzzzz', goog.math.Long.fromString('zzzzzz', 36).toString(36));
16241622
}
1623+
1624+
// BEGIN MONKEY PATCH
1625+
1626+
// long.js doesn't have getZero etc. but instead ZERO
1627+
if (goog.math.Long.ZERO) {
1628+
goog.math.Long.getZero = function() { return this.ZERO; };
1629+
goog.math.Long.getOne = function() { return this.ONE; };
1630+
goog.math.Long.getMaxValue = function() { return this.MAX_VALUE; };
1631+
goog.math.Long.getMinValue = function() { return this.MIN_VALUE; };
1632+
}
1633+
1634+
// the test runner can't just 'see' these functions, so add them explicitly
1635+
[
1636+
testToFromBits,
1637+
testToFromInt,
1638+
testToFromNumber,
1639+
testIsZero,
1640+
testIsNegative,
1641+
testIsOdd,
1642+
testNegation,
1643+
testAdd,
1644+
testSubtract,
1645+
testMultiply,
1646+
testBase36ToString
1647+
].forEach(function(fn) { goog.global[fn.name] = fn; });
1648+
1649+
// END MONKEY PATCH

0 commit comments

Comments
 (0)