Add testsuite for argument parser
This commit is contained in:
parent
7d045bd49f
commit
6d87807863
4 changed files with 45 additions and 4 deletions
|
@ -18,10 +18,10 @@ class CLIHelper {
|
|||
|
||||
Argument arg = defaults.getArg(name)!;
|
||||
if (arg.hasValue) {
|
||||
builder.append("=<T>");
|
||||
builder.append("=<...>");
|
||||
}
|
||||
|
||||
builder.append("\t\t\t${arg.description}\n");
|
||||
builder.append("\t\t\t${arg.description} [Default: ${arg.getValue()}]\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
|
|
|
@ -3,7 +3,8 @@ import 'package:libac_dart/argparse/Args.dart';
|
|||
class StringArgument extends Argument<String> {
|
||||
final String value;
|
||||
|
||||
StringArgument({required super.name, required this.value}) {
|
||||
StringArgument(
|
||||
{required super.name, required this.value, super.description}) {
|
||||
hasValue = value.isNotEmpty;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: libac_dart
|
||||
description: "Aria's Creations code library"
|
||||
version: 1.1.070224+2109
|
||||
version: 1.1.070224+2222
|
||||
homepage: "https://zontreck.com"
|
||||
|
||||
|
||||
|
|
40
test/args_test.dart
Normal file
40
test/args_test.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
import 'package:libac_dart/argparse/Args.dart';
|
||||
import 'package:libac_dart/argparse/Builder.dart';
|
||||
import 'package:libac_dart/argparse/CLIHelper.dart';
|
||||
import 'package:libac_dart/argparse/types/Bool.dart';
|
||||
import 'package:libac_dart/argparse/types/String.dart';
|
||||
import 'package:test/expect.dart';
|
||||
import 'package:test/scaffolding.dart';
|
||||
|
||||
void main() {
|
||||
test("Test parsing a argument", () async {
|
||||
List<String> testArgs = ["--test=12", "--enable", "--put=\"Here\""];
|
||||
|
||||
Arguments defaults = Arguments();
|
||||
|
||||
Arguments parsed = await CLIHelper.parseArgs(testArgs, defaults);
|
||||
|
||||
expect(true, parsed.hasArg("test"));
|
||||
expect(12, parsed.getArg("test")!.getValue() as int);
|
||||
expect(ArgumentType.INTEGER, parsed.getArg("test")!.getType());
|
||||
|
||||
expect(true, parsed.hasArg("enable"));
|
||||
expect(ArgumentType.BOOL, parsed.getArg("enable")!.getType());
|
||||
|
||||
expect("Here", parsed.getArg("put")!.getValue() as String);
|
||||
});
|
||||
|
||||
test("Test printing Usage", () async {
|
||||
Arguments testArgs = ArgumentsBuilder.builder()
|
||||
.withArgument(BoolArgument(
|
||||
name: "use_legacy", description: "Uses legacy settings"))
|
||||
.withArgument(StringArgument(
|
||||
name: "output",
|
||||
value: "./out",
|
||||
description: "Where to put the output files"))
|
||||
.build();
|
||||
|
||||
String usage = CLIHelper.makeArgCLIHelp(testArgs);
|
||||
print("LibAC_Dart\nTestsuite - 1.0\n\n${usage}");
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue