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

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

Comments

Projects
None yet
4 participants
@dantswain

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

This comment has been minimized.

Show comment
Hide comment
@dantswain

dantswain Jan 8, 2017

FWIW This produces the expected result:

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

FWIW This produces the expected result:

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

This comment has been minimized.

Show comment
Hide comment
@Eiji7

Eiji7 Jan 8, 2017

Contributor

Similar:

Macro.underscore("Foo_Bar")
"foo__bar"
Contributor

Eiji7 commented Jan 8, 2017

Similar:

Macro.underscore("Foo_Bar")
"foo__bar"
@eksperimental

This comment has been minimized.

Show comment
Hide comment
@eksperimental

eksperimental Jan 8, 2017

Member

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

iex>  Macro.camelize("FOO_BAR")  
"FOO_BAR"
Member

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

This comment has been minimized.

Show comment
Hide comment
@Eiji7

Eiji7 Jan 8, 2017

Contributor

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.

Contributor

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

Fix Macro.camelize/1 for screaming snake case
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.

Amos King @adkron <amos@binarynoggin.com>

josevalim added a commit that referenced this issue Jan 18, 2017

Fix Macro.camelize/1 for screaming snake case (#5662)
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.

@josevalim josevalim closed this in #5630 Jan 18, 2017

AndrewDryga added a commit to AndrewDryga/elixir that referenced this issue Jan 28, 2017

Fix Macro.camelize/1 for screaming snake case (#5662)
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.

ckampfe added a commit to ckampfe/elixir that referenced this issue Jul 22, 2017

Fix Macro.camelize/1 for screaming snake case (#5662)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment