Skip to content

Commit 17b4b41

Browse files
committed
test: add -Infinity double test cases
1 parent b5b50f3 commit 17b4b41

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

.github/workflows/pkg.pr.new.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish Any Commit
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- run: corepack enable
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
17+
- name: Install dependencies
18+
run: npm install
19+
20+
- name: Build
21+
run: npm run prepublishOnly
22+
23+
- run: npx pkg-pr-new publish

test/v1.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,24 @@ describe('hessian v1', function () {
150150
[1.111, '<Buffer 44 3f f1 c6 a7 ef 9d b2 2d>'],
151151
// 1e320
152152
[Infinity, '<Buffer 44 7f f0 00 00 00 00 00 00>'],
153+
[-Infinity, '<Buffer 44 ff f0 00 00 00 00 00 00>'],
153154
];
154155

155156
tests.forEach(function (t) {
156157
var buf = encoder.writeDouble(t[0]).get();
157-
assert(buf.inspect() === t[1]);
158-
assert(decoder.init(buf).readDouble() === t[0]);
158+
assert.equal(buf.inspect(), t[1]);
159+
assert.equal(decoder.init(buf).readDouble(), t[0]);
159160
encoder.clean();
160161
decoder.clean();
161162
});
163+
const negativeInfinityBuffer = encoder.writeDouble(-Infinity).get();
164+
const v = decoder.init(negativeInfinityBuffer).readDouble();
165+
assert.equal(JSON.stringify({ v }), '{"v":null}');
162166
});
163167

164168
it('should read double error', function () {
165169
var tests = [
166-
[new Buffer([0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
170+
[Buffer.from([0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
167171
'hessian readDouble only accept label `D` but got unexpect label `E`']
168172
];
169173
tests.forEach(function (t) {

0 commit comments

Comments
 (0)