Skip to content

Commit 15302af

Browse files
committed
Merge pull request #76 from hdgarrood/fix-show-number-again
Fix show number again
2 parents 7857fb1 + dd1bace commit 15302af

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install:
1212
- npm install -g bower
1313
- npm install
1414
script:
15-
- npm run build
15+
- npm run build && npm test
1616
after_success:
1717
- >-
1818
test $TRAVIS_TAG &&

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"scripts": {
44
"postinstall": "pulp dep install",
55
"clean": "rimraf output && rimraf .pulp-cache",
6-
"build": "jshint src && jscs src && pulp build"
6+
"build": "jshint src && jscs src && pulp build",
7+
"test": "pulp test"
78
},
89
"devDependencies": {
910
"jscs": "^2.8.0",

src/Data/Show.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ exports.showIntImpl = function (n) {
88

99
exports.showNumberImpl = function (n) {
1010
var str = n.toString();
11-
return str.indexOf("e") === -1 && str.indexOf(".") === -1 ?
12-
str + ".0" :
13-
str;
11+
return isNaN(str + ".0") ? str : str + ".0";
1412
};
1513

1614
exports.showCharImpl = function (c) {

test/Test/Main.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use strict";
2+
3+
// module Test.Main
4+
5+
exports.mainImpl = function(showNumber) {
6+
return function() {
7+
function testAll(cases) {
8+
cases.forEach(function(c) {
9+
var expected = c[1];
10+
var actual = showNumber(c[0]);
11+
if (expected !== actual) {
12+
throw new Error(
13+
"For " + c[0] +
14+
", expected " + expected +
15+
", got: " + actual + ".");
16+
}
17+
});
18+
}
19+
20+
testAll([
21+
// Within Int range
22+
[0.0, "0.0"],
23+
[1.0, "1.0"],
24+
[-1.0, "-1.0"],
25+
[500.0, "500.0"],
26+
27+
// Outside Int range
28+
[1e10, "10000000000.0"],
29+
[1e10 + 0.5, "10000000000.5"],
30+
[-1e10, "-10000000000.0"],
31+
[-1e10 - 0.5, "-10000000000.5"],
32+
33+
// With exponent
34+
[1e21, "1e+21"],
35+
[1e-21, "1e-21"],
36+
37+
// With decimal and exponent
38+
[1.5e21, "1.5e+21"],
39+
[1.5e-10, "1.5e-10"],
40+
41+
[NaN, "NaN"],
42+
[Infinity, "Infinity"],
43+
[-Infinity, "-Infinity"],
44+
]);
45+
};
46+
};
47+

test/Test/Main.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Test.Main where
2+
3+
import Prelude
4+
5+
type AlmostEff = Unit -> Unit
6+
7+
main :: AlmostEff
8+
main = mainImpl show
9+
10+
foreign import mainImpl :: (Number -> String) -> AlmostEff

0 commit comments

Comments
 (0)