mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
61 lines
2.6 KiB
TypeScript
61 lines
2.6 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { translateToGnomeSpeak, shouldTranslateToGnomeSpeak } from './gnomeSpeak';
|
|
|
|
describe('gnomeSpeak', () => {
|
|
describe('shouldTranslateToGnomeSpeak', () => {
|
|
it('returns true for kind 1 events', () => {
|
|
expect(shouldTranslateToGnomeSpeak(1)).toBe(true);
|
|
});
|
|
|
|
it('returns false for other event kinds', () => {
|
|
expect(shouldTranslateToGnomeSpeak(0)).toBe(false);
|
|
expect(shouldTranslateToGnomeSpeak(3)).toBe(false);
|
|
expect(shouldTranslateToGnomeSpeak(1111)).toBe(false);
|
|
expect(shouldTranslateToGnomeSpeak(30023)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('translateToGnomeSpeak', () => {
|
|
it('translates basic words to gnome speak', () => {
|
|
const result = translateToGnomeSpeak('Hello world! This is good.');
|
|
expect(result).toContain('Greetings, fellow');
|
|
expect(result).toContain('splendid as');
|
|
});
|
|
|
|
it('preserves URLs during translation', () => {
|
|
const result = translateToGnomeSpeak('Check out https://example.com for good info');
|
|
expect(result).toMatch(/https:\/\/example/);
|
|
expect(result).toContain('splendid as');
|
|
});
|
|
|
|
it('preserves nostr references during translation', () => {
|
|
const result = translateToGnomeSpeak('Follow nostr:npub1zg69v7ys40x77y352eufp27daufrg4ncjz4ummcjx3t83y9tehhsqepuh0 for good content');
|
|
expect(result).toContain('nostr:npub1zg69v7ys40x77y352eufp27daufrg4ncjz4ummcjx3t83y9tehhsqepuh0');
|
|
expect(result).toContain('splendid as');
|
|
});
|
|
|
|
it('preserves hashtags during translation', () => {
|
|
const result = translateToGnomeSpeak('This is about #nostr and #bitcoin development');
|
|
expect(result).toContain('#nostr');
|
|
expect(result).toContain('#bitcoin');
|
|
});
|
|
|
|
it('adds gnome-specific formatting for special terms', () => {
|
|
const result = translateToGnomeSpeak('I love bitcoin and gm everyone!');
|
|
expect(result).toContain('golden acorns of the digital realm');
|
|
expect(result).toContain('🌅when dew kisses the earth🌅');
|
|
});
|
|
|
|
it('handles empty or invalid input', () => {
|
|
expect(translateToGnomeSpeak('')).toBe('');
|
|
expect(translateToGnomeSpeak(null as unknown as string)).toBe(null);
|
|
expect(translateToGnomeSpeak(undefined as unknown as string)).toBe(undefined);
|
|
});
|
|
|
|
it('capitalizes sentences properly', () => {
|
|
const result = translateToGnomeSpeak('hello world. this is good.');
|
|
expect(result).toMatch(/^[A-Z]/); // Should start with capital letter
|
|
expect(result).toMatch(/\. [A-Z]/); // Should capitalize after periods
|
|
});
|
|
});
|
|
}); |