From 17b4b410fb8422f827f10e3d83a321bd15ce110f Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 30 Jun 2024 15:08:31 +0800 Subject: [PATCH] test: add `-Infinity` double test cases --- .github/workflows/pkg.pr.new.yml | 23 +++++++++++++++++++++++ test/v1.test.js | 10 +++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/pkg.pr.new.yml diff --git a/.github/workflows/pkg.pr.new.yml b/.github/workflows/pkg.pr.new.yml new file mode 100644 index 0000000..ebe7c34 --- /dev/null +++ b/.github/workflows/pkg.pr.new.yml @@ -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 + + - run: npx pkg-pr-new publish diff --git a/test/v1.test.js b/test/v1.test.js index 7402ed9..a09cb5c 100644 --- a/test/v1.test.js +++ b/test/v1.test.js @@ -150,20 +150,24 @@ describe('hessian v1', function () { [1.111, ''], // 1e320 [Infinity, ''], + [-Infinity, ''], ]; 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) {