File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ defmodule Mix.Utils do
267
267
268
268
def module_name_to_command ( module , nesting ) do
269
269
t = Regex . split ( ~r/ \. / , to_string ( module ) )
270
- t |> Enum . drop ( nesting ) |> Enum . map ( & first_to_lower ( & 1 ) ) |> Enum . join ( "." )
270
+ t |> Enum . drop ( nesting ) |> Enum . map ( & underscore ( & 1 ) ) |> Enum . join ( "." )
271
271
end
272
272
273
273
@ doc """
@@ -281,16 +281,10 @@ defmodule Mix.Utils do
281
281
"""
282
282
def command_to_module_name ( s ) do
283
283
Regex . split ( ~r/ \. / , to_string ( s ) ) |>
284
- Enum . map ( & first_to_upper ( & 1 ) ) |>
284
+ Enum . map ( & camelize ( & 1 ) ) |>
285
285
Enum . join ( "." )
286
286
end
287
287
288
- defp first_to_upper ( << s , t :: binary >> ) , do: << to_upper_char ( s ) >> <> t
289
- defp first_to_upper ( << >> ) , do: << >>
290
-
291
- defp first_to_lower ( << s , t :: binary >> ) , do: << to_lower_char ( s ) >> <> t
292
- defp first_to_lower ( << >> ) , do: << >>
293
-
294
288
defp to_upper_char ( char ) when char in ?a .. ?z , do: char - 32
295
289
defp to_upper_char ( char ) , do: char
296
290
Original file line number Diff line number Diff line change @@ -16,11 +16,15 @@ defmodule Mix.UtilsTest do
16
16
assert Mix.Utils . module_name_to_command ( Mix.Tasks.Foo , 2 ) == "foo"
17
17
assert Mix.Utils . module_name_to_command ( "Mix.Tasks.Foo" , 2 ) == "foo"
18
18
assert Mix.Utils . module_name_to_command ( "Mix.Tasks.Foo.Bar" , 2 ) == "foo.bar"
19
+ assert Mix.Utils . module_name_to_command ( "Mix.Tasks.FooBar.Bing" , 2 ) == "foo_bar.bing"
20
+ assert Mix.Utils . module_name_to_command ( "Mix.Tasks.FooBar.BingBang" , 2 ) == "foo_bar.bing_bang"
19
21
end
20
22
21
23
test :command_to_module_name do
22
24
assert Mix.Utils . command_to_module_name ( "foo" ) == "Foo"
23
25
assert Mix.Utils . command_to_module_name ( "foo.bar" ) == "Foo.Bar"
26
+ assert Mix.Utils . command_to_module_name ( "foo_bar.baz" ) == "FooBar.Baz"
27
+ assert Mix.Utils . command_to_module_name ( "foo_bar.baz_bing" ) == "FooBar.BazBing"
24
28
end
25
29
26
30
test :underscore do
You can’t perform that action at this time.
0 commit comments