diff options
| author | stonedDiscord <Tukz@gmx.de> | 2025-06-26 18:37:30 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2025-06-26 18:37:30 +0200 |
| commit | 774ae2255f71f8939b365796f703579e1ee245af (patch) | |
| tree | 094a11cc9cfbe4c5fbc5cd775708ce3526a87511 /webAO/__tests__/encoding.test.ts | |
| parent | 576eacb298a6e4816a16f48e837785924ee2045f (diff) | |
encoding tests
Diffstat (limited to 'webAO/__tests__/encoding.test.ts')
| -rw-r--r-- | webAO/__tests__/encoding.test.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/webAO/__tests__/encoding.test.ts b/webAO/__tests__/encoding.test.ts new file mode 100644 index 0000000..36f34cf --- /dev/null +++ b/webAO/__tests__/encoding.test.ts @@ -0,0 +1,52 @@ +import { escapeChat, unescapeChat, safeTags, decodeChat, prepChat } from '../encoding'; + +describe('encode/decode', () => { + it('should escape special characters correctly', () => { + const input = '#&$%'; + const expectedOutput = '<num><and><dollar><percent>'; + expect(escapeChat(input)).toBe(expectedOutput); + }); + + it('should unescape special characters correctly', () => { + const input = '<num><and><dollar><percent>'; + const expectedOutput = '#&$%'; + expect(unescapeChat(input)).toBe(expectedOutput); + }); +}); + +describe('safeTags', () => { + it('should replace < with < and > with >', () => { + const input = '<div>Hello</div>'; + const expectedOutput = '<div>Hello</div>'; + expect(safeTags(input)).toBe(expectedOutput); + }); + + it('should handle empty strings correctly', () => { + expect(safeTags('')).toBe(''); + }); +}); + +describe('decodeChat', () => { + it('should decode escaped unicode characters', () => { + const input = '\\u0041\\u0026\\u003F'; + const expectedOutput = 'A&?'; + expect(decodeChat(input)).toBe(expectedOutput); + }); + + it('should handle no unicode to decode', () => { + const input = 'Hello World!'; + expect(decodeChat(input)).toBe(input); + }); +}); + +describe('prepChat', () => { + it('should apply safeTags, unescapeChat and decodeChat correctly', () => { + const input = '<num><and>A<percent>'; + const expectedOutput = '#&A%'; // Output after applying all functions in order + expect(prepChat(input)).toBe(expectedOutput); + }); + + it('should handle empty strings correctly', () => { + expect(prepChat('')).toBe(''); + }); +});
\ No newline at end of file |
