Skip to content

Commit

Permalink
Fix invalid parsing ot TaskName.get and test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
buijs-dev committed Nov 13, 2023
1 parent ae770c4 commit f73929c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/cli/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Command {

if (script == ScriptName.consumer) {
if (taskName == TaskName.init) {
if (arguments.isEmpty) {
if (args.isEmpty) {
return Command(taskName: taskName, scriptName: script);
} else {
return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cli/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension TaskNameParser on String? {
case "ADD":
return TaskName.add;
case "GET":
return TaskName.init;
return TaskName.get;
case "INIT":
return TaskName.init;
default:
Expand Down
98 changes: 98 additions & 0 deletions test/src/cli/command_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) 2021 - 2023 Buijs Software
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import "package:klutter/klutter.dart";
import "package:test/test.dart";

void main() {
test("Verify parsing consumer init command", () {
final command = Command.from(
script: ScriptName.consumer,
arguments: ["init"]);

expect(command != null, true, reason: "command should not be null");
expect(command!.scriptName, ScriptName.consumer);
expect(command.taskName, TaskName.init);
});

test("Verify parsing get flutte command", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["get", "flutter=3.10.6.macos.x64"]);

expect(command != null, true);
});

test("When more than 2 arguments are supplied then command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["init", "bom=2023.1.1.beta", "flutter=3.10.6.macos.arm64", "x=y"]);

expect(command == null, true, reason: "command should be null because too many arguments");
});

test("When an argument has more than one '=' then command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["init", "bom=2023.1.1.beta=woot", "flutter=3.10.6.macos.arm64",]);

expect(command == null, true, reason: "command should be null argument is invalid");
});

test("When an argument is not a valid option value then command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["init", "woot=2023.1.1.beta", "flutter=3.10.6.macos.arm64",]);

expect(command == null, true, reason: "command should be null because argument is invalid");
});

test("When get command has more than 1 argument, command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["get", "this", "and" ]);

expect(command == null, true, reason: "command should be null because get can only have one argument");
});

test("When get command option is invalid, command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["get", "flutter=this=that"]);

expect(command, null);
});

test("When get command option is not named flutter, command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["get", "not=flutter"]);

expect(command, null);
});

test("When get command option flutter is not a valid version, command is null", () {
final command = Command.from(
script: ScriptName.producer,
arguments: ["get", "flutter=not.really.flutterrrr"]);

expect(command, null);
});
}

0 comments on commit f73929c

Please sign in to comment.