| 1 | use lib 't/lib'; |
| 2 | use Test::More; |
| 3 | use TidierTests; |
| 4 | |
| 5 | run_test( <<'RAW', <<'TIDIED', 'Simple class defn', '', ); |
| 6 | class Person { |
| 7 | has 'name' => (is => 'rw'); |
| 8 | } |
| 9 | RAW |
| 10 | class Person { |
| 11 | has 'name' => ( is => 'rw' ); |
| 12 | } |
| 13 | TIDIED |
| 14 | |
| 15 | run_test( <<'RAW', <<'TIDIED', 'Class defn with Moose', '', ); |
| 16 | class Person using Moose { |
| 17 | has 'name' => ( is => 'rw' ); |
| 18 | } |
| 19 | RAW |
| 20 | class Person using Moose { |
| 21 | has 'name' => ( is => 'rw' ); |
| 22 | } |
| 23 | TIDIED |
| 24 | |
| 25 | run_test( <<'RAW', <<'TIDIED', 'Class defn with version ', '', ); |
| 26 | class Person 1.2 { |
| 27 | has 'name' => ( is => 'rw' ); |
| 28 | } |
| 29 | RAW |
| 30 | class Person 1.2 { |
| 31 | has 'name' => ( is => 'rw' ); |
| 32 | } |
| 33 | TIDIED |
| 34 | |
| 35 | run_test( <<'RAW', <<'TIDIED', 'Role defn', '', ); |
| 36 | role NamedThing { |
| 37 | has 'balance' => ( is => 'rw' ); |
| 38 | } |
| 39 | RAW |
| 40 | role NamedThing { |
| 41 | has 'balance' => ( is => 'rw' ); |
| 42 | } |
| 43 | TIDIED |
| 44 | |
| 45 | run_test( <<'RAW', <<'TIDIED', 'Class with role', '', ); |
| 46 | class Person with NamedThing; |
| 47 | RAW |
| 48 | class Person with NamedThing; |
| 49 | TIDIED |
| 50 | |
| 51 | run_test( <<'RAW', <<'TIDIED', 'Class that extends another', '', ); |
| 52 | class Employee extends Person { |
| 53 | has job_title => (is=>'ro'); |
| 54 | } |
| 55 | RAW |
| 56 | class Employee extends Person { |
| 57 | has job_title => ( is => 'ro' ); |
| 58 | } |
| 59 | TIDIED |
| 60 | |
| 61 | run_test( <<'RAW', <<'TIDIED', 'Class that extends another with ::', '', ); |
| 62 | class Employee extends Person::Object { |
| 63 | has job_title => (is=>'ro'); |
| 64 | } |
| 65 | RAW |
| 66 | class Employee extends Person::Object { |
| 67 | has job_title => ( is => 'ro' ); |
| 68 | } |
| 69 | TIDIED |
| 70 | |
| 71 | run_test( <<'RAW', <<'TIDIED', 'Class that extends and role', '', ); |
| 72 | class Employee extends Person with Employment { |
| 73 | has job_title => (is=>'ro'); |
| 74 | } |
| 75 | RAW |
| 76 | class Employee extends Person with Employment { |
| 77 | has job_title => ( is => 'ro' ); |
| 78 | } |
| 79 | TIDIED |
| 80 | |
| 81 | run_test( <<'RAW', <<'TIDIED', 'Class with lexical_has', '', ); |
| 82 | class Employee extends Person { |
| 83 | lexical_has job_title => (is=>'ro'); |
| 84 | } |
| 85 | RAW |
| 86 | class Employee extends Person { |
| 87 | lexical_has job_title => ( is => 'ro' ); |
| 88 | } |
| 89 | TIDIED |
| 90 | |
| 91 | run_test( <<'RAW', <<'TIDIED', 'Class defn with method', '', ); |
| 92 | class BankAccount { |
| 93 | has 'balance' => ( is => 'rw' ); |
| 94 | method deposit (Num $amount){ |
| 95 | $self->inc_balance( $amount ); |
| 96 | } |
| 97 | } |
| 98 | RAW |
| 99 | class BankAccount { |
| 100 | has 'balance' => ( is => 'rw' ); |
| 101 | |
| 102 | method deposit (Num $amount) { |
| 103 | $self->inc_balance($amount); |
| 104 | } |
| 105 | } |
| 106 | TIDIED |
| 107 | |
| 108 | run_test( <<'RAW', <<'TIDIED', 'Class with attribute', '', ); |
| 109 | class Person :mutable { |
| 110 | lexical_has job_title => (is=>'ro'); |
| 111 | } |
| 112 | RAW |
| 113 | class Person :mutable { |
| 114 | lexical_has job_title => ( is => 'ro' ); |
| 115 | } |
| 116 | TIDIED |
| 117 | |
| 118 | done_testing; |