|
| 1 | +require "../../../spec_helper" |
| 2 | + |
| 3 | +module Ameba::Rule::Lint |
| 4 | + describe VoidOutsideLib do |
| 5 | + subject = VoidOutsideLib.new |
| 6 | + |
| 7 | + it "passes if Void is used in a fun def" do |
| 8 | + expect_no_issues subject, <<-CRYSTAL |
| 9 | + lib LibFoo |
| 10 | + fun bar(baz : Void) : Void |
| 11 | + end |
| 12 | + CRYSTAL |
| 13 | + end |
| 14 | + |
| 15 | + it "passes if `Pointer(Void)` is used as a parameter type restriction" do |
| 16 | + expect_no_issues subject, <<-CRYSTAL |
| 17 | + def foo(bar : Pointer(Void)) |
| 18 | + end |
| 19 | + CRYSTAL |
| 20 | + end |
| 21 | + |
| 22 | + it "fails if `Void` is used as a parameter type restriction" do |
| 23 | + expect_issue subject, <<-CRYSTAL |
| 24 | + def foo(bar : Void) |
| 25 | + # ^^^^ error: `Void` is not allowed in this context |
| 26 | + end |
| 27 | + CRYSTAL |
| 28 | + end |
| 29 | + |
| 30 | + it "passes if `Pointer(Void)` is used as return type restriction" do |
| 31 | + expect_no_issues subject, <<-CRYSTAL |
| 32 | + def foo(bar) : Pointer(Void) |
| 33 | + end |
| 34 | + CRYSTAL |
| 35 | + end |
| 36 | + |
| 37 | + it "passes if `Pointer(Void) | Nil` is used as return type restriction" do |
| 38 | + expect_no_issues subject, <<-CRYSTAL |
| 39 | + def foo(bar) : Pointer(Void) | Nil |
| 40 | + end |
| 41 | + CRYSTAL |
| 42 | + end |
| 43 | + |
| 44 | + it "fails if `Pointer(Void | Int32)` is used as return type restriction" do |
| 45 | + expect_issue subject, <<-CRYSTAL |
| 46 | + def foo(bar) : Pointer(Void | Int32) |
| 47 | + # ^^^^ error: `Void` is not allowed in this context |
| 48 | + end |
| 49 | + CRYSTAL |
| 50 | + end |
| 51 | + |
| 52 | + it "fails if `Array(Void)` is used as return type restriction" do |
| 53 | + expect_issue subject, <<-CRYSTAL |
| 54 | + def foo(bar) : Array(Void) |
| 55 | + # ^^^^ error: `Void` is not allowed in this context |
| 56 | + end |
| 57 | + CRYSTAL |
| 58 | + end |
| 59 | + |
| 60 | + it "passes if Void is used as name of a class" do |
| 61 | + expect_no_issues subject, <<-CRYSTAL |
| 62 | + class Foo |
| 63 | + class Void |
| 64 | + end |
| 65 | + end |
| 66 | + CRYSTAL |
| 67 | + end |
| 68 | + |
| 69 | + it "fails if Void is inherited from" do |
| 70 | + expect_issue subject, <<-CRYSTAL |
| 71 | + struct Foo < Void |
| 72 | + # ^^^^ error: `Void` is not allowed in this context |
| 73 | + end |
| 74 | + CRYSTAL |
| 75 | + end |
| 76 | + |
| 77 | + it "passes if Void is name of alias" do |
| 78 | + expect_no_issues subject, <<-CRYSTAL |
| 79 | + alias Void = Foo |
| 80 | + CRYSTAL |
| 81 | + end |
| 82 | + |
| 83 | + it "fails if Void is value of alias" do |
| 84 | + expect_issue subject, <<-CRYSTAL |
| 85 | + alias Foo = Void |
| 86 | + # ^^^^ error: `Void` is not allowed in this context |
| 87 | + CRYSTAL |
| 88 | + end |
| 89 | + |
| 90 | + it "fails if `Void` is used for an uninitialized var" do |
| 91 | + expect_issue subject, <<-CRYSTAL |
| 92 | + var = uninitialized Void |
| 93 | + # ^^^^ error: `Void` is not allowed in this context |
| 94 | + CRYSTAL |
| 95 | + end |
| 96 | + end |
| 97 | +end |
0 commit comments