feat: Screwdriver v1.0.0
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { translateCommand, getAllCommands } from '../src/utils/command-translator.js'
|
||||
|
||||
describe('command-translator', () => {
|
||||
it('translates simple commands', () => {
|
||||
const r = translateCommand('list files')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.command).toBe('ls -la')
|
||||
})
|
||||
|
||||
it('translates git commands', () => {
|
||||
const r = translateCommand('git status')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.command).toBe('git status')
|
||||
})
|
||||
|
||||
it('marks dangerous commands', () => {
|
||||
const r = translateCommand('remove directory')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.dangerous).toBe(true)
|
||||
})
|
||||
|
||||
it('handles unknown input gracefully', () => {
|
||||
const r = translateCommand('xyz')
|
||||
expect(r.success).toBe(false)
|
||||
})
|
||||
|
||||
it('handles empty input', () => {
|
||||
const r = translateCommand('')
|
||||
expect(r.success).toBe(false)
|
||||
expect(r.error).toBe('Empty input')
|
||||
})
|
||||
|
||||
it('has a command catalog', () => {
|
||||
const cmds = getAllCommands()
|
||||
expect(cmds.length).toBeGreaterThan(20)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { parseConflicts, resolveConflicts } from '../src/utils/git-conflict-resolver.js'
|
||||
|
||||
const CONFLICT_TEXT = `import { foo } from './foo'
|
||||
<<<<<<< HEAD
|
||||
const x = 1
|
||||
=======
|
||||
const x = 2
|
||||
>>>>>>> feature
|
||||
export { x }`
|
||||
|
||||
describe('git-conflict-resolver', () => {
|
||||
it('parses conflicts', () => {
|
||||
const conflicts = parseConflicts(CONFLICT_TEXT)
|
||||
expect(conflicts.length).toBe(1)
|
||||
expect(conflicts[0].ours).toBe('const x = 1')
|
||||
expect(conflicts[0].theirs).toBe('const x = 2')
|
||||
expect(conflicts[0].header).toBe('HEAD')
|
||||
})
|
||||
|
||||
it('auto-resolves with ours strategy', () => {
|
||||
const result = resolveConflicts(CONFLICT_TEXT, 'ours')
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.resolution).toContain('const x = 1')
|
||||
expect(result.resolution).not.toContain('<<<<<<<')
|
||||
})
|
||||
|
||||
it('auto-resolves with theirs strategy', () => {
|
||||
const result = resolveConflicts(CONFLICT_TEXT, 'theirs')
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.resolution).toContain('const x = 2')
|
||||
})
|
||||
|
||||
it('detects no conflicts', () => {
|
||||
const result = resolveConflicts('no conflict here')
|
||||
expect(result.success).toBe(false)
|
||||
expect(result.explanation).toContain('No git conflict markers')
|
||||
})
|
||||
|
||||
it('handles multiple conflicts', () => {
|
||||
const multi = `${CONFLICT_TEXT}\n\n${CONFLICT_TEXT.replace('x', 'y')}`
|
||||
const result = resolveConflicts(multi, 'ours')
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.conflictCount).toBe(2)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { testRegex, explainRegex } from '../src/utils/regex-tester.js'
|
||||
|
||||
describe('regex-tester', () => {
|
||||
it('finds simple matches', () => {
|
||||
const result = testRegex({ pattern: '\\d+', flags: 'g', text: 'abc 123 def 456' })
|
||||
expect(result.valid).toBe(true)
|
||||
expect(result.matches.length).toBe(2)
|
||||
expect(result.matches[0].full).toBe('123')
|
||||
expect(result.matches[1].full).toBe('456')
|
||||
})
|
||||
|
||||
it('captures groups', () => {
|
||||
const result = testRegex({ pattern: '(\\w+)=(\\d+)', flags: 'g', text: 'a=1,b=2' })
|
||||
expect(result.valid).toBe(true)
|
||||
expect(result.matches[0].groups).toEqual(['a', '1'])
|
||||
})
|
||||
|
||||
it('reports invalid regex', () => {
|
||||
const result = testRegex({ pattern: '[', flags: '', text: 'test' })
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.error).toBeDefined()
|
||||
})
|
||||
|
||||
it('shows replace preview', () => {
|
||||
const result = testRegex({
|
||||
pattern: '\\d+',
|
||||
flags: 'g',
|
||||
text: 'abc 123',
|
||||
replacement: 'XXX',
|
||||
})
|
||||
expect(result.replacePreview).toBe('abc XXX')
|
||||
})
|
||||
|
||||
it('explains patterns', () => {
|
||||
const exp = explainRegex('\\d+')
|
||||
expect(exp).toContain('\\d')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { transformText, TRANSFORM_OPTIONS } from '../src/utils/text-transformer.js'
|
||||
|
||||
describe('text-transformer', () => {
|
||||
it('converts to uppercase', () => {
|
||||
const r = transformText('hello world', 'uppercase')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toBe('HELLO WORLD')
|
||||
})
|
||||
|
||||
it('converts to camelCase', () => {
|
||||
const r = transformText('hello world', 'camelcase')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toBe('helloWorld')
|
||||
})
|
||||
|
||||
it('base64 encodes', () => {
|
||||
const r = transformText('hello', 'base64encode')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toBe('aGVsbG8=')
|
||||
})
|
||||
|
||||
it('base64 decodes', () => {
|
||||
const r = transformText('aGVsbG8=', 'base64decode')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toBe('hello')
|
||||
})
|
||||
|
||||
it('formats JSON', () => {
|
||||
const r = transformText('{"a":1}', 'jsonpretty')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toContain('"a": 1')
|
||||
})
|
||||
|
||||
it('minifies JSON', () => {
|
||||
const r = transformText('{\n "a": 1\n}', 'jsoncompact')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toBe('{"a":1}')
|
||||
})
|
||||
|
||||
it('sorts lines', () => {
|
||||
const r = transformText('c\nb\na', 'sortlines')
|
||||
expect(r.success).toBe(true)
|
||||
expect(r.result).toBe('a\nb\nc')
|
||||
})
|
||||
|
||||
it('has transform options', () => {
|
||||
expect(TRANSFORM_OPTIONS.length).toBeGreaterThan(10)
|
||||
})
|
||||
|
||||
it('handles invalid JSON', () => {
|
||||
const r = transformText('not json', 'jsonpretty')
|
||||
expect(r.success).toBe(false)
|
||||
expect(r.error).toBeDefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user