Skip to content

Commit 5b7d3ad

Browse files
committed
Better names for sample type definitions in Kernel.TypespecTest
1 parent 4bb40b2 commit 5b7d3ad

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

lib/elixir/test/elixir/kernel/typespec_test.exs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ defmodule Kernel.TypespecTest do
8080

8181
test "@type with an atom" do
8282
module = test_module do
83-
@type mytype :: :atom
83+
@type my_type :: :foo
8484
end
8585

86-
assert [type: {:mytype, {:atom, _, :atom}, []}] =
86+
assert [type: {:my_type, {:atom, _, :foo}, []}] =
8787
types(module)
8888
end
8989

9090
test "@type with an atom alias" do
9191
module = test_module do
92-
@type mytype :: Atom
92+
@type my_type :: Atom
9393
end
9494

95-
assert [type: {:mytype, {:atom, _, Atom}, []}] =
95+
assert [type: {:my_type, {:atom, _, Atom}, []}] =
9696
types(module)
9797
end
9898

@@ -115,12 +115,12 @@ defmodule Kernel.TypespecTest do
115115

116116
test "@type with a remote type" do
117117
module = test_module do
118-
@type mytype :: Remote.Some.type
119-
@type mytype_arg :: Remote.type(integer)
118+
@type my_type :: Remote.Some.type
119+
@type my_type_arg :: Remote.type(integer)
120120
end
121121

122-
assert [type: {:mytype, {:remote_type, _, [{:atom, _, Remote.Some}, {:atom, _, :type}, []]}, []},
123-
type: {:mytype_arg, {:remote_type, _, [{:atom, _, Remote}, {:atom, _, :type}, [{:type, _, :integer, []}]]}, []}] =
122+
assert [type: {:my_type, {:remote_type, _, [{:atom, _, Remote.Some}, {:atom, _, :type}, []]}, []},
123+
type: {:my_type_arg, {:remote_type, _, [{:atom, _, Remote}, {:atom, _, :type}, [{:type, _, :integer, []}]]}, []}] =
124124
types(module)
125125
end
126126

@@ -188,10 +188,10 @@ defmodule Kernel.TypespecTest do
188188

189189
test "@type with a keyword map" do
190190
module = test_module do
191-
@type mytype :: %{hello: :world}
191+
@type my_type :: %{hello: :world}
192192
end
193193

194-
assert [type: {:mytype,
194+
assert [type: {:my_type,
195195
{:type, _, :map, [
196196
{:type, _, :map_field_exact, [{:atom, _, :hello}, {:atom, _, :world}]}
197197
]},
@@ -200,10 +200,10 @@ defmodule Kernel.TypespecTest do
200200

201201
test "@type with a map" do
202202
module = test_module do
203-
@type mytype :: %{required(:a) => :b, optional(:c) => :d}
203+
@type my_type :: %{required(:a) => :b, optional(:c) => :d}
204204
end
205205

206-
assert [type: {:mytype,
206+
assert [type: {:my_type,
207207
{:type, _, :map, [
208208
{:type, _, :map_field_exact, [{:atom, _, :a}, {:atom, _, :b}]},
209209
{:type, _, :map_field_assoc, [{:atom, _, :c}, {:atom, _, :d}]}
@@ -214,10 +214,10 @@ defmodule Kernel.TypespecTest do
214214
test "@type with a struct" do
215215
module = test_module do
216216
defstruct [hello: nil, other: nil]
217-
@type mytype :: %TestTypespec{hello: :world}
217+
@type my_type :: %TestTypespec{hello: :world}
218218
end
219219

220-
assert [type: {:mytype,
220+
assert [type: {:my_type,
221221
{:type, _, :map, [
222222
{:type, _, :map_field_exact, [{:atom, _, :__struct__}, {:atom, _, TestTypespec}]},
223223
{:type, _, :map_field_exact, [{:atom, _, :hello}, {:atom, _, :world}]},
@@ -269,10 +269,10 @@ defmodule Kernel.TypespecTest do
269269
module = test_module do
270270
require Record
271271
Record.defrecord :timestamp, [date: 1, time: 2]
272-
@type mytype :: record(:timestamp, time: :foo)
272+
@type my_type :: record(:timestamp, time: :foo)
273273
end
274274

275-
assert [type: {:mytype,
275+
assert [type: {:my_type,
276276
{:type, _, :tuple, [
277277
{:atom, 0, :timestamp}, {:type, 0, :term, []}, {:atom, 0, :foo}
278278
]},
@@ -283,10 +283,10 @@ defmodule Kernel.TypespecTest do
283283
module = test_module do
284284
require Record
285285
Record.defrecordp :timestamp, [date: 1, time: 2]
286-
@type mytype :: record(:timestamp, time: :foo)
286+
@type my_type :: record(:timestamp, time: :foo)
287287
end
288288

289-
assert [type: {:mytype,
289+
assert [type: {:my_type,
290290
{:type, _, :tuple, [
291291
{:atom, 0, :timestamp}, {:type, 0, :term, []}, {:atom, 0, :foo}
292292
]},
@@ -374,21 +374,21 @@ defmodule Kernel.TypespecTest do
374374

375375
test "@type with a union" do
376376
module = test_module do
377-
@type mytype :: integer | charlist | atom
377+
@type my_type :: integer | charlist | atom
378378
end
379379

380-
assert [type: {:mytype, {:type, _, :union, [{:type, _, :integer, []},
380+
assert [type: {:my_type, {:type, _, :union, [{:type, _, :integer, []},
381381
{:remote_type, _, [{:atom, _, :elixir}, {:atom, _, :charlist}, []]},
382382
{:type, _, :atom, []}]}, []}] =
383383
types(module)
384384
end
385385

386386
test "@type with keywords" do
387387
module = test_module do
388-
@type mytype :: [first: integer, step: integer, last: integer]
388+
@type my_type :: [first: integer, step: integer, last: integer]
389389
end
390390

391-
assert [type: {:mytype, {:type, _, :list, [
391+
assert [type: {:my_type, {:type, _, :list, [
392392
{:type, _, :union, [
393393
{:type, _, :tuple, [{:atom, _, :first}, {:type, _, :integer, []}]},
394394
{:type, _, :tuple, [{:atom, _, :step}, {:type, _, :integer, []}]},
@@ -444,14 +444,14 @@ defmodule Kernel.TypespecTest do
444444
test "@type unquote fragment" do
445445
module = test_module do
446446
quoted = quote unquote: false do
447-
name = :mytype
448-
type = :atom
447+
name = :my_type
448+
type = :foo
449449
@type unquote(name)() :: unquote(type)
450450
end
451451
Module.eval_quoted(__MODULE__, quoted) |> elem(0)
452452
end
453453

454-
assert [type: {:mytype, {:atom, _, :atom}, []}] =
454+
assert [type: {:my_type, {:atom, _, :foo}, []}] =
455455
types(module)
456456
end
457457

@@ -467,81 +467,81 @@ defmodule Kernel.TypespecTest do
467467

468468
test "@spec(spec)" do
469469
module = test_module do
470-
def myfun1(x), do: x
471-
def myfun2(), do: :ok
472-
def myfun3(x, y), do: {x, y}
473-
def myfun4(x), do: x
474-
@spec myfun1(integer) :: integer
475-
@spec myfun2() :: integer
476-
@spec myfun3(integer, integer) :: {integer, integer}
477-
@spec myfun4(x :: integer) :: integer
470+
def my_fun1(x), do: x
471+
def my_fun2(), do: :ok
472+
def my_fun3(x, y), do: {x, y}
473+
def my_fun4(x), do: x
474+
@spec my_fun1(integer) :: integer
475+
@spec my_fun2() :: integer
476+
@spec my_fun3(integer, integer) :: {integer, integer}
477+
@spec my_fun4(x :: integer) :: integer
478478
end
479479

480-
assert [{{:myfun1, 1}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}]}]},
481-
{{:myfun2, 0}, [{:type, _, :fun, [{:type, _, :product, []}, {:type, _, :integer, []}]}]},
482-
{{:myfun3, 2}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]}, {:type, _, :tuple, [{:type, _, :integer, []}, {:type, _, :integer, []}]}]}]},
483-
{{:myfun4, 1}, [{:type, _, :fun, [{:type, _, :product, [{:ann_type, _, [{:var, _, :x}, {:type, _, :integer, []}]}]}, {:type, _, :integer, []}]}]}] =
480+
assert [{{:my_fun1, 1}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}]}]},
481+
{{:my_fun2, 0}, [{:type, _, :fun, [{:type, _, :product, []}, {:type, _, :integer, []}]}]},
482+
{{:my_fun3, 2}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]}, {:type, _, :tuple, [{:type, _, :integer, []}, {:type, _, :integer, []}]}]}]},
483+
{{:my_fun4, 1}, [{:type, _, :fun, [{:type, _, :product, [{:ann_type, _, [{:var, _, :x}, {:type, _, :integer, []}]}]}, {:type, _, :integer, []}]}]}] =
484484
specs(module)
485485
end
486486

487487
test "@spec(spec) for unreachable private function" do
488-
# Run it inside capture_io/2 so that the "myfun/1 is unused"
488+
# Run it inside capture_io/2 so that the "my_fun/1 is unused"
489489
# warning doesn't get printed among the ExUnit test results.
490490
output = ExUnit.CaptureIO.capture_io :stderr, fn ->
491491
module = test_module do
492-
defp myfun(x), do: x
493-
@spec myfun(integer) :: integer
492+
defp my_fun(x), do: x
493+
@spec my_fun(integer) :: integer
494494
end
495495

496496
assert [] == specs(module)
497497
end
498498

499-
assert output =~ "function myfun/1 is unused"
499+
assert output =~ "function my_fun/1 is unused"
500500
end
501501

502502
test "@spec(spec) with guards" do
503503
module = test_module do
504-
def myfun1(x), do: x
505-
@spec myfun1(x) :: boolean when [x: integer]
504+
def my_fun1(x), do: x
505+
@spec my_fun1(x) :: boolean when [x: integer]
506506

507-
def myfun2(x), do: x
508-
@spec myfun2(x) :: x when [x: var]
507+
def my_fun2(x), do: x
508+
@spec my_fun2(x) :: x when [x: var]
509509

510-
def myfun3(_x, y), do: y
511-
@spec myfun3(x, y) :: y when [y: x, x: var]
510+
def my_fun3(_x, y), do: y
511+
@spec my_fun3(x, y) :: y when [y: x, x: var]
512512
end
513513

514-
assert [{{:myfun1, 1}, [{:type, _, :bounded_fun, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :x}]}, {:type, _, :boolean, []}]}, [{:type, _, :constraint, [{:atom, _, :is_subtype}, [{:var, _, :x}, {:type, _, :integer, []}]]}]]}]},
515-
{{:myfun2, 1}, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :x}]}, {:var, _, :x}]}]},
516-
{{:myfun3, 2}, [{:type, _, :bounded_fun, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :x}, {:var, _, :y}]}, {:var, _, :y}]}, [{:type, _, :constraint, [{:atom, _, :is_subtype}, [{:var, _, :y}, {:var, _, :x}]]}]]}]}] =
514+
assert [{{:my_fun1, 1}, [{:type, _, :bounded_fun, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :x}]}, {:type, _, :boolean, []}]}, [{:type, _, :constraint, [{:atom, _, :is_subtype}, [{:var, _, :x}, {:type, _, :integer, []}]]}]]}]},
515+
{{:my_fun2, 1}, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :x}]}, {:var, _, :x}]}]},
516+
{{:my_fun3, 2}, [{:type, _, :bounded_fun, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :x}, {:var, _, :y}]}, {:var, _, :y}]}, [{:type, _, :constraint, [{:atom, _, :is_subtype}, [{:var, _, :y}, {:var, _, :x}]]}]]}]}] =
517517
specs(module)
518518
end
519519

520520
test "@callback(callback)" do
521521
module = test_module do
522-
@callback myfun(integer) :: integer
523-
@callback myfun() :: integer
524-
@callback myfun(integer, integer) :: {integer, integer}
522+
@callback my_fun(integer) :: integer
523+
@callback my_fun() :: integer
524+
@callback my_fun(integer, integer) :: {integer, integer}
525525
end
526526

527-
assert [{{:myfun, 0}, [{:type, _, :fun, [{:type, _, :product, []}, {:type, _, :integer, []}]}]},
528-
{{:myfun, 1}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}]}]},
529-
{{:myfun, 2}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]}, {:type, _, :tuple, [{:type, _, :integer, []}, {:type, _, :integer, []}]}]}]}] =
527+
assert [{{:my_fun, 0}, [{:type, _, :fun, [{:type, _, :product, []}, {:type, _, :integer, []}]}]},
528+
{{:my_fun, 1}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}]}]},
529+
{{:my_fun, 2}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]}, {:type, _, :tuple, [{:type, _, :integer, []}, {:type, _, :integer, []}]}]}]}] =
530530
callbacks(module)
531531
end
532532

533533
test "@spec + @callback" do
534534
module = test_module do
535-
def myfun(x), do: x
536-
@spec myfun(integer) :: integer
537-
@spec myfun(charlist) :: charlist
535+
def my_fun(x), do: x
536+
@spec my_fun(integer) :: integer
537+
@spec my_fun(charlist) :: charlist
538538
@callback cb(integer) :: integer
539539
end
540540

541541
assert [{{:cb, 1}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}]}]}] =
542542
callbacks(module)
543543

544-
assert [{{:myfun, 1}, [
544+
assert [{{:my_fun, 1}, [
545545
{:type, _, :fun, [{:type, _, :product, [
546546
{:remote_type, _, [{:atom, _, :elixir}, {:atom, _, :charlist}, []]}]},
547547
{:remote_type, _, [{:atom, _, :elixir}, {:atom, _, :charlist}, []]}]},
@@ -571,7 +571,7 @@ defmodule Kernel.TypespecTest do
571571
(quote do: @type one_tuple() :: {:foo}),
572572
(quote do: @type two_tuple() :: {:foo, :bar}),
573573
(quote do: @type imm_type_1() :: 1),
574-
(quote do: @type imm_type_2() :: :atom),
574+
(quote do: @type imm_type_2() :: :foo),
575575
(quote do: @type simple_type() :: integer()),
576576
(quote do: @type param_type(p) :: [p]),
577577
(quote do: @type union_type() :: integer() | binary() | boolean()),
@@ -592,8 +592,8 @@ defmodule Kernel.TypespecTest do
592592
(quote do: @type a_map() :: map()),
593593
(quote do: @type empty_map() :: %{}),
594594
(quote do: @type my_map() :: %{hello: :world}),
595-
(quote do: @type my_req_map() :: %{required(0) => :atom}),
596-
(quote do: @type my_opt_map() :: %{optional(0) => :atom}),
595+
(quote do: @type my_req_map() :: %{required(0) => :foo}),
596+
(quote do: @type my_opt_map() :: %{optional(0) => :foo}),
597597
(quote do: @type my_struct() :: %Kernel.TypespecTest{hello: :world}),
598598
(quote do: @type list1() :: list()),
599599
(quote do: @type list2() :: [0]),
@@ -657,7 +657,7 @@ defmodule Kernel.TypespecTest do
657657
@callback bar(External.hello, my_var :: binary) :: binary
658658
@callback guarded(my_var) :: my_var when my_var: binary
659659
@callback orr(atom | integer) :: atom
660-
@callback literal(123, {atom}, :atom, [integer], true) :: atom
660+
@callback literal(123, {atom}, :foo, [integer], true) :: atom
661661
@macrocallback last(integer) :: Macro.t
662662
@macrocallback lastlast() :: atom
663663
@optional_callbacks bar: 2, lastlast: 0
@@ -712,9 +712,9 @@ defmodule Kernel.TypespecTest do
712712
end
713713

714714
test "@spec shows readable error message when return type is missing" do
715-
assert_raise CompileError, ~r"type specification missing return type: myfun\(integer\)", fn ->
715+
assert_raise CompileError, ~r"type specification missing return type: my_fun\(integer\)", fn ->
716716
test_module do
717-
@spec myfun(integer)
717+
@spec my_fun(integer)
718718
end
719719
end
720720
end

0 commit comments

Comments
 (0)