diff --git a/src/action/Argument.winxed b/src/action/Argument.winxed index 9e7d5fbd..8fab2a8c 100644 --- a/src/action/Argument.winxed +++ b/src/action/Argument.winxed @@ -35,7 +35,7 @@ namespace Rosella { namespace Action function name(string name) { self.name = name; - self.position = -9999; + self.position = -1; } // Set the position of the Argument. It is now a positional argument, @@ -65,18 +65,10 @@ namespace Rosella { namespace Action var value = self.resolve_value(); if (self.name != null) named[self.name] = value; - else if (self.position != -9999) { - if (self.position >= 0) - pos[self.position] = value; - else - ${ push pos, value }; - } - else { - using Rosella.Error.invalid; - invalid("Rosella.Action.Argument.resolve_to", - "Method argument must be Named or Positional" - ); - } + else if (self.position >= 0) + pos[self.position] = value; + else + ${ push pos, value }; } // Get the actual value. This happens in a subclass. diff --git a/src/mockobject/expectation/With.winxed b/src/mockobject/expectation/With.winxed index acebd146..a57ffe56 100644 --- a/src/mockobject/expectation/With.winxed +++ b/src/mockobject/expectation/With.winxed @@ -40,7 +40,7 @@ namespace Rosella { namespace MockObject { namespace Expectation for (string name in named) { if (!(exists self.named_args[name])) return 0; - if (named[name] != self.named_args[named]) + if (named[name] != self.named_args[name]) return 0; } return 1; diff --git a/t/action/Action.t b/t/action/Action.t index 5a6716e5..784df9dc 100644 --- a/t/action/Action.t +++ b/t/action/Action.t @@ -12,11 +12,55 @@ class ActionTest { Assert::instance_of($action, Rosella::Action, "Is not an Action"); } - method test_prepare_args_empty() { - $!status.todo("Oh noes!"); + method prepare_args_empty() { my $action := Rosella::build(Rosella::Action, "foo", []); my @pos := []; my %named := {}; $action.prepare_args(@pos, %named); + Assert::equal(+@pos, 0); + Assert::equal(+%named, 0); + } + + method prepare_args_positional() { + my $action := Rosella::build(Rosella::Action, "foo", [ + Rosella::build(Rosella::Action::Argument::Instance, 5, :position(0)), + Rosella::build(Rosella::Action::Argument::Instance, "Test", :position(1)), + ]); + my @pos := []; + my %named := {}; + $action.prepare_args(@pos, %named); + Assert::equal(+@pos, 2); + Assert::equal(+%named, 0); + Assert::equal(@pos[0], 5); + Assert::equal(@pos[1], "Test"); + } + + method prepare_args_positional_skip() { + my $action := Rosella::build(Rosella::Action, "foo", [ + Rosella::build(Rosella::Action::Argument::Instance, 5, :position(0)), + Rosella::build(Rosella::Action::Argument::Instance, "Test", :position(2)), + ]); + my @pos := []; + my %named := {}; + $action.prepare_args(@pos, %named); + Assert::equal(+@pos, 3); + Assert::equal(+%named, 0); + Assert::equal(@pos[0], 5, 'pos[0]'); + Assert::not_defined(@pos[1], 'pos[1]'); + Assert::equal(@pos[2], "Test", 'pos[2]'); + } + + method prepare_args_named() { + my $action := Rosella::build(Rosella::Action, "foo", [ + Rosella::build(Rosella::Action::Argument::Instance, 5, :name("A")), + Rosella::build(Rosella::Action::Argument::Instance, "Test", :name("B")) + ]); + my @pos := []; + my %named := {}; + $action.prepare_args(@pos, %named); + Assert::equal(+@pos, 0); + Assert::equal(+%named, 2); + Assert::equal(%named{"A"}, 5); + Assert::equal(%named{"B"}, "Test"); } } diff --git a/t/action/Action/Method.t b/t/action/Action/Method.t index ce0229e7..8e73cfbe 100644 --- a/t/action/Action/Method.t +++ b/t/action/Action/Method.t @@ -1,13 +1,49 @@ INIT { pir::load_bytecode("rosella/test.pbc"); pir::load_bytecode("rosella/action.pbc"); + pir::load_bytecode("rosella/mockobject.pbc"); } Rosella::Test::test(ActionMethodTest); +class MyTargetType { method test() { } } + class ActionMethodTest { method test_BUILD() { - my $action := Rosella::build(Rosella::Action::Method, "test", []); + my $action := Rosella::build(Rosella::Action::Method, "test"); Assert::instance_of($action, Rosella::Action::Method, "Is not a Method"); } + + method execute() { + my $action := Rosella::build(Rosella::Action::Method, "test"); + my $mockfactory := Rosella::build(Rosella::MockObject::Factory); + my $controller := $mockfactory.create_typed(MyTargetType); + $controller.expect_method("test").once.with_no_args; + my $target := $controller.mock; + $action.execute($target); + $controller.verify; + } + + method execute_initializer() { + my $action := Rosella::build(Rosella::Action::Method, "test"); + my $mockfactory := Rosella::build(Rosella::MockObject::Factory); + my $controller := $mockfactory.create_typed(MyTargetType); + $controller.expect_method("test").once.with_no_args; + my $target := $controller.mock; + $action.execute_initializer($target, [], {}); + $controller.verify; + } + + method execute_initializer_args() { + my $action := Rosella::build(Rosella::Action::Method, "test"); + my $mockfactory := Rosella::build(Rosella::MockObject::Factory); + my $controller := $mockfactory.create_typed(MyTargetType); + $controller.expect_method("test").once.with_args(1, 2, 3, :foo("A"), :bar("B")); + my $target := $controller.mock; + my %named := {}; + %named{"foo"} := "A"; + %named{"bar"} := "B"; + $action.execute_initializer($target, [1, 2, 3], %named); + $controller.verify; + } } diff --git a/t/action/Argument.t b/t/action/Argument.t index 08f68ec4..878fc0b6 100644 --- a/t/action/Argument.t +++ b/t/action/Argument.t @@ -10,23 +10,25 @@ class Action::Argument::Test { my $arg := Rosella::build(Rosella::Action::Argument); } - method test_name() { - $!status.unimplemented("This"); - } - - method test_position() { - $!status.unimplemented("This"); - } - - method test_set_positioning() { - $!status.unimplemented("This"); + method test_setup_positioning_name() { + my $arg := Rosella::build(Rosella::Action::Argument); + $arg.setup_positioning(:name("Foo")); + my $name := $arg.name(); + my $pos := $arg.position(); + Assert::equal($name, "Foo"); + Assert::equal($pos, -1); } - method test_type() { - $!status.unimplemented("This"); + method test_setup_positioning_position() { + my $arg := Rosella::build(Rosella::Action::Argument); + $arg.setup_positioning(:position(7)); + my $name := $arg.name(); + my $pos := $arg.position(); + Assert::is_null($name); + Assert::equal($pos, 7); } - method test_resolve_to() { - $!status.unimplemented("This"); + method test_verify_all_arguments() { + $!status.unimplemented("Write a test for verify_all_arguments"); } } diff --git a/t/action/Argument/Instance.t b/t/action/Argument/Instance.t index 2b0a2729..a3e8454d 100644 --- a/t/action/Argument/Instance.t +++ b/t/action/Argument/Instance.t @@ -8,5 +8,12 @@ Rosella::Test::test(ActionArgInstanceTest); class ActionArgInstanceTest { method test_BUILD() { my $arg := Rosella::build(Rosella::Action::Argument::Instance, 1); + Assert::instance_of($arg, Rosella::Action::Argument::Instance); + } + + method resolve_value() { + my $arg := Rosella::build(Rosella::Action::Argument::Instance, 1); + my $value := $arg.resolve_value(); + Assert::equal($value, 1); } } diff --git a/t/action/Argument/ContainerResolver.t b/t/container/action_argument/ContainerResolver.t similarity index 90% rename from t/action/Argument/ContainerResolver.t rename to t/container/action_argument/ContainerResolver.t index 73d933cb..d713a031 100644 --- a/t/action/Argument/ContainerResolver.t +++ b/t/container/action_argument/ContainerResolver.t @@ -10,5 +10,6 @@ class ActionArgContainerResolverTest { method test_BUILD() { my $c := Rosella::build(Rosella::Container); my $arg := Rosella::build(Rosella::Action::Argument::ContainerResolver, $c, "String"); + $!status.unimplemented("Test this"); } }