Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Macro.underscore/1 behavior with screaming snake case #5627

Closed
dantswain opened this issue Jan 8, 2017 · 4 comments
Closed

Unexpected Macro.underscore/1 behavior with screaming snake case #5627

dantswain opened this issue Jan 8, 2017 · 4 comments

Comments

@dantswain
Copy link

@dantswain dantswain commented Jan 8, 2017

This may not be a bug so much as an incorrect expectation on my part, but I couldn't find it reported otherwise.

Environment

Tested with Erlang/OTP 19, Elixir 1.3.4 and 1.4.0

Current behavior

iex(1)> Macro.underscore("FOO_BAR")
"fo_o__bar"

Expected behavior

I would expect "foo_bar" or some variation on that. I know this isn't precisely what Macro.underscore/1 advertises to do, but I'm trying to use it to turn a not-quite-arbitrary string (may represent, e.g., a function name in another language) into a valid Elixir function name. Regardless, the output "fo_o__bar" seems odd.

@dantswain
Copy link
Author

@dantswain dantswain commented Jan 8, 2017

FWIW This produces the expected result:

iex(3)> "FOO_BAR" |> String.split("_") |> Enum.map(&Macro.underscore/1) |> Enum.join("_")
"foo_bar"
@Eiji7
Copy link
Contributor

@Eiji7 Eiji7 commented Jan 8, 2017

Similar:

Macro.underscore("Foo_Bar")
"foo__bar"
@eksperimental
Copy link
Contributor

@eksperimental eksperimental commented Jan 8, 2017

I think it is a bug,
also see the behaviour of the "reverse" function

iex>  Macro.camelize("FOO_BAR")  
"FOO_BAR"
@Eiji7
Copy link
Contributor

@Eiji7 Eiji7 commented Jan 8, 2017

I created my version of &Macro.underscore/1 with tests for both implementations: MyMacroUnderscore.
Test it and let me know what do you think about it. Any tips are welcome! 😄
Note: I'm also changing ASCII whitespace characters to _ with really easy method guards.
If you are interested in my version of this method then I can create PR here.

adkron added a commit to BinaryNoggin/elixir that referenced this issue Jan 16, 2017
The screaming snake case was keeping its original format after being
camelized. As mentioned in issue elixir-lang#5627. This change allows it to behave
like the all lower snake case when camelized.

Amos King @adkron <amos@binarynoggin.com>
josevalim added a commit that referenced this issue Jan 18, 2017
The screaming snake case was keeping its original format after being
camelized. As mentioned in issue #5627. This change allows it to behave
like the all lower snake case when camelized.
AndrewDryga added a commit to AndrewDryga/elixir that referenced this issue Jan 28, 2017
The screaming snake case was keeping its original format after being
camelized. As mentioned in issue elixir-lang#5627. This change allows it to behave
like the all lower snake case when camelized.
ckampfe added a commit to ckampfe/elixir that referenced this issue Jul 22, 2017
The screaming snake case was keeping its original format after being
camelized. As mentioned in issue elixir-lang#5627. This change allows it to behave
like the all lower snake case when camelized.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.