48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
|
|
import { describe, it, expect } from 'vitest'
|
||
|
|
import { buildArgs } from '../lib/converters.js'
|
||
|
|
|
||
|
|
describe('buildArgs', () => {
|
||
|
|
it('returns empty array for empty flags', () => {
|
||
|
|
expect(buildArgs('chafa', {})).toEqual([])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('maps value flags to --key value pairs', () => {
|
||
|
|
expect(buildArgs('chafa', { size: '80x40' })).toEqual(['--size', '80x40'])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('includes bool flag only when true', () => {
|
||
|
|
expect(buildArgs('ascii-image-converter', { color: true })).toContain('--color')
|
||
|
|
expect(buildArgs('ascii-image-converter', { color: false })).not.toContain('--color')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('rejects unknown flags', () => {
|
||
|
|
expect(() => buildArgs('chafa', { evil: 'value' })).toThrow('Unknown flag')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('rejects invalid enum values', () => {
|
||
|
|
expect(() => buildArgs('chafa', { colors: 'invalid' })).toThrow('Invalid value')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('accepts valid enum values', () => {
|
||
|
|
expect(() => buildArgs('chafa', { colors: '256' })).not.toThrow()
|
||
|
|
expect(() => buildArgs('chafa', { colors: '16/8' })).not.toThrow()
|
||
|
|
expect(() => buildArgs('chafa', { dither: 'noise' })).not.toThrow()
|
||
|
|
expect(() => buildArgs('jp2a', { background: 'dark' })).not.toThrow()
|
||
|
|
expect(() => buildArgs('img2txt', { format: 'ansi' })).not.toThrow()
|
||
|
|
})
|
||
|
|
|
||
|
|
it('throws on unknown tool', () => {
|
||
|
|
expect(() => buildArgs('malicious-tool', {})).toThrow('Unknown tool')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('stringifies numeric values', () => {
|
||
|
|
const args = buildArgs('chafa', { size: 80 })
|
||
|
|
expect(args).toEqual(['--size', '80'])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('handles font-ratio hyphenated key', () => {
|
||
|
|
const args = buildArgs('chafa', { 'font-ratio': '0.5' })
|
||
|
|
expect(args).toEqual(['--font-ratio', '0.5'])
|
||
|
|
})
|
||
|
|
})
|