| /** |
| * @license |
| * Copyright 2017 Google LLC |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| import '../test/common-test-setup-karma'; |
| import {pluralize, ordinal, listForSentence} from './string-util'; |
| |
| suite('formatter util tests', () => { |
| test('pluralize', () => { |
| const noun = 'comment'; |
| assert.equal(pluralize(0, noun), ''); |
| assert.equal(pluralize(1, noun), '1 comment'); |
| assert.equal(pluralize(2, noun), '2 comments'); |
| }); |
| |
| test('ordinal', () => { |
| assert.equal(ordinal(0), '0th'); |
| assert.equal(ordinal(1), '1st'); |
| assert.equal(ordinal(2), '2nd'); |
| assert.equal(ordinal(3), '3rd'); |
| assert.equal(ordinal(4), '4th'); |
| assert.equal(ordinal(10), '10th'); |
| assert.equal(ordinal(11), '11th'); |
| assert.equal(ordinal(12), '12th'); |
| assert.equal(ordinal(13), '13th'); |
| assert.equal(ordinal(44413), '44413th'); |
| assert.equal(ordinal(44451), '44451st'); |
| }); |
| |
| test('listForSentence', () => { |
| assert.equal(listForSentence(['Foo', 'Bar', 'Baz']), 'Foo, Bar, and Baz'); |
| assert.equal(listForSentence(['Foo', 'Bar']), 'Foo and Bar'); |
| assert.equal(listForSentence(['Foo']), 'Foo'); |
| assert.equal(listForSentence([]), ''); |
| }); |
| }); |