import { describe, it, expect } from 'vitest'; import { parseCommand, type Command } from '../../src/utils/command'; describe('parseCommand', () => { it('should parse empty string', () => { const result = parseCommand(''); expect(result).toEqual({ name: '', flags: {}, options: {}, params: [] }); }); it('should parse command name only', () => { const result = parseCommand('move'); expect(result).toEqual({ name: 'move', flags: {}, options: {}, params: [] }); }); it('should parse command with params', () => { const result = parseCommand('move meeple1 region1'); expect(result).toEqual({ name: 'move', flags: {}, options: {}, params: ['meeple1', 'region1'] }); }); it('should parse command with long flags', () => { const result = parseCommand('move meeple1 --force --quiet'); expect(result).toEqual({ name: 'move', flags: { force: true, quiet: true }, options: {}, params: ['meeple1'] }); }); it('should parse command with short flags', () => { const result = parseCommand('move meeple1 -f -q'); expect(result).toEqual({ name: 'move', flags: { f: true, q: true }, options: {}, params: ['meeple1'] }); }); it('should parse command with long options', () => { const result = parseCommand('move meeple1 --x 10 --y 20'); expect(result).toEqual({ name: 'move', flags: {}, options: { x: '10', y: '20' }, params: ['meeple1'] }); }); it('should parse command with short options', () => { const result = parseCommand('move meeple1 -x 10 -y 20'); expect(result).toEqual({ name: 'move', flags: {}, options: { x: '10', y: '20' }, params: ['meeple1'] }); }); it('should parse command with mixed flags和选项', () => { const result = parseCommand('move meeple1 region1 --force -x 10 -q'); expect(result).toEqual({ name: 'move', flags: { force: true, q: true }, options: { x: '10' }, params: ['meeple1', 'region1'] }); }); it('should handle extra whitespace', () => { const result = parseCommand(' move meeple1 --force '); expect(result).toEqual({ name: 'move', flags: { force: true }, options: {}, params: ['meeple1'] }); }); it('should parse complex command', () => { const result = parseCommand('place meeple1 board --x 5 --y 3 --rotate 90 --force'); expect(result).toEqual({ name: 'place', flags: { force: true }, options: { x: '5', y: '3', rotate: '90' }, params: ['meeple1', 'board'] }); }); it('should treat negative number as option value', () => { const result = parseCommand('set --value -10'); expect(result).toEqual({ name: 'set', flags: {}, options: { value: '-10' }, params: [] }); }); });