working lazy default and builder
[gitmo/Moo.git] / t / accessor-default.t
diff --git a/t/accessor-default.t b/t/accessor-default.t
new file mode 100644 (file)
index 0000000..af6e448
--- /dev/null
@@ -0,0 +1,30 @@
+use strictures 1;
+use Test::More;
+
+{
+  package Foo;
+
+  use Sub::Quote;
+  use Class::Tiny;
+
+  has one => (is => 'ro', lazy => 1, default => quote_sub q{ {} });
+  has two => (is => 'ro', lazy => 1, builder => '_build_two');
+  sub _build_two { {} }
+  has three => (is => 'ro', default => quote_sub q{ {} });
+  has four => (is => 'ro', default => '_build_four');
+  sub _build_four { {} }
+}
+
+sub check {
+  my ($attr, @h) = @_;
+
+  is_deeply($h[$_], {}, "${attr}: empty hashref \$h[$_]") for 0..1;
+
+  isnt($h[0],$h[1], "${attr}: not the same hashref");
+}
+
+check one => map Foo->new->one, 1..2;
+
+check two => map Foo->new->two, 1..2;
+
+done_testing;