All Downloads are FREE. Search and download functionalities are using the official Maven repository.

__tests__.string-utils.test.js Maven / Gradle / Ivy

import { F } from "helpers/formatter"

test('basic pretty list', () => {
  expect(F.toList([])).toEqual("")
  expect(F.toList(["one"])).toEqual("one")
  expect(F.toList(["one", "two"], " and ")).toEqual("one and two")
  expect(F.toList(["one", "two", "three"], " and ")).toEqual("one, two and three")
})

test('limited pretty list', () => {
  expect(F.toList([], " and ", 1)).toEqual("")
  expect(F.toList(["one"], " and ", 1)).toEqual("one")
  expect(F.toList(["one", "two"], " and ", 1)).toEqual("one, ...")
  expect(F.toList(["one", "two", "three"], " and ", 2)).toEqual("one, ... and three")
  expect(F.toList(["one", "two", "three", "four"], " and ", 2)).toEqual("one, ... and four")
  expect(F.toList(["one", "two", "three", "four"], " and ", 3)).toEqual("one, two, ... and four")
  expect(F.toList(["one", "two", "three", "four"], " and ", 4)).toEqual("one, two, three and four")
})

test('different delimiters', () => {
  expect(F.toList([], " and ", 1, "; ")).toEqual("")
  expect(F.toList(["one"], " and ", 1, "; ")).toEqual("one")
  expect(F.toList(["one", "two"], " and ", 1, "; ")).toEqual("one; ...")
  expect(F.toList(["one", "two", "three"], " # ", 2, "; ")).toEqual("one; ... # three")
  expect(F.toList(["one", "two", "three"], " # ", 3, "; ")).toEqual("one; two # three")
})




© 2015 - 2024 Weber Informatics LLC | Privacy Policy