This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
68 lines
2.9 KiB
JavaScript
68 lines
2.9 KiB
JavaScript
import {compareVersions, padNumber} from '../../../src/ol/string.js';
|
|
|
|
describe('ol.string', function () {
|
|
describe('ol.string.padNumber', function () {
|
|
it('returns the correct padding without precision', function () {
|
|
expect(padNumber(6.5, 2)).to.be('06.5');
|
|
expect(padNumber(6.5, 3)).to.be('006.5');
|
|
expect(padNumber(1.25, 2)).to.be('01.25');
|
|
expect(padNumber(5, 3)).to.be('005');
|
|
});
|
|
|
|
it('returns the same string when padding is less than length', function () {
|
|
expect(padNumber(6.5, 0)).to.be('6.5');
|
|
expect(padNumber(6.5, 1)).to.be('6.5');
|
|
expect(padNumber(1.25, 0)).to.be('1.25');
|
|
expect(padNumber(5, 0)).to.be('5');
|
|
expect(padNumber(5, 1)).to.be('5');
|
|
});
|
|
|
|
it('returns the correct string precision is given', function () {
|
|
expect(padNumber(6.5, 0, 2)).to.be('6.50');
|
|
expect(padNumber(6.5, 1, 2)).to.be('6.50');
|
|
expect(padNumber(6.5, 2, 2)).to.be('06.50');
|
|
expect(padNumber(1.25, 2, 3)).to.be('01.250');
|
|
expect(padNumber(1.25, 2, 1)).to.be('01.3');
|
|
expect(padNumber(9.9, 2, 0)).to.be('10');
|
|
expect(padNumber(5, 0, 0)).to.be('5');
|
|
expect(padNumber(5, 1, 1)).to.be('5.0');
|
|
expect(padNumber(5, 2, 1)).to.be('05.0');
|
|
expect(padNumber(5, 2, 0)).to.be('05');
|
|
});
|
|
});
|
|
|
|
describe('ol.string.compareVersions', function () {
|
|
it('should return the correct value for number input', function () {
|
|
expect(compareVersions(1, 1)).to.be(0);
|
|
expect(compareVersions(1.0, 1.1)).to.be.below(0);
|
|
expect(compareVersions(2.0, 1.1)).to.be.above(0);
|
|
});
|
|
it('should return the correct value for string input', function () {
|
|
expect(compareVersions('1.0', '1.0')).to.be(0);
|
|
expect(compareVersions('1.0.0.0', '1.0')).to.be(0);
|
|
expect(compareVersions('1.000', '1.0')).to.be(0);
|
|
expect(compareVersions('1.0.2.1', '1.1')).to.be.below(0);
|
|
expect(compareVersions('1.1', '1.0.2.1')).to.be.above(0);
|
|
expect(compareVersions('1', '1.1')).to.be.below(0);
|
|
expect(compareVersions('2.2', '2')).to.be.above(0);
|
|
|
|
expect(compareVersions('9.5', '9.10')).to.be.below(0);
|
|
expect(compareVersions('9.5', '9.11')).to.be.below(0);
|
|
expect(compareVersions('9.11', '9.10')).to.be.above(0);
|
|
expect(compareVersions('9.1', '9.10')).to.be.below(0);
|
|
expect(compareVersions('9.1.1', '9.10')).to.be.below(0);
|
|
expect(compareVersions('9.1.1', '9.11')).to.be.below(0);
|
|
|
|
expect(compareVersions(' 7', '6')).to.be.above(0);
|
|
expect(compareVersions('7 ', '6')).to.be.above(0);
|
|
expect(compareVersions(' 7 ', '6')).to.be.above(0);
|
|
expect(compareVersions('7', ' 6')).to.be.above(0);
|
|
expect(compareVersions('7', '6 ')).to.be.above(0);
|
|
expect(compareVersions('7', ' 6 ')).to.be.above(0);
|
|
expect(compareVersions(' 7', ' 6')).to.be.above(0);
|
|
expect(compareVersions('7 ', '6 ')).to.be.above(0);
|
|
expect(compareVersions(' 7 ', ' 6 ')).to.be.above(0);
|
|
});
|
|
});
|
|
});
|