mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-28 10:01:58 +00:00
## About The Pull Request 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> ## Why It's Good For The Game 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
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('&');
|
|
});
|
|
});
|