diff --git a/test/generators.spec.ts b/test/generators.spec.ts new file mode 100644 index 0000000..c525a9f --- /dev/null +++ b/test/generators.spec.ts @@ -0,0 +1,149 @@ +import { generateCode, getOutputFileName, getLanguageExtension } from '../src/generators/code-generator.js'; +import { generateCompletion, getCompletionFileName } from '../src/generators/completion-generator.js'; +import { generateManPage, generateReadmeSection } from '../src/generators/docs-generator.js'; +import { testSpec } from './fixtures.js'; + +describe('Code Generator', () => { + describe('Python generation', () => { + it('should generate Python code', () => { + const result = generateCode(testSpec, 'python'); + + expect(result.success).toBe(true); + expect(result.code).toBeDefined(); + expect(result.code).toContain('argparse'); + expect(result.code).toContain('test-cli'); + }); + + it('should include version info', () => { + const result = generateCode(testSpec, 'python'); + + expect(result.code).toContain('1.0.0'); + }); + }); + + describe('Go generation', () => { + it('should generate Go code', () => { + const result = generateCode(testSpec, 'go'); + + expect(result.success).toBe(true); + expect(result.code).toBeDefined(); + expect(result.code).toContain('flag'); + expect(result.code).toContain('test-cli'); + }); + }); + + describe('Rust generation', () => { + it('should generate Rust code', () => { + const result = generateCode(testSpec, 'rust'); + + expect(result.success).toBe(true); + expect(result.code).toBeDefined(); + expect(result.code).toContain('test-cli'); + }); + }); + + describe('Node.js Commander generation', () => { + it('should generate Node.js Commander code', () => { + const result = generateCode(testSpec, 'node-commander'); + + expect(result.success).toBe(true); + expect(result.code).toBeDefined(); + expect(result.code).toContain('commander'); + }); + }); + + describe('Node.js Yargs generation', () => { + it('should generate Node.js Yargs code', () => { + const result = generateCode(testSpec, 'node-yargs'); + + expect(result.success).toBe(true); + expect(result.code).toBeDefined(); + expect(result.code).toContain('yargs'); + }); + }); + + describe('file naming', () => { + it('should return correct extension for each language', () => { + expect(getLanguageExtension('python')).toBe('.py'); + expect(getLanguageExtension('go')).toBe('.go'); + expect(getLanguageExtension('rust')).toBe('.rs'); + expect(getLanguageExtension('node-commander')).toBe('.ts'); + expect(getLanguageExtension('node-yargs')).toBe('.ts'); + }); + + it('should return correct output file name', () => { + expect(getOutputFileName(testSpec, 'python')).toBe('test-cli.py'); + expect(getOutputFileName(testSpec, 'go')).toBe('test-cli.go'); + expect(getOutputFileName(testSpec, 'rust')).toBe('test-cli.rs'); + }); + }); +}); + +describe('Completion Generator', () => { + describe('bash completion', () => { + it('should generate bash completion script', () => { + const result = generateCompletion(testSpec, 'bash'); + + expect(result.success).toBe(true); + expect(result.script).toBeDefined(); + expect(result.script).toContain('test-cli'); + expect(result.script).toContain('start'); + expect(result.script).toContain('stop'); + }); + }); + + describe('zsh completion', () => { + it('should generate zsh completion script', () => { + const result = generateCompletion(testSpec, 'zsh'); + + expect(result.success).toBe(true); + expect(result.script).toBeDefined(); + expect(result.script).toContain('test-cli'); + }); + }); + + describe('fish completion', () => { + it('should generate fish completion script', () => { + const result = generateCompletion(testSpec, 'fish'); + + expect(result.success).toBe(true); + expect(result.script).toBeDefined(); + expect(result.script).toContain('test-cli'); + }); + }); + + describe('file naming', () => { + it('should return correct completion file name', () => { + expect(getCompletionFileName(testSpec, 'bash')).toBe('_test-cli.bash'); + expect(getCompletionFileName(testSpec, 'zsh')).toBe('_test-cli.zsh'); + expect(getCompletionFileName(testSpec, 'fish')).toBe('_test-cli.fish'); + }); + }); +}); + +describe('Docs Generator', () => { + describe('man page', () => { + it('should generate man page', () => { + const result = generateManPage(testSpec); + + expect(result.success).toBe(true); + expect(result.content).toBeDefined(); + expect(result.content).toContain('test-cli'); + expect(result.content).toContain('1'); + expect(result.content).toContain('start'); + expect(result.content).toContain('stop'); + }); + }); + + describe('README section', () => { + it('should generate README section', () => { + const result = generateReadmeSection(testSpec); + + expect(result.success).toBe(true); + expect(result.content).toBeDefined(); + expect(result.content).toContain('test-cli'); + expect(result.content).toContain('## test-cli'); + expect(result.content).toContain('### Commands'); + }); + }); +});