Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,174 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import {expect} from 'chai';
import NumberFormatter from '../../../_dev/cldr/number-formatter';
import PriceSpecification from '../../../_dev/cldr/specifications/price';
import NumberSymbol from '../../../_dev/cldr/number-symbol';
describe('NumberFormatter', () => {
let currency;
beforeEach(() => {
const symbol = new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
'×',
'‰',
'∞',
'NaN',
);
currency = new NumberFormatter(
new PriceSpecification(
'¤#,##0.###',
'-¤#,##0.###',
symbol,
3,
0,
true,
3,
3,
'$',
'USD',
),
);
});
describe('extractMajorMinorDigits', () => {
const assertions = [
[10, ['10', '']],
[10.1, ['10', '1']],
[11.12345, ['11', '12345']],
[11.00000, ['11', '']],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]}`, () => {
expect(currency.extractMajorMinorDigits(assertion[0])).to.eql(assertion[1]);
});
});
});
describe('getCldrPattern', () => {
const assertions = [
[false, '¤#,##0.###'],
[true, '-¤#,##0.###'],
];
assertions.forEach((assertion) => {
it(`test isNegative ${assertion[0]}`, () => {
expect(currency.getCldrPattern(assertion[0])).to.eq(assertion[1]);
});
});
});
describe('splitMajorGroups', () => {
const assertions = [
['10', '10'],
['100', '100'],
['1000', '1,000'],
['10000', '10,000'],
['100000', '100,000'],
['1000000', '1,000,000'],
['10000000', '10,000,000'],
['100000000', '100,000,000'],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]} should display ${assertion[1]}`, () => {
expect(currency.splitMajorGroups(assertion[0])).to.eq(assertion[1]);
});
});
});
describe('adjustMinorDigitsZeroes', () => {
const assertions = [
['10000', '10'],
['100', '100'],
['12', '12'],
['120', '120'],
['1271', '1271'],
['1270', '127'],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]} should display ${assertion[1]}`, () => {
currency.numberSpecification.minFractionDigits = 2;
expect(currency.adjustMinorDigitsZeroes(assertion[0])).to.eq(assertion[1]);
});
});
});
describe('addPlaceholders', () => {
const assertions = [
['100,000.13', '¤#,##0.00', '¤100,000.13'],
['100.13', '¤#,##0.00', '¤100.13'],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]} with pattern ${assertion[1]} should display ${assertion[2]}`, () => {
expect(currency.addPlaceholders(assertion[0], assertion[1])).to.eq(assertion[2]);
});
});
});
describe('replaceSymbols', () => {
it('should replace all symbols', () => {
currency.numberSpecification.symbol = new NumberSymbol(
'_',
':)',
';',
'%',
'Moins',
'+',
'E',
'×',
'‰',
'∞',
'NaN',
);
expect(currency.replaceSymbols('¤-10,000,000.13')).to.eq('¤Moins10:)000:)000_13');
});
});
describe('addPlaceholders', () => {
it('should replace currency symbol', () => {
expect(currency.performSpecificReplacements('¤10,000,000.13')).to.eq('$10,000,000.13');
});
});
describe('format', () => {
const assertions = [
['10.3', '$10.300'],
['100.34', '$100.340'],
['1000.345', '$1,000.345'],
['10000.3456', '$10,000.346'],
['100000.512', '$100,000.512'],
['1000000', '$1,000,000.000'],
['10000000', '$10,000,000.000'],
['100000000', '$100,000,000.000'],
['-10.3', '-$10.300'],
['-125.45672', '-$125.457'],
['-125.45627', '-$125.456'],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]} should display ${assertion[1]}`, () => {
expect(currency.format(assertion[0])).to.eq(assertion[1]);
});
});
});
});

View File

@@ -0,0 +1,153 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import {expect} from 'chai';
import NumberSymbol from '../../../_dev/cldr/number-symbol';
describe('NumberSymbol', () => {
describe('validateData', () => {
it('should throw if invalid decimal', () => {
expect(() => { new NumberSymbol(); }).to.throw('Invalid decimal');
});
it('should throw if invalid group', () => {
expect(() => {
new NumberSymbol(
'.',
);
}).to.throw('Invalid group');
});
it('should throw if invalid symbol list', () => {
expect(() => {
new NumberSymbol(
'.',
',',
);
}).to.throw('Invalid symbol list');
});
it('should throw if invalid percentSign', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
);
}).to.throw('Invalid percentSign');
});
it('should throw if invalid minusSign', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
);
}).to.throw('Invalid minusSign');
});
it('should throw if invalid plusSign', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
'-',
);
}).to.throw('Invalid plusSign');
});
it('should throw if invalid exponential', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
);
}).to.throw('Invalid exponential');
});
it('should throw if invalid superscriptingExponent', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
);
}).to.throw('Invalid superscriptingExponent');
});
it('should throw if invalid perMille', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
'×',
);
}).to.throw('Invalid perMille');
});
it('should throw if invalid infinity', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
'×',
'‰',
);
}).to.throw('Invalid infinity');
});
it('should throw if invalid nan', () => {
expect(() => {
new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
'×',
'‰',
'∞',
);
}).to.throw('Invalid nan');
});
});
});

View File

@@ -0,0 +1,139 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import {expect} from 'chai';
import NumberSpecification from '../../../../_dev/cldr/specifications/number';
import NumberSymbol from '../../../../_dev/cldr/number-symbol';
describe('NumberSpecification', () => {
let symbol;
beforeEach(() => {
symbol = new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
'×',
'‰',
'∞',
'NaN',
);
});
describe('validateData', () => {
it('should throw if invalid positive pattern', () => {
expect(() => {
new NumberSpecification();
}).to.throw('Invalid positivePattern');
});
it('should throw if invalid negative pattern', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
);
}).to.throw('Invalid negativePattern');
});
it('should throw if invalid symbol', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
);
}).to.throw('Invalid symbol');
});
it('should throw if invalid maxFractionDigits', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
);
}).to.throw('Invalid maxFractionDigits');
});
it('should throw if invalid minFractionDigits', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
);
}).to.throw('Invalid minFractionDigits');
});
it('should throw if invalid groupingUsed', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
);
}).to.throw('Invalid groupingUsed');
});
it('should throw if invalid primaryGroupSize', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
false,
);
}).to.throw('Invalid primaryGroupSize');
});
it('should throw if invalid secondaryGroupSize', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
true,
3,
);
}).to.throw('Invalid secondaryGroupSize');
});
it('should not throw if everything is ok', () => {
expect(() => {
new NumberSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
true,
3,
3,
);
}).to.not.throw();
});
});
});

View File

@@ -0,0 +1,172 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import {expect} from 'chai';
import PriceSpecification from '../../../../_dev/cldr/specifications/price';
import NumberSymbol from '../../../../_dev/cldr/number-symbol';
describe('PriceSpecification', () => {
let symbol;
beforeEach(() => {
symbol = new NumberSymbol(
'.',
',',
';',
'%',
'-',
'+',
'E',
'×',
'‰',
'∞',
'NaN',
);
});
describe('validateData', () => {
it('should throw if invalid positive pattern', () => {
expect(() => {
new PriceSpecification();
}).to.throw('Invalid positivePattern');
});
it('should throw if invalid negative pattern', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
);
}).to.throw('Invalid negativePattern');
});
it('should throw if invalid symbol', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
);
}).to.throw('Invalid symbol');
});
it('should throw if invalid maxFractionDigits', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
);
}).to.throw('Invalid maxFractionDigits');
});
it('should throw if invalid minFractionDigits', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
);
}).to.throw('Invalid minFractionDigits');
});
it('should throw if invalid groupingUsed', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
);
}).to.throw('Invalid groupingUsed');
});
it('should throw if invalid primaryGroupSize', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
false,
);
}).to.throw('Invalid primaryGroupSize');
});
it('should throw if invalid secondaryGroupSize', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
true,
3,
);
}).to.throw('Invalid secondaryGroupSize');
});
it('should throw if invalid currencySymbol', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
true,
3,
3,
);
}).to.throw('Invalid currencySymbol');
});
it('should throw if invalid currencyCode', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
true,
3,
3,
'$',
);
}).to.throw('Invalid currencyCode');
});
it('should not throw if everything is ok', () => {
expect(() => {
new PriceSpecification(
'#,##0.###',
'-#,##0.###',
symbol,
3,
0,
true,
3,
3,
'$',
'USD',
);
}).to.not.throw();
});
});
});

View File

@@ -0,0 +1,57 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import {expect} from 'chai';
import getQueryParameters from '../../../_dev/front/urlparser';
describe('getQueryParameters', () => {
const assertions = [
[
'q=%C3%89tat-Nouveau%2FPrix-%E2%82%AC-22-42',
[{
name: 'q',
value: 'État-Nouveau/Prix-€-22-42',
}],
],
[
'q=Prix-%E2%82%AC-22-42/Composition-Carton recycl%C3%A9',
[{
name: 'q',
value: 'Prix-€-22-42/Composition-Carton recyclé',
}],
],
[
'q=Prix-%E2%82%AC-22-42/Composition-Carton recycl%C3%A9&something=thisIsSparta',
[
{
name: 'q',
value: 'Prix-€-22-42/Composition-Carton recyclé',
},
{
name: 'something',
value: 'thisIsSparta',
},
],
],
];
assertions.forEach((assertion) => {
it(`test ${assertion[0]}`, () => {
expect(getQueryParameters(assertion[0])).to.eql(assertion[1]);
});
});
});