~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
42 lines · 2.0 KB Raw History
// `npm run unit` in web/ (`just check` runs it).
import { strict as assert } from 'node:assert';
import { test } from 'node:test';
import { spacing, translateOf } from './translate.ts';

test('an @handle or a DID is kept from translation', () => {
	assert.equal(translateOf('@chadtmiller.com'), 'no');
	assert.equal(translateOf('@tx3.grapevyne.social'), 'no');
	assert.equal(translateOf('lineasonora.bsky.social'), 'no');
	assert.equal(translateOf(' @natespilman.at '), 'no');
	assert.equal(translateOf('did:plc:kqd2csf4wvgvqioz374r5r2y'), 'no');
	assert.equal(translateOf('did:web:grain.social'), 'no');
});

test('a web address is kept from translation', () => {
	assert.equal(translateOf('https://grain.social'), 'no');
	assert.equal(translateOf('https://localhost:8080/a?b=c'), 'no');
	assert.equal(translateOf('grain.social/prints'), 'no');
	assert.equal(translateOf('bsky.app/profile/alice.test/post/3k…'), 'no');
});

test('words are translated with the page', () => {
	assert.equal(translateOf('Atardecer en la playa'), undefined);
	assert.equal(translateOf('Show more'), undefined);
	assert.equal(translateOf('Hi @alice.test, look'), undefined);
	assert.equal(translateOf('v1.2'), undefined);
	assert.equal(translateOf('3.5'), undefined);
	assert.equal(translateOf(''), undefined);
	assert.equal(translateOf(null), undefined);
	assert.equal(translateOf('on my website'), undefined);
	assert.equal(translateOf('Read it at https://grain.social'), undefined);
});

test("the spaces beside a text's ends and its line breaks are kept from translation, its words not", () => {
	const kept = (text: string) => spacing(text).map((part) => (part.kept ? `[${part.text}]` : part.text)).join('');
	assert.equal(kept('Oakland, CA\n'), 'Oakland, CA[\n]');
	assert.equal(kept(' and shooting film\nPrints at '), '[ ]and shooting film[\n]Prints at[ ]');
	assert.equal(kept('always \n\n Say hello'), 'always[ \n\n ]Say hello');
	assert.equal(kept('two  words'), 'two  words');
	assert.equal(kept('   '), '[   ]');
	assert.deepEqual(spacing(''), []);
});