@@ -28,6 +28,47 @@ defmodule Credo.Code.ModuleTest do
28
28
assert false == Module . attribute ( ast , :moduledoc )
29
29
end
30
30
31
+ test "should return the given module attribute for the top module in the given AST" do
32
+ { :ok , ast } =
33
+ """
34
+ defmodule CredoExample do
35
+ @attr_list [:atom1, :atom2]
36
+ @attr_string "This is a String"
37
+ @attr_number 42
38
+
39
+ @moduledoc false
40
+
41
+ defmodule Foo do
42
+ @attr_list [:atom3, :atom4]
43
+ @attr_string "This is another String"
44
+ @attr_number -1
45
+
46
+ @moduledoc "test"
47
+ end
48
+ end
49
+ """
50
+ |> Code . string_to_quoted ( )
51
+
52
+ assert [ :atom1 , :atom2 ] == Module . attribute ( ast , :attr_list )
53
+ assert "This is a String" == Module . attribute ( ast , :attr_string )
54
+ assert 42 == Module . attribute ( ast , :attr_number )
55
+ assert false == Module . attribute ( ast , :moduledoc )
56
+ end
57
+
58
+ test "should return the given module attribute, if found" do
59
+ ast =
60
+ { :defmodule , [ line: 2 , column: 3 ] ,
61
+ [
62
+ { :__aliases__ , [ line: 2 , column: 13 ] , [ :SubModule ] } ,
63
+ [ do: { :__block__ , [ ] , [ ] } ]
64
+ ] }
65
+
66
+ assert { :error , nil } == Module . attribute ( ast , :attr_list )
67
+ assert { :error , nil } == Module . attribute ( ast , :attr_string )
68
+ assert { :error , nil } == Module . attribute ( ast , :attr_number )
69
+ assert { :error , nil } == Module . attribute ( ast , :moduledoc )
70
+ end
71
+
31
72
#
32
73
# def_count
33
74
#
0 commit comments