-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion.test.ts
More file actions
84 lines (75 loc) · 2.73 KB
/
Copy pathcompletion.test.ts
File metadata and controls
84 lines (75 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { describe, expect, it } from 'vitest';
import type { Writable } from 'node:stream';
import {
completionScript,
isCompletionShell,
runCompletion,
COMPLETION_SHELLS,
} from './completion.js';
function collector(): { stream: Writable; text: () => string } {
let buf = '';
const stream = {
write: (s: string): boolean => {
buf += s;
return true;
},
} as unknown as Writable;
return { stream, text: () => buf };
}
describe('completionScript', () => {
it('bash script registers a completion function with flags + subcommands', () => {
const s = completionScript('bash');
expect(s).toContain('complete -F _deepcode deepcode');
expect(s).toContain('--model');
expect(s).toContain('doctor');
expect(s).toContain('-C');
});
it('zsh script uses compdef', () => {
const s = completionScript('zsh');
expect(s).toContain('#compdef deepcode');
expect(s).toContain('compdef _deepcode deepcode');
expect(s).toContain("'--effort'");
});
it('fish script registers completions per flag + subcommands', () => {
const s = completionScript('fish');
expect(s).toContain('complete -c deepcode -l model');
expect(s).toContain('complete -c deepcode -o C'); // the -C short flag
expect(s).toContain('completion'); // subcommand listed
});
it('COMPLETION_SHELLS lists the three supported shells', () => {
expect(COMPLETION_SHELLS).toEqual(['bash', 'zsh', 'fish']);
});
});
describe('isCompletionShell', () => {
it('accepts known shells, rejects others', () => {
expect(isCompletionShell('bash')).toBe(true);
expect(isCompletionShell('zsh')).toBe(true);
expect(isCompletionShell('fish')).toBe(true);
expect(isCompletionShell('powershell')).toBe(false);
expect(isCompletionShell(undefined)).toBe(false);
});
});
describe('runCompletion', () => {
it('writes the script and returns 0 for a known shell', () => {
const out = collector();
const err = collector();
const code = runCompletion(['bash'], { output: out.stream, errOutput: err.stream });
expect(code).toBe(0);
expect(out.text()).toContain('complete -F _deepcode deepcode');
expect(err.text()).toBe('');
});
it('returns 2 and a usage message for an unknown shell', () => {
const out = collector();
const err = collector();
const code = runCompletion(['powershell'], { output: out.stream, errOutput: err.stream });
expect(code).toBe(2);
expect(err.text()).toMatch(/Usage: deepcode completion/);
expect(out.text()).toBe('');
});
it('returns 2 when no shell argument is given', () => {
const out = collector();
const err = collector();
const code = runCompletion([], { output: out.stream, errOutput: err.stream });
expect(code).toBe(2);
});
});