import { describe, it, expect } from 'vitest'; import { transformVowels, transformConsonants, preserveCase, transformWord, transformPattern, } from './translator'; import { TextElement, Pattern } from '@fluent/syntax'; describe('transformVowels', () => { it('should transform vowels correctly', () => { expect(transformVowels('hello')).toBe('hάllů'); expect(transformVowels('quick')).toBe('qøīck'); }); it('should return the same word if no vowels are present', () => { expect(transformVowels('gym')).toBe('gym'); }); }); describe('transformConsonants', () => { it('should transform consonants correctly', () => { expect(transformConsonants('hello')).toBe('ħe££o'); expect(transformConsonants('quick')).toBe('ʠuiĉʞ'); }); }); describe('preserveCase', () => { it('should preserve the case of the original word', () => { expect(preserveCase('Hello', 'ħëllø')).toBe('Ħëllø'); expect(preserveCase('hElLo', 'ħëllø')).toBe('ħËlLø'); }); it('should return the transformed word if there is no case to preserve', () => { expect(preserveCase('hello', 'ħëllø')).toBe('ħëllø'); }); }); describe('transformWord', () => { it('should transform and preserve case of the word', () => { expect(transformWord('Hello')).toBe('Ħά££ů'); expect(transformWord('quick')).toBe('ʠøīĉʞ'); }); it('should return the original word if it contains no alphabets', () => { expect(transformWord('123')).toBe('123'); expect(transformWord('!@#')).toBe('!@#'); }); }); describe('transformPattern', () => { it('should transform a simple sentence', () => { const input = new Pattern([new TextElement('Hello world')]); const expected = new Pattern([new TextElement('Ħά££ů ŵůř£ḍ')]); expect(transformPattern(input)).toEqual(expected); }); it('should preserve lines with special placeholders', () => { // eslint-disable-next-line no-template-curly-in-string const input = new Pattern([new TextElement('${text} [one] *[default]')]); // eslint-disable-next-line no-template-curly-in-string const expected = new Pattern([new TextElement('${text} [one] *[default]')]); expect(transformPattern(input)).toEqual(expected); }); it('should preserve lines with labels', () => { const input = new Pattern([new TextElement('.aria-label = Actions')]); const expected = new Pattern([new TextElement('.aria-label = Ëĉ†īůŋš')]); expect(transformPattern(input)).toEqual(expected); }); it('should only transform the last part of a sentence with multiple "=" signs', () => { const input = new Pattern([new TextElement('KEY = .aria-label = Actions')]); const expected = new Pattern([ new TextElement('KEY = .aria-label = Ëĉ†īůŋš'), ]); expect(transformPattern(input)).toEqual(expected); }); it('should only transform plain text within placeholders', () => { const input = new Pattern([ new TextElement('[true] including { $firstParticipant }'), ]); const expected = new Pattern([ new TextElement('[true] īŋĉ£øḍīŋğ { $firstParticipant }'), ]); expect(transformPattern(input)).toEqual(expected); }); it('should preserve comments and empty lines', () => { const input1 = new Pattern([new TextElement('# This is a comment')]); const expected1 = new Pattern([new TextElement('# This is a comment')]); expect(transformPattern(input1)).toEqual(expected1); const input2 = new Pattern([new TextElement('')]); const expected2 = new Pattern([new TextElement('')]); expect(transformPattern(input2)).toEqual(expected2); }); });