Skip to content

Commit 2611ab6

Browse files
committed
glayzzle#386 - improve tests
1 parent 23c2845 commit 2611ab6

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const engine = function(options) {
8484
if (typeof options.parser.version === "string") {
8585
let version = options.parser.version.split(".");
8686
version = parseInt(version[0]) * 100 + parseInt(version[1]);
87-
if (isNaN(options.parser.version)) {
87+
if (isNaN(version)) {
8888
throw new Error("Bad version number : " + options.parser.version);
8989
} else {
9090
options.parser.version = version;
@@ -93,7 +93,7 @@ const engine = function(options) {
9393
throw new Error("Expecting a number for version");
9494
}
9595
if (options.parser.version < 500 || options.parser.version > 704) {
96-
throw new Error("Can only handle versions between 5.0 to 7.4");
96+
throw new Error("Can only handle versions between 5.x to 7.x");
9797
}
9898
}
9999
}

test/version.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const parser = require("./main");
2+
3+
describe("Test versions", function() {
4+
it("unserialize a version string", function() {
5+
const test = parser.create({
6+
parser: {
7+
version: "7.3"
8+
}
9+
});
10+
expect(test.parser.version).toEqual(703);
11+
});
12+
it("unserialize a version string - with bugfix ignored", function() {
13+
const test = parser.create({
14+
parser: {
15+
version: "7.3.5"
16+
}
17+
});
18+
expect(test.parser.version).toEqual(703);
19+
});
20+
it("fail to parse array", function() {
21+
expect(
22+
parser.create.bind(null, {
23+
parser: {
24+
version: [701]
25+
}
26+
})
27+
).toThrow(new Error("Expecting a number for version"));
28+
});
29+
it("fail to parse bad version numbers", function() {
30+
expect(
31+
parser.create.bind(null, {
32+
parser: {
33+
version: "x.y.z"
34+
}
35+
})
36+
).toThrow(new Error("Bad version number : x.y.z"));
37+
});
38+
it("unhandled version", function() {
39+
expect(
40+
parser.create.bind(null, {
41+
parser: {
42+
version: "4.9"
43+
}
44+
})
45+
).toThrow(new Error("Can only handle versions between 5.x to 7.x"));
46+
expect(
47+
parser.create.bind(null, {
48+
parser: {
49+
version: "8.9"
50+
}
51+
})
52+
).toThrow(new Error("Can only handle versions between 5.x to 7.x"));
53+
});
54+
});

0 commit comments

Comments
 (0)