Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / attributes / attribute_names.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Test::Fatal;
7
8 my $exception_regex = qr/You must provide a name for the attribute/;
9 {
10     package My::Role;
11     use Moose::Role;
12
13     ::like( ::exception {
14         has;
15     }, $exception_regex, 'has; fails' );
16
17     ::like( ::exception {
18         has undef;
19     }, $exception_regex, 'has undef; fails' );
20
21     ::is( ::exception {
22         has "" => (
23             is => 'bare',
24         );
25     }, undef, 'has ""; works now' );
26
27     ::is( ::exception {
28         has 0 => (
29             is => 'bare',
30         );
31     }, undef, 'has 0; works now' );
32 }
33
34 {
35     package My::Class;
36     use Moose;
37
38     ::like( ::exception {
39         has;
40     }, $exception_regex, 'has; fails' );
41
42     ::like( ::exception {
43         has undef;
44     }, $exception_regex, 'has undef; fails' );
45
46     ::is( ::exception {
47         has "" => (
48             is => 'bare',
49         );
50     }, undef, 'has ""; works now' );
51
52     ::is( ::exception {
53         has 0 => (
54             is => 'bare',
55         );
56     }, undef, 'has 0; works now' );
57 }
58
59 done_testing;