mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-18 13:43:27 +00:00
* tgui: Strings.ts (#83096) Wrote better docs and tests for string helpers in tgui. Something I noticed, which I'm ok with reverting, is that multiline does precisely nothing. And despite being a template string fn, it doesn't accept vars for interpolation. It looks as if it were used to circumvent a babel limitation, which we are no longer using. Removed: - babel plugin (unused) - multiline (no impact) - createGlobPattern (unused) - buildQueryString (unused) <details> <summary>Spot the difference</summary>   (There is none) </details> More core tools in TS. Better docs so hopefully these functions are more widely used (and done so properly) Tests so things don't break * Moduuular. --------- Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com> Co-authored-by: Useroth <37159550+Useroth@users.noreply.github.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { createSearch, decodeHtmlEntities, toTitleCase } from './string';
|
|
|
|
describe('createSearch', () => {
|
|
it('matches search terms correctly', () => {
|
|
const search = createSearch('test', (obj: { value: string }) => obj.value);
|
|
|
|
const obj1 = { value: 'This is a test string.' };
|
|
const obj2 = { value: 'This is a different string.' };
|
|
const obj3 = { value: 'This is a test string.' };
|
|
|
|
const objects = [obj1, obj2, obj3];
|
|
|
|
expect(objects.filter(search)).toEqual([obj1, obj3]);
|
|
});
|
|
});
|
|
|
|
describe('toTitleCase', () => {
|
|
it('converts strings to title case correctly', () => {
|
|
expect(toTitleCase('hello world')).toBe('Hello World');
|
|
expect(toTitleCase('HELLO WORLD')).toBe('Hello World');
|
|
expect(toTitleCase('HeLLo wORLd')).toBe('Hello World');
|
|
expect(toTitleCase('a tale of two cities')).toBe('A Tale of Two Cities');
|
|
expect(toTitleCase('war and peace')).toBe('War and Peace');
|
|
});
|
|
});
|
|
|
|
describe('decodeHtmlEntities', () => {
|
|
it('decodes HTML entities and removes unnecessary HTML tags correctly', () => {
|
|
expect(decodeHtmlEntities('<br>')).toBe('\n');
|
|
expect(decodeHtmlEntities('<p>Hello World</p>')).toBe('Hello World');
|
|
expect(decodeHtmlEntities('&')).toBe('&');
|
|
expect(decodeHtmlEntities('&')).toBe('&');
|
|
expect(decodeHtmlEntities('&')).toBe('&');
|
|
});
|
|
});
|