Skip to content

Commit

Permalink
Add hb.version() and rename hb.version to hb.version_string()
Browse files Browse the repository at this point in the history
hb.version() returns an object with major, minor, and micro properties
as numbers, while hb.version_string() returns a string.
  • Loading branch information
khaledhosny committed Sep 24, 2024
1 parent 5df5473 commit 4d1f93f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 19 additions & 2 deletions hbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,23 @@ function hbjs(Module) {
return trace;
}

function get_version() {
function version() {
var major = exports.malloc(4);
var minor = exports.malloc(4);
var micro = exports.malloc(4);
exports.hb_version(major, minor, micro);
var version = {
major: heapu32[major / 4],
minor: heapu32[minor / 4],
micro: heapu32[micro / 4],
};
exports.free(major);
exports.free(minor);
exports.free(micro);
return version;
}

function version_string() {
var versionPtr = exports.hb_version_string();
var version = utf8Decoder.decode(heapu8.subarray(versionPtr, heapu8.indexOf(0, versionPtr)));
return version;
Expand All @@ -546,7 +562,8 @@ function hbjs(Module) {
createBuffer: createBuffer,
shape: shape,
shapeWithTrace: shapeWithTrace,
version: get_version(),
version: version,
version_string: version_string,
};
}

Expand Down
12 changes: 10 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const {expect} = require('chai');
const exp = require('constants');
let hb;

before(async function () {
Expand Down Expand Up @@ -249,8 +250,15 @@ describe('shape', function () {
});

describe('misc', function () {
it('get version', function () {
const version = hb.version();
expect(version).to.have.property('major').that.is.a('number');
expect(version).to.have.property('minor').that.is.a('number');
expect(version).to.have.property('micro').that.is.a('number');
expect(version.major).to.be.at.least(10);
});
it('get version string', function () {
const version = hb.version
expect(version).to.match(/^\d+\.\d+\.\d+$/);
const version_string = hb.version_string();
expect(version_string).to.match(/^\d+\.\d+\.\d+$/);
});
});

0 comments on commit 4d1f93f

Please sign in to comment.