Skip to content

Commit

Permalink
Add unit tests and GitHub Actions integration
Browse files Browse the repository at this point in the history
  • Loading branch information
khashashin committed May 26, 2024
1 parent f94e6bc commit 7654514
Show file tree
Hide file tree
Showing 7 changed files with 3,792 additions and 24 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test -- --coverage

- name: Publish package
run: npx jsr publish
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/
node_modules/
105 changes: 105 additions & 0 deletions __tests__/translit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { apply, applyToWord, translitMap } from '../translit';

describe('translitMap', () => {
it('should contain mapping for Cyrillic "а" and "А"', () => {
expect(translitMap['а']).toBe('a');
expect(translitMap['А']).toBe('A');
});
});

describe('applyToWord', () => {
it('should transliterate a word correctly', () => {
expect(applyToWord('дӏахь')).toBe('djaẋ');
expect(applyToWord('доьгӏна')).toBe('döġna');
});

it('should handle words with special cases', () => {
expect(applyToWord('тӏ')).toBe('ṫ');
expect(applyToWord('къ')).toBe('q̇');
});

it('should handle uppercase words correctly', () => {
expect(applyToWord('Д')).toBe('D');
expect(applyToWord('Т')).toBe('T');
});

it('should handle mixed case words correctly', () => {
expect(applyToWord('КъХ')).toBe('Q̇X');
});

it('should handle words with standalone Cyrillic "ъ"', () => {
expect(applyToWord('къе')).toBe('q̇e');
expect(applyToWord('Къе')).toBe('Q̇e');
});

it('should handle words with Cyrillic "ъ" before "е", "ё", "ю", or "я"', () => {
expect(applyToWord('къе')).toBe('q̇e');
expect(applyToWord('къё')).toBe('q̇ö');
expect(applyToWord('къю')).toBe('q̇yu');
expect(applyToWord('къя')).toBe('q̇ya');
expect(applyToWord('къЕ')).toBe('q̇E');
expect(applyToWord('къЁ')).toBe('q̇Ö');
expect(applyToWord('къЮ')).toBe('q̇Yu');
expect(applyToWord('къЯ')).toBe('q̇Ya');
});

it('should handle "ъ" not preceded by "к" correctly', () => {
expect(applyToWord('ъе')).toBe('ye');
expect(applyToWord('Ъё')).toBe('ö');
expect(applyToWord('ъю')).toBe('yu');
expect(applyToWord('ъя')).toBe('ya');
});

it('should handle "ъ" preceded by a non-"к" character correctly', () => {
expect(applyToWord('мъе')).toBe('mye');
expect(applyToWord('Мъё')).toBe('Mö');
expect(applyToWord('пъю')).toBe('pyu');
expect(applyToWord('съя')).toBe('sya');
});

it('should handle words with "е" at the start correctly', () => {
expect(applyToWord('е')).toBe('ye');
expect(applyToWord('Е')).toBe('Ye');
});

it('should handle words with "н" at the end correctly', () => {
expect(applyToWord('тхан')).toBe('txaŋ');
expect(applyToWord('тхаН')).toBe('txaŊ');
});

it('should handle words without any special transliteration cases', () => {
expect(applyToWord('нанас')).toBe('nanas');
});
});

describe('apply', () => {
it('should transliterate a text correctly', () => {
const text = 'Мелхо а, шуна цхьанна а тхайх бала ца бархьама, дийнахь а, буса а, къа а хьоьгуш, болх бора оха.';
const expected = 'Melxo ə, şuna cẋanna ə txayx bala ca barẋama, diynaẋ ə, busa ə, q̇a ə ẋöguş, bolx bora oxa.';
expect(apply(text)).toBe(expected);
});

it('should replace standalone Cyrillic "а" with "ə"', () => {
expect(apply('дӏахь а доьгӏна')).toBe('djaẋ ə döġna');
});

it('should handle mixed case texts correctly', () => {
expect(apply('Дӏахь А доьгӏна')).toBe('Djaẋ A döġna');
});

it('should handle texts with punctuation', () => {
expect(apply('а, а. а!')).toBe('ə, ə. ə!');
});

it('should handle texts with hyphens correctly', () => {
expect(apply('доьгӏна-шун')).toBe('döġna-şuŋ');
});

it('should handle empty strings', () => {
expect(apply('')).toBe('');
});

it('should handle texts with no Cyrillic characters', () => {
expect(apply('Hello world!')).toBe('Hello world!');
});
});
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/'],
coverageThreshold: {
global: {
branches: 90,
functions: 90,
lines: 90,
statements: 90,
},
},
};
Loading

0 comments on commit 7654514

Please sign in to comment.