| 1 | use lib 't/lib'; |
| 2 | use Test::More; |
| 3 | use TidierTests qw(run_test $indent_tc); |
| 4 | |
| 5 | run_test( <<'RAW', <<'TIDIED', 'Simple method usage', '', ); |
| 6 | method name1{ |
| 7 | } |
| 8 | sub name2{ |
| 9 | } |
| 10 | RAW |
| 11 | method name1 { |
| 12 | } |
| 13 | |
| 14 | sub name2 { |
| 15 | } |
| 16 | TIDIED |
| 17 | |
| 18 | run_test( <<'RAW', <<'TIDIED', 'Simple methods with underscores ', '', ); |
| 19 | method name_1{ |
| 20 | } |
| 21 | RAW |
| 22 | method name_1 { |
| 23 | } |
| 24 | TIDIED |
| 25 | |
| 26 | run_test( <<'RAW', <<'TIDIED', 'Method with signature', '', ); |
| 27 | method name1 (class: $that) { |
| 28 | } |
| 29 | method name2( :$arg1, :$arg2 ){ |
| 30 | } |
| 31 | sub name3 {} |
| 32 | RAW |
| 33 | method name1 (class: $that) { |
| 34 | } |
| 35 | |
| 36 | method name2 ( :$arg1, :$arg2 ) { |
| 37 | } |
| 38 | sub name3 { } |
| 39 | TIDIED |
| 40 | |
| 41 | run_test( <<'RAW', <<'TIDIED', 'Simple classmethod usage', '', ); |
| 42 | classmethod name1{ |
| 43 | } |
| 44 | sub name2{ |
| 45 | } |
| 46 | RAW |
| 47 | classmethod name1 { |
| 48 | } |
| 49 | |
| 50 | sub name2 { |
| 51 | } |
| 52 | TIDIED |
| 53 | |
| 54 | run_test( <<'RAW', <<'TIDIED', 'Simple classmethods with underscores ', '', ); |
| 55 | classmethod name_1{ |
| 56 | } |
| 57 | RAW |
| 58 | classmethod name_1 { |
| 59 | } |
| 60 | TIDIED |
| 61 | |
| 62 | run_test( <<'RAW', <<'TIDIED', 'classmethod with signature', '', ); |
| 63 | classmethod name1 (class: $that) { |
| 64 | } |
| 65 | classmethod name2( :$arg1, :$arg2 ){ |
| 66 | } |
| 67 | sub name3 {} |
| 68 | RAW |
| 69 | classmethod name1 (class: $that) { |
| 70 | } |
| 71 | |
| 72 | classmethod name2 ( :$arg1, :$arg2 ) { |
| 73 | } |
| 74 | sub name3 { } |
| 75 | TIDIED |
| 76 | |
| 77 | run_test( <<'RAW', <<'TIDIED', 'Simple objectmethod usage', '', ); |
| 78 | objectmethod name1{ |
| 79 | } |
| 80 | sub name2{ |
| 81 | } |
| 82 | RAW |
| 83 | objectmethod name1 { |
| 84 | } |
| 85 | |
| 86 | sub name2 { |
| 87 | } |
| 88 | TIDIED |
| 89 | |
| 90 | run_test( <<'RAW', <<'TIDIED', 'Simple objectmethods with underscores ', '', ); |
| 91 | objectmethod name_1{ |
| 92 | } |
| 93 | RAW |
| 94 | objectmethod name_1 { |
| 95 | } |
| 96 | TIDIED |
| 97 | |
| 98 | run_test( <<'RAW', <<'TIDIED', 'objectmethod with signature', '', ); |
| 99 | objectmethod name1 (class: $that) { |
| 100 | } |
| 101 | objectmethod name2( :$arg1, :$arg2 ){ |
| 102 | } |
| 103 | sub name3 {} |
| 104 | RAW |
| 105 | objectmethod name1 (class: $that) { |
| 106 | } |
| 107 | |
| 108 | objectmethod name2 ( :$arg1, :$arg2 ) { |
| 109 | } |
| 110 | sub name3 { } |
| 111 | TIDIED |
| 112 | |
| 113 | run_test( <<'RAW', <<'TIDIED', 'Functions', '', ); |
| 114 | fun morning ($name) { |
| 115 | say "Hi $name"; |
| 116 | } |
| 117 | RAW |
| 118 | fun morning ($name) { |
| 119 | say "Hi $name"; |
| 120 | } |
| 121 | TIDIED |
| 122 | |
| 123 | run_test( <<'RAW', <<'TIDIED', 'Functions with underscore in name', '', ); |
| 124 | fun morn_ing ($name) { |
| 125 | say "Hi $name"; |
| 126 | } |
| 127 | RAW |
| 128 | fun morn_ing ($name) { |
| 129 | say "Hi $name"; |
| 130 | } |
| 131 | TIDIED |
| 132 | |
| 133 | run_test( <<'RAW', <<'TIDIED', 'Functions with multi-line paramaters', '', ); |
| 134 | fun morning ( Str :$name, |
| 135 | Int :$age, |
| 136 | ) { |
| 137 | say "Hi $name"; |
| 138 | } |
| 139 | RAW |
| 140 | fun morning ( Str :$name, |
| 141 | Int :$age, |
| 142 | ) { |
| 143 | say "Hi $name"; |
| 144 | } |
| 145 | TIDIED |
| 146 | |
| 147 | run_test( <<'RAW', <<"TIDIED", 'With trailing comments', '', ); |
| 148 | method name1{# Trailing comment |
| 149 | } |
| 150 | sub name2{ # Trailing comment |
| 151 | } |
| 152 | RAW |
| 153 | method name1 { # Trailing comment |
| 154 | } |
| 155 | |
| 156 | sub name2 {$indent_tc# Trailing comment |
| 157 | } |
| 158 | TIDIED |
| 159 | |
| 160 | run_test( <<'RAW', <<"TIDIED", 'With attribs trailing comments', '', ); |
| 161 | method name1 :Attrib(Arg) {# comment |
| 162 | } |
| 163 | sub name2 :Attrib(Arg) { # comment |
| 164 | } |
| 165 | RAW |
| 166 | method name1 :Attrib(Arg) { # comment |
| 167 | } |
| 168 | |
| 169 | sub name2 : Attrib(Arg) {$indent_tc# comment |
| 170 | } |
| 171 | TIDIED |
| 172 | |
| 173 | run_test( <<'RAW', <<'TIDIED', 'but begin', '', ); |
| 174 | method foo () but begin { 'bar' } |
| 175 | RAW |
| 176 | method foo () but begin { 'bar' } |
| 177 | TIDIED |
| 178 | |
| 179 | run_test( <<'RAW', <<'TIDIED', 'around modifiers', '', ); |
| 180 | around foo(Str :$bar, Str :$baz?) { |
| 181 | say "hi"; |
| 182 | } |
| 183 | RAW |
| 184 | around foo (Str :$bar, Str :$baz?) { |
| 185 | say "hi"; |
| 186 | } |
| 187 | TIDIED |
| 188 | |
| 189 | run_test( <<'RAW', <<'TIDIED', 'before modifiers', '', ); |
| 190 | before foo(Str :$bar, Str :$baz?) { |
| 191 | say "hi"; |
| 192 | } |
| 193 | RAW |
| 194 | before foo (Str :$bar, Str :$baz?) { |
| 195 | say "hi"; |
| 196 | } |
| 197 | TIDIED |
| 198 | |
| 199 | run_test( <<'RAW', <<'TIDIED', 'after modifiers', '', ); |
| 200 | after foo(Str :$bar, Str :$baz?) { |
| 201 | say "hi"; |
| 202 | } |
| 203 | RAW |
| 204 | after foo (Str :$bar, Str :$baz?) { |
| 205 | say "hi"; |
| 206 | } |
| 207 | TIDIED |
| 208 | |
| 209 | done_testing; |