Skip to content

Commit

Permalink
flesh out several tests for action library. Move ContainerResolver te…
Browse files Browse the repository at this point in the history
…st file (mostly stubbish) to the t/container folder
  • Loading branch information
Whiteknight committed Mar 31, 2011
1 parent e81c44c commit 3156f57
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 31 deletions.
18 changes: 5 additions & 13 deletions src/action/Argument.winxed
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/mockobject/expectation/With.winxed
Expand Up @@ -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;
Expand Down
48 changes: 46 additions & 2 deletions t/action/Action.t
Expand Up @@ -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");
}
}
38 changes: 37 additions & 1 deletion 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;
}
}
30 changes: 16 additions & 14 deletions t/action/Argument.t
Expand Up @@ -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");
}
}
7 changes: 7 additions & 0 deletions t/action/Argument/Instance.t
Expand Up @@ -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);
}
}
Expand Up @@ -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");
}
}

0 comments on commit 3156f57

Please sign in to comment.