From 3ad2bb35a5e16e2c4937ef03c0bd303924f3c485 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 6 Feb 2017 11:40:18 +0100 Subject: [PATCH] =?utf8?q?js=20parse=5F/format=5Famount:=20Tests=20f=C3=BC?= =?utf8?q?r=20Swiss-Zahlenformat=20&=20f=C3=BCr=20Nicht-Oktal-Parsen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- js/t/kivi/format_amount.js | 10 ++++++++++ js/t/kivi/parse_amount.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/js/t/kivi/format_amount.js b/js/t/kivi/format_amount.js index bfc093ddc..256c2eae4 100644 --- a/js/t/kivi/format_amount.js +++ b/js/t/kivi/format_amount.js @@ -38,6 +38,16 @@ QUnit.test("kivi.format_amount function English number style without thousand se assert.equal(kivi.format_amount(-1000000000.1234, 2), '-1000000000.12', 'format -1000000000.1234'); }); +QUnit.test("kivi.format_amount function Swiss number style with thousand separator", function( assert ) { + kivi.setup_formats({ numbers: '1\'000.00' }); + + assert.equal(kivi.format_amount('1e1', 2), '10.00', 'format 1e1'); + assert.equal(kivi.format_amount(1000, 2), '1\'000.00', 'format 1000'); + assert.equal(kivi.format_amount(1000.1234, 2), '1\'000.12', 'format 1000.1234'); + assert.equal(kivi.format_amount(1000000000.1234, 2), '1\'000\'000\'000.12', 'format 1000000000.1234'); + assert.equal(kivi.format_amount(-1000000000.1234, 2), '-1\'000\'000\'000.12', 'format -1000000000.1234'); +}); + QUnit.test("kivi.format_amount function negative places", function( assert ) { kivi.setup_formats({ numbers: '1000.00' }); diff --git a/js/t/kivi/parse_amount.js b/js/t/kivi/parse_amount.js index d0c6e884f..9b7d2aa07 100644 --- a/js/t/kivi/parse_amount.js +++ b/js/t/kivi/parse_amount.js @@ -81,3 +81,31 @@ QUnit.test("kivi.parse_amount function English number style without thousand sep assert.equal(kivi.parse_amount('1010.987654321'), 1010.987654321, '1010.987654321'); assert.equal(kivi.parse_amount('1,010.987654321'), 1010.987654321, '1,010.987654321'); }); + +QUnit.test("kivi.parse_amount function Swiss number style with thousand separator", function( assert ) { + kivi.setup_formats({ numbers: '1\'000.00' }); + + assert.equal(kivi.parse_amount('10.00'), 10, '10.00'); + assert.equal(kivi.parse_amount('10.'), 10, '10.'); + assert.equal(kivi.parse_amount('1010.00'), 1010, '1010.00'); + assert.equal(kivi.parse_amount('1010.'), 1010, '1010.'); + assert.equal(kivi.parse_amount('1\'010.00'), 1010, '1\'010.00'); + assert.equal(kivi.parse_amount('1\'010.'), 1010, '1\'010.'); + assert.equal(kivi.parse_amount('9\'080\'070\'060\'050\'040\'030\'020\'010.00'), 9080070060050040030020010, '9\'080\'070\'060\'050\'040\'030\'020\'010.00'); + assert.equal(kivi.parse_amount('9\'080\'070\'060\'050\'040\'030\'020\'010.'), 9080070060050040030020010, '9\'080\'070\'060\'050\'040\'030\'020\'010.'); + + assert.equal(kivi.parse_amount('10.98'), 10.98, '10.98'); + assert.equal(kivi.parse_amount('1010.98'), 1010.98, '1010.98'); + assert.equal(kivi.parse_amount('1\'010.98'), 1010.98, '1\'010.98'); + + assert.equal(kivi.parse_amount('10.987654321'), 10.987654321, '10.987654321'); + assert.equal(kivi.parse_amount('1010.987654321'), 1010.987654321, '1010.987654321'); + assert.equal(kivi.parse_amount('1\'010.987654321'), 1010.987654321, '1\'010.987654321'); +}); + +QUnit.test("kivi.parse_amount function numbers with leading 0 should still be parsed as decimal and not octal", function( assert ) { + kivi.setup_formats({ numbers: '1000,00' }); + + assert.equal(kivi.parse_amount('0123456789'), 123456789, '0123456789'); + assert.equal(kivi.parse_amount('000123456789'), 123456789, '000123456789'); +}); -- 2.20.1