import { Command, CommandRouter } from './command-router'; import { message } from '../../test/fakes'; const command: Command = { id: 'checkin', paths: [['checkin'], ['签到']], bare: ['签到'], description: { 'zh-CN': '签到', en: 'check in' }, usage: { 'zh-CN': '!签到', en: '!checkin' }, run: async () => undefined }; describe('shared command aliases', () => { it.each(['签到', '!签到', '!签到', '/签到', '/checkin', '!CHECKIN', '!checkin'])('%s resolves to the same command', (text) => { expect(new CommandRouter([command]).match(message(text))?.command.id).toBe('checkin'); }); it('does not parse normal conversation as commands', () => { expect(new CommandRouter([command]).match(message('今天已经签到了吗'))).toBeUndefined(); expect(new CommandRouter([command]).match(message('checkin'))).toBeUndefined(); }); it('matches longest registered paths and preserves quoted arguments', () => { const nested = { ...command, id: 'query', paths: [['签到', '查询']], bare: [] }; const result = new CommandRouter([command, nested]).match(message('!签到 查询 "value with spaces" --原始'))!; expect(result.command.id).toBe('query'); expect(result.invocation).toMatchObject({ args: ['value with spaces'], raw: true }); }); it('rejects alias collisions instead of dispatching multiple handlers', () => { expect(() => new CommandRouter([command, { ...command, id: 'other' }])).toThrow('Duplicate'); }); });