Add support for multi-underscore command modules.

This commit is contained in:
Brandon Shroyer 2016-03-04 13:16:18 -05:00
parent a5a54f1f85
commit de9463b859
2 changed files with 7 additions and 2 deletions

View File

@ -29,8 +29,7 @@ defmodule CommandModules do
file_name
|> Path.basename
|> Path.rootname(".ex")
|> String.split("_")
|> List.first
|> String.replace_suffix("_command", "")
end
# Takes a name (e.g., "status_command") and returns a {atom, string}

View File

@ -23,6 +23,7 @@ defmodule CommandModulesTest do
filenames = [
"#{source_dir}/imperial_command.ex",
"#{source_dir}/lord_protectoral_command.ex",
"#{source_dir}/polite_suggestion.ex",
"#{source_dir}/royalcommand.ex",
"#{source_dir}/ducal-command.ex",
@ -40,6 +41,11 @@ defmodule CommandModulesTest do
assert CommandModules.generate_module_map[:imperial] == "ImperialCommand"
end
test "command with multiple underscores shows up in map" do
assert CommandModules.generate_module_map[:lord_protectoral] ==
"LordProtectoralCommand"
end
test "command_modules does not have non-existent commands" do
assert CommandModules.generate_module_map[:usurper] == nil
end