From 7ab19565daede1f649dceab8a2b2914bebc68836 Mon Sep 17 00:00:00 2001 From: "Julian Doherty (madlep)" Date: Sat, 20 Jul 2013 21:04:20 +1000 Subject: [PATCH] reverse @__behaviour_docs__ These are top accumlated as module attributes, so are therefore stored in reverse order to how they were added. When we get them back out, reverse them again so they're back in the right order. This is used by ex_doc, and callbacks are listed backwards otherwise --- lib/elixir/lib/behaviour.ex | 2 +- lib/elixir/test/elixir/behaviour_test.exs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/elixir/lib/behaviour.ex b/lib/elixir/lib/behaviour.ex index bdde6b594e5..c58cd2574e3 100644 --- a/lib/elixir/lib/behaviour.ex +++ b/lib/elixir/lib/behaviour.ex @@ -109,7 +109,7 @@ defmodule Behaviour do end def __behaviour__(:docs) do - @__behaviour_docs__ + Enum.reverse(@__behaviour_docs__) end end end diff --git a/lib/elixir/test/elixir/behaviour_test.exs b/lib/elixir/test/elixir/behaviour_test.exs index 11a111c2383..facc54b34c9 100644 --- a/lib/elixir/test/elixir/behaviour_test.exs +++ b/lib/elixir/test/elixir/behaviour_test.exs @@ -6,27 +6,35 @@ defmodule BehaviourTest do defmodule Sample do use Behaviour + @doc "I should be first." + defcallback first(integer) :: integer + @doc "Foo" defcallback foo(atom, binary) :: binary @doc "Bar" defcallback bar(External.hello, my_var :: binary) :: binary + + @doc "I should be last." + defcallback last(integer) :: integer end test :docs do - docs = Enum.sort(Sample.__behaviour__(:docs)) + docs = Sample.__behaviour__(:docs) assert docs == [ - {{:bar, 2}, 13, "Bar"}, - {{:foo, 2}, 10, "Foo"} + {{:first, 1}, 10, "I should be first."}, + {{:foo, 2}, 13, "Foo"}, + {{:bar, 2}, 16, "Bar"}, + {{:last, 1}, 19, "I should be last."} ] end test :callbacks do - assert Sample.__behaviour__(:callbacks) == [foo: 2, bar: 2] + assert Sample.__behaviour__(:callbacks) == [first: 1, foo: 2, bar: 2, last: 1] end test :specs do - assert length(Keyword.get_values(Sample.module_info[:attributes], :callback)) == 2 + assert length(Keyword.get_values(Sample.module_info[:attributes], :callback)) == 4 end test :default_is_not_supported do