Skip to content

Commit

Permalink
Test the error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Mar 24, 2024
1 parent 6751949 commit e473a67
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function subsetFont(
exports.hb_face_destroy(face);
exports.free(fontBuffer);
throw new Error(
`hb_subset_input_pin_axis_location (harfbuzz) returned zero when pinning ${axisName} and a value of ${value}, indicating failure.`
`hb_subset_input_pin_axis_location (harfbuzz) returned zero when pinning ${axisName} to ${value}, indicating failure. Maybe the axis does not exist in the font?`
);
}
} else if (value && typeof value === 'object') {
Expand Down Expand Up @@ -126,7 +126,7 @@ async function subsetFont(
exports.hb_face_destroy(face);
exports.free(fontBuffer);
throw new Error(
`hb_subset_input_set_axis_range (harfbuzz) returned zero when setting the range of ${axisName} to [${value.min}; ${value.max}] and a default value of ${value.default}, indicating failure.`
`hb_subset_input_set_axis_range (harfbuzz) returned zero when setting the range of ${axisName} to [${value.min}; ${value.max}] and a default value of ${value.default}, indicating failure. Maybe the axis does not exist in the font?`
);
}
}
Expand Down
63 changes: 63 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,69 @@ describe('subset-font', function () {
// When not instancing the subset font is about 29 KB
expect(result.length, 'to be less than', 25000);
});

describe('when leaving out a min value', function () {
it('should error', async function () {
await expect(
() =>
subsetFont(this.variableRobotoFont, 'abcd', {
variationAxes: {
wght: { max: 300 },
},
}),
'to error',
'wght: You must provide both a min and a max value when setting the axis range'
);
});
});

describe('when leaving out a max value', function () {
it('should error', async function () {
await expect(
() =>
subsetFont(this.variableRobotoFont, 'abcd', {
variationAxes: {
wght: { min: 300 },
},
}),
'to error',
'wght: You must provide both a min and a max value when setting the axis range'
);
});
});

describe('when pinning a non-existent axis', function () {
it('should error', async function () {
await expect(
() =>
subsetFont(this.variableRobotoFont, 'abcd', {
variationAxes: {
foob: 123,
},
}),
'to error',
'hb_subset_input_pin_axis_location (harfbuzz) returned zero when pinning foob to 123, indicating failure. Maybe the axis does not exist in the font?'
);
});
});

describe('when reducing the variation space of a non-existent axis', function () {
it('should error', async function () {
await expect(
() =>
subsetFont(this.variableRobotoFont, 'abcd', {
variationAxes: {
foob: {
min: 123,
max: 456,
},
},
}),
'to error',
'hb_subset_input_set_axis_range (harfbuzz) returned zero when setting the range of foob to [123; 456] and a default value of undefined, indicating failure. Maybe the axis does not exist in the font?'
);
});
});
});
});
});

0 comments on commit e473a67

Please sign in to comment.