Skip to content

Commit

Permalink
test: add -Infinity double test cases (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jun 30, 2024
1 parent b5b50f3 commit 7c14b64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
10 changes: 7 additions & 3 deletions test/v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,24 @@ describe('hessian v1', function () {
[1.111, '<Buffer 44 3f f1 c6 a7 ef 9d b2 2d>'],
// 1e320
[Infinity, '<Buffer 44 7f f0 00 00 00 00 00 00>'],
[-Infinity, '<Buffer 44 ff f0 00 00 00 00 00 00>'],
];

tests.forEach(function (t) {
var buf = encoder.writeDouble(t[0]).get();
assert(buf.inspect() === t[1]);
assert(decoder.init(buf).readDouble() === t[0]);
assert.equal(buf.inspect(), t[1]);
assert.equal(decoder.init(buf).readDouble(), t[0]);
encoder.clean();
decoder.clean();
});
const negativeInfinityBuffer = encoder.writeDouble(-Infinity).get();
const v = decoder.init(negativeInfinityBuffer).readDouble();
assert.equal(JSON.stringify({ v }), '{"v":null}');
});

it('should read double error', function () {
var tests = [
[new Buffer([0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
[Buffer.from([0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
'hessian readDouble only accept label `D` but got unexpect label `E`']
];
tests.forEach(function (t) {
Expand Down

0 comments on commit 7c14b64

Please sign in to comment.