turned simple moo-role test into a separate use case test file
[p5sagit/Package-Variant.git] / t / 20moo-param-role.t
diff --git a/t/20moo-param-role.t b/t/20moo-param-role.t
new file mode 100644 (file)
index 0000000..2b33250
--- /dev/null
@@ -0,0 +1,36 @@
+use strictures 1;
+use Test::More qw(no_plan);
+
+BEGIN {
+  package My::Role::OnOff;
+
+  use Package::Variant
+    importing => { 'Moo::Role' => [] },
+    subs => [ qw(has before after around) ];
+
+  sub make_variant {
+    my ($me, $into, %args) = @_;
+    my $name = $args{name};
+    has $name => (is => 'rw');
+    install "${name}_on" => sub { shift->$name(1); };
+    install "${name}_off" => sub { shift->$name(0); };
+  }
+  $INC{"My/Role/OnOff.pm"} = __FILE__;
+}
+
+BEGIN {
+  package LightSwitch;
+
+  use My::Role::OnOff;
+  use Moo;
+
+  with OnOff(name => 'lights');
+}
+
+my $lights = LightSwitch->new;
+
+is($lights->lights, undef, 'Initial state');
+is($lights->lights_on, 1, 'Turn on');
+is($lights->lights, 1, 'On');
+is($lights->lights_off, 0, 'Turn off');
+is($lights->lights, 0, 'Off');