| 1 | // vfmt off |
| 2 | @[deprecated('use NewPositional instead')] |
| 3 | struct OldPositional {} |
| 4 | |
| 5 | @[deprecated(msg: 'use NewNamed instead', after: '2999-01-01')] |
| 6 | struct OldNamed {} |
| 7 | |
| 8 | @[deprecated('use NewMixed instead', after: '2999-01-02')] |
| 9 | struct OldMixed {} |
| 10 | |
| 11 | @[custom(flag: true, count: 2)] |
| 12 | struct CustomNamed {} |
| 13 | // vfmt on |
| 14 | |
| 15 | fn test_attribute_call_syntax_positional_and_named_args() { |
| 16 | mut positional_msg := '' |
| 17 | $for attr in OldPositional.attributes { |
| 18 | if attr.name == 'deprecated' { |
| 19 | positional_msg = attr.arg |
| 20 | } |
| 21 | } |
| 22 | assert positional_msg == 'use NewPositional instead' |
| 23 | |
| 24 | mut named_msg := '' |
| 25 | mut named_after := '' |
| 26 | $for attr in OldNamed.attributes { |
| 27 | if attr.name == 'deprecated' { |
| 28 | named_msg = attr.arg |
| 29 | } |
| 30 | if attr.name == 'deprecated_after' { |
| 31 | named_after = attr.arg |
| 32 | } |
| 33 | } |
| 34 | assert named_msg == 'use NewNamed instead' |
| 35 | assert named_after == '2999-01-01' |
| 36 | |
| 37 | mut mixed_msg := '' |
| 38 | mut mixed_after := '' |
| 39 | $for attr in OldMixed.attributes { |
| 40 | if attr.name == 'deprecated' { |
| 41 | mixed_msg = attr.arg |
| 42 | } |
| 43 | if attr.name == 'deprecated_after' { |
| 44 | mixed_after = attr.arg |
| 45 | } |
| 46 | } |
| 47 | assert mixed_msg == 'use NewMixed instead' |
| 48 | assert mixed_after == '2999-01-02' |
| 49 | } |
| 50 | |
| 51 | fn test_attribute_call_syntax_generic_named_args() { |
| 52 | mut has_custom := false |
| 53 | mut custom_flag := '' |
| 54 | mut custom_count := '' |
| 55 | $for attr in CustomNamed.attributes { |
| 56 | if attr.name == 'custom' { |
| 57 | has_custom = true |
| 58 | } |
| 59 | if attr.name == 'custom_flag' { |
| 60 | custom_flag = attr.arg |
| 61 | } |
| 62 | if attr.name == 'custom_count' { |
| 63 | custom_count = attr.arg |
| 64 | } |
| 65 | } |
| 66 | assert has_custom |
| 67 | assert custom_flag == 'true' |
| 68 | assert custom_count == '2' |
| 69 | } |
| 70 | |