Skip to content

Commit

Permalink
Updates ion-js to be compatible with jsbi@^4.0.0 (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt authored Feb 16, 2022
1 parent 832219b commit f1158ac
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"scripts": {
"commit": "git-cz",
"prepare": "grunt release",
"test": "nyc mocha",
"test": "npm run test-jsbi4 && npm run test-jsbi3",
"test-jsbi3": "npm install [email protected] && nyc mocha",
"test-jsbi4": "npm install [email protected] && nyc mocha",
"release": "grunt release",
"test-driver": "cd test-driver && npm install",
"build-test-driver": "cd test-driver && npm run build",
Expand Down
8 changes: 4 additions & 4 deletions src/IonTextWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class TextWriter extends AbstractWriter {
const scale = -exponent;

if (exponent == 0) {
s += coefficient + ".";
s += coefficient.toString() + ".";
} else if (exponent < 0) {
// Avoid printing small negative exponents using a heuristic
// adapted from http://speleotrove.com/decimal/daconvs.html
Expand All @@ -186,15 +186,15 @@ export class TextWriter extends AbstractWriter {
} else if (adjustedExponent >= -6) {
s += "0.";
s += "00000".substring(0, scale - significantDigits);
s += coefficient;
s += coefficient.toString();
} else {
s += coefficient;
s += coefficient.toString();
s += "d-";
s += scale.toString();
}
} else {
// exponent > 0
s += coefficient + "d" + exponent;
s += coefficient.toString() + "d" + exponent;
}

this.writeUtf8(s);
Expand Down
2 changes: 1 addition & 1 deletion src/dom/Decimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Decimal extends Value(
* @param annotations An optional array of strings to associate with `value`.
*/
constructor(value: ion.Decimal, annotations: string[] = []) {
super(...[value.getCoefficient(), value.getExponent(), value.isNegative()]);
super(value.numberValue());
this._decimalValue = value;
this._numberValue = value.numberValue();
this._setAnnotations(annotations);
Expand Down
4 changes: 2 additions & 2 deletions src/events/IonEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class IonIntEvent extends AbstractIonEvent {
}
return new ComparisonResult(
ComparisonResultType.NOT_EQUAL,
this.ionValue + " vs. " + expected.ionValue
`${this.ionValue} vs. ${expected.ionValue}`
);
}

Expand Down Expand Up @@ -870,7 +870,7 @@ class IonListEvent extends AbsIonContainerEvent {
) {
return new ComparisonResult(
ComparisonResultType.NOT_EQUAL,
child.ionValue + " vs. " + expectedContainer[i].ionValue,
`${child.ionValue} vs. ${expectedContainer[i].ionValue}`,
i + 1,
i + 1
);
Expand Down
3 changes: 2 additions & 1 deletion test/IonAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import {assert} from 'chai';
import * as ion from '../src/Ion';
import JSBI from "jsbi";

function readerToBytes(reader) {
let writer = ion.makeTextWriter();
Expand All @@ -33,7 +34,7 @@ describe('Annotations', () => {
let reader = ion.makeReader(data);
reader.next();
assert.deepEqual(reader.annotations(), ['a', 'b']);
assert.equal(reader.value(), '123');
assert.equal(reader.value()?.toString(), '123');
assert.equal(readerToString(reader), 'a::b::123');
});

Expand Down
6 changes: 4 additions & 2 deletions test/IonParserBinaryRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {assert} from 'chai';
import SignAndMagnitudeInt from "../src/SignAndMagnitudeInt";
import {BinarySpan} from "../src/IonSpan";
import {ParserBinaryRaw} from "../src/IonParserBinaryRaw";
import JSBI from "jsbi";

/**
* Tests for reading the UInt primitive follow.
Expand Down Expand Up @@ -49,7 +50,8 @@ let unsignedIntBytesMatchValue = (bytes: number[],
ParserBinaryRaw._readUnsignedIntAsBigIntFrom) => {
let binarySpan = new BinarySpan(new Uint8Array(bytes));
let actual = readFrom(binarySpan, bytes.length);
assert.equal(actual, expected)
actual = actual instanceof JSBI ? JSBI.toNumber(actual) : actual;
assert.equal(actual, expected);
};

let unsignedIntReadingTests = [
Expand Down Expand Up @@ -369,4 +371,4 @@ describe("Reading floats", () => {
);
});
});
});
});
4 changes: 2 additions & 2 deletions test/dom/Value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ function domValueTest(jsValue, expectedIonType) {
return () => {
// Test Value.from() with and without specifying annotations
let annotations = ["foo", "bar", "baz"];
it("" + jsValue, () => {
it(`${jsValue}`, () => {
validateDomValue(Value.from(jsValue), []);
});
it(annotations.join("::") + "::" + jsValue, () => {
it(annotations.join("::") + `::${jsValue}`, () => {
validateDomValue(Value.from(jsValue, annotations), annotations);
});
};
Expand Down
6 changes: 3 additions & 3 deletions test/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('DOM', () => {
assert.equal(101.5, +d);
assert.equal(101.5, d.numberValue());
assert.isTrue(new ion.Decimal('101.5').equals(d.decimalValue()!));
assert.equal(1015, +d.decimalValue()!.getCoefficient());
assert.equal(1015, JSBI.toNumber(d.decimalValue()!.getCoefficient()));
});

it('load() Decimal as any', () => {
Expand All @@ -234,7 +234,7 @@ describe('DOM', () => {
assert.equal(101.5, d);
assert.equal(101.5, +d);
assert.isTrue(new ion.Decimal('101.5').equals(d.decimalValue()));
assert.equal(1015, +d.decimalValue()!.getCoefficient());
assert.equal(1015, JSBI.toNumber(d.decimalValue()!.getCoefficient()));
});

it('load() Timestamp as Value', () => {
Expand Down Expand Up @@ -549,4 +549,4 @@ describe('DOM', () => {
// length is 1 with two values: 55, 41
assert.equal(1, s.fields().length)
});
});
});
2 changes: 1 addition & 1 deletion test/mochaSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function valueName(value: any): string {
}
if (typeof value === "object") {
let typeText = _hasValue(value.constructor) ? value.constructor.name : 'Object';
let valueText = _hasValue(value.toString) ? ''+value : JSON.stringify(value);
let valueText = _hasValue(value.toString) ? `${value}` : JSON.stringify(value);

return `${typeText}(${valueText})`;
}
Expand Down

0 comments on commit f1158ac

Please sign in to comment.