claude-code-best/src/utils/__tests__/slashCommandParsing.test.ts
2026-05-01 21:39:30 +08:00

59 lines
1.5 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { parseSlashCommand } from '../slashCommandParsing'
describe('parseSlashCommand', () => {
test('parses simple command', () => {
const result = parseSlashCommand('/search foo bar')
expect(result).toEqual({
commandName: 'search',
args: 'foo bar',
isMcp: false,
})
})
test('parses command without args', () => {
const result = parseSlashCommand('/help')
expect(result).toEqual({
commandName: 'help',
args: '',
isMcp: false,
})
})
test('parses MCP command', () => {
const result = parseSlashCommand('/tool (MCP) arg1 arg2')
expect(result).toEqual({
commandName: 'tool (MCP)',
args: 'arg1 arg2',
isMcp: true,
})
})
test('parses MCP command without args', () => {
const result = parseSlashCommand('/tool (MCP)')
expect(result).toEqual({
commandName: 'tool (MCP)',
args: '',
isMcp: true,
})
})
test('returns null for non-slash input', () => {
expect(parseSlashCommand('hello')).toBeNull()
})
test('returns null for empty string', () => {
expect(parseSlashCommand('')).toBeNull()
})
test('returns null for just slash', () => {
expect(parseSlashCommand('/')).toBeNull()
})
test('trims whitespace before parsing', () => {
const result = parseSlashCommand(' /search foo ')
expect(result!.commandName).toBe('search')
expect(result!.args).toBe('foo')
})
})