-
Notifications
You must be signed in to change notification settings - Fork 4
/
Action.t
66 lines (60 loc) · 2.23 KB
/
Action.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
INIT {
pir::load_bytecode("rosella/core.pbc");
pir::load_bytecode("rosella/test.pbc");
pir::load_bytecode("rosella/action.pbc");
}
Rosella::Test::test(ActionTest);
class ActionTest {
method test_BUILD() {
my $action := Rosella::build(Rosella::Action, "foo", []);
Assert::instance_of($action, Rosella::Action, "Is not an Action");
}
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");
}
}