X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F300_immutable%2F012_default_values.t;fp=t%2F300_immutable%2F012_default_values.t;h=aca9bf8220dfc948312fff97b9ffae9dd22da389;hb=16504b1548c2c3b2570a46b1864287f50d49faf2;hp=0000000000000000000000000000000000000000;hpb=ee5e6a034b6aeaed7819138193288eb249d9380b;p=gitmo%2FMouse.git diff --git a/t/300_immutable/012_default_values.t b/t/300_immutable/012_default_values.t new file mode 100644 index 0000000..aca9bf8 --- /dev/null +++ b/t/300_immutable/012_default_values.t @@ -0,0 +1,69 @@ +#!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; + +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +{ + + package Foo; + use Mouse; + + has 'foo' => ( is => 'rw', default => q{'} ); + has 'bar' => ( is => 'rw', default => q{\\} ); + has 'baz' => ( is => 'rw', default => q{"} ); + has 'buz' => ( is => 'rw', default => q{"'\\} ); + has 'faz' => ( is => 'rw', default => qq{\0} ); + + ::lives_ok { __PACKAGE__->meta->make_immutable } + 'no errors making a package immutable when it has default values that could break quoting'; +} + +my $foo = Foo->new; +is( $foo->foo, q{'}, + 'default value for foo attr' ); +is( $foo->bar, q{\\}, + 'default value for bar attr' ); +is( $foo->baz, q{"}, + 'default value for baz attr' ); +is( $foo->buz, q{"'\\}, + 'default value for buz attr' ); +is( $foo->faz, qq{\0}, + 'default value for faz attr' ); + + +# Lazy attrs were never broken, but it doesn't hurt to test that they +# won't be broken by any future changes. +{ + + package Bar; + use Mouse; + + has 'foo' => ( is => 'rw', default => q{'}, lazy => 1 ); + has 'bar' => ( is => 'rw', default => q{\\}, lazy => 1 ); + has 'baz' => ( is => 'rw', default => q{"}, lazy => 1 ); + has 'buz' => ( is => 'rw', default => q{"'\\}, lazy => 1 ); + has 'faz' => ( is => 'rw', default => qq{\0}, lazy => 1 ); + + ::lives_ok { __PACKAGE__->meta->make_immutable } + 'no errors making a package immutable when it has lazy default values that could break quoting'; +} + +my $bar = Bar->new; +is( $bar->foo, q{'}, + 'default value for foo attr' ); +is( $bar->bar, q{\\}, + 'default value for bar attr' ); +is( $bar->baz, q{"}, + 'default value for baz attr' ); +is( $bar->buz, q{"'\\}, + 'default value for buz attr' ); +is( $bar->faz, qq{\0}, + 'default value for faz attr' ); + +done_testing;