<commit_before>import { FnAny, _testSuites } from './_testSuites';
import { expect, should } from 'chai';

import { truncate } from '../src/alpha';

should();

const suiteText: string = 'Truncate string to a shorter one.';

const tests: object = {};
const inputs: object = {};
const answers: object = {};

const funcs: FnAny[] = [
  truncate,
];

tests['truncate'] = [
  'return \'\' for empty string.',
  'truncate string with all spaces as normal.',
  'return \'\' for  -ve length.',
  'return \'\' for  zero length.',
  'return copy of original string if length too long.',
  'make use the passed in padding string.',
  'use ... when length is >= 10 char.',
  'use … when length is < 10 char.',
  'return padding only if length is 3.',
  'return padding only if length is 2.',
  'return padding only if length is 1.',
];

const str: string = 'hello world to everyone.';

inputs['truncate'] = [
  ['', 50],
  ['   ', 50],
  [str, -1],
  [str, 0],
  [str, 50],
  [str, 10, '='],
  [str, 10],
  [str, 9],
  [str, 3, '==='],
  [str, 2, '==='],
  [str, 1, '==='],
];

answers['truncate'] = [
  '',
  '   ',
  '',
  '',
  str,
  'hello wor=',
  'hello w...',
  'hello wo…',
  '===',
  '==',
  '=',
];

_testSuites(funcs, tests, inputs, answers, suiteText, __filename);
<commit_msg>add: test for extra long padding in truncate()<commit_after>import { FnAny, _testSuites } from './_testSuites';
import { expect, should } from 'chai';

import { truncate } from '../src/alpha';

should();

const suiteText: string = 'Truncate string to a shorter one.';

const tests: object = {};
const inputs: object = {};
const answers: object = {};

const funcs: FnAny[] = [
  truncate,
];

tests['truncate'] = [
  'return \'\' for empty string.',
  'truncate string with all spaces as normal.',
  'return \'\' for  -ve length.',
  'return \'\' for  zero length.',
  'return copy of original string if length too long.',
  'make use the passed in padding string.',
  'limit padding string to half a word (3 char).',
  'use ... when length is >= 10 char.',
  'use … when length is < 10 char.',
  'return padding only if length is 3.',
  'return padding only if length is 2.',
  'return padding only if length is 1.',
];

const str: string = 'hello world to everyone.';

inputs['truncate'] = [
  ['', 50],
  ['   ', 50],
  [str, -1],
  [str, 0],
  [str, 50],
  [str, 10, '='],
  [str, 20, '======='],
  [str, 10],
  [str, 9],
  [str, 3, '==='],
  [str, 2, '==='],
  [str, 1, '==='],
];

answers['truncate'] = [
  '',
  '   ',
  '',
  '',
  str,
  'hello wor=',
  'hello world to ev===',
  'hello w...',
  'hello wo…',
  '===',
  '==',
  '=',
];

_testSuites(funcs, tests, inputs, answers, suiteText, __filename);

{'fraction_non_alphanumeric': 0.2137546468401487, 'fraction_numerical': 0.018215613382899627, 'mean_word_length': 3.095890410958904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2612604', 'n_tokens_mistral': 1025, 'n_tokens_neox': 973, 'n_words': 320}