e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 1 | import assert from 'node:assert/strict'; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 2 | import { test } from 'node:test'; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 3 | import { isKnownCommand, parseCommand, splitTarget, unescapeCommand } from '../src/lib/commands.ts'; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 4 | |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 5 | const people = [ |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 6 | { user_id: '@alice:example.org', name: 'Alice Liddell', avatar: null }, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 7 | { user_id: '@al:example.org', name: 'Alice', avatar: null }, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 8 | { user_id: '@bob:example.org', name: 'Bob', avatar: null }, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 9 | { user_id: '@bob2:example.org', name: 'Bob', avatar: null } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 10 | ]; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 11 | |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 12 | test('parses a leading command and leaves text alone', () => { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 13 | assert.deepEqual(parseCommand('/kick Bob being rude '), { name: 'kick', args: 'Bob being rude' }); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 14 | assert.deepEqual(parseCommand('/leave'), { name: 'leave', args: '' }); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 15 | assert.equal(parseCommand('hello /kick'), null); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 16 | assert.equal(parseCommand('//kick bob'), null); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 17 | assert.equal(unescapeCommand('//kick bob'), '/kick bob'); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 18 | assert.equal(isKnownCommand('kick'), true); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 19 | assert.equal(isKnownCommand('shrug'), false); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 20 | }); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 21 | |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 22 | test('finds targets by id or the longest display name', () => { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 23 | assert.deepEqual(splitTarget('@carol:example.org 50', people), { user_id: '@carol:example.org', rest: '50' }); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 24 | assert.deepEqual(splitTarget('Alice Liddell spam', people), { user_id: '@alice:example.org', rest: 'spam' }); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 25 | assert.deepEqual(splitTarget('alice', people), { user_id: '@al:example.org', rest: '' }); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 26 | assert.ok('error' in splitTarget('Bob', people)); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 27 | assert.ok('error' in splitTarget('Zed', people)); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 28 | assert.ok('error' in splitTarget('', people)); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 29 | }); |