todo-app/test/cli/cli_args_test.dart
Krzysztof kuhy Rudnicki 56cb1b3594
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Add headless note CLI (bin/todo_note.dart) reusing app CRDT sync
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-16 15:35:46 +02:00

81 lines
2.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:todo/cli/cli_args.dart';
import 'package:todo/data/note.dart';
void main() {
group('CliArgs.parse', () {
test('no arguments means add with defaults', () {
final args = CliArgs.parse([]);
expect(args.mode, CliMode.add);
expect(args.text, isNull);
expect(args.priority, Priority.medium);
expect(args.status, Status.todo);
expect(args.dataDir, isNull);
});
test('reads every add option', () {
final args = CliArgs.parse([
'--text',
'Title',
'--priority',
'high',
'--status',
'in_progress',
'--data-dir',
'/tmp/x',
]);
expect(args.mode, CliMode.add);
expect(args.text, 'Title');
expect(args.priority, Priority.high);
expect(args.status, Status.inProgress);
expect(args.dataDir, '/tmp/x');
});
test('accepts plain status names', () {
expect(CliArgs.parse(['--status', 'done']).status, Status.done);
});
test('selects list, get and delete', () {
expect(CliArgs.parse(['--list']).mode, CliMode.list);
final get = CliArgs.parse(['--get', 'abc']);
expect(get.mode, CliMode.get);
expect(get.id, 'abc');
final del = CliArgs.parse(['--delete', 'xyz']);
expect(del.mode, CliMode.delete);
expect(del.id, 'xyz');
});
test('help wins over everything else', () {
expect(CliArgs.parse(['--list', '-h']).mode, CliMode.help);
expect(CliArgs.parse(['--help']).mode, CliMode.help);
});
test('rejects malformed command lines', () {
void expectUsage(List<String> argv, String fragment) {
expect(
() => CliArgs.parse(argv),
throwsA(
isA<UsageError>().having(
(e) => e.toString(),
'message',
contains(fragment),
),
),
);
}
expectUsage(['--text'], '--text needs a value');
expectUsage(['--bogus'], 'unknown argument: --bogus');
expectUsage(['--priority', 'urgent'], 'low|medium|high');
expectUsage(['--status', 'inProgress'], 'todo|in_progress|done');
expectUsage(['--list', '--get', 'a'], 'mutually exclusive');
expectUsage(['--list', '--text', 'x'], 'only applies when adding');
});
});
test('statusName spells inProgress with an underscore', () {
expect(CliArgs.statusName(Status.inProgress), 'in_progress');
expect(CliArgs.statusName(Status.abandoned), 'abandoned');
});
}