Skip to content

Add failing idempotence test#115

Closed
TomerAberbach wants to merge 1 commit intosindresorhus:mainfrom
TomerAberbach:main
Closed

Add failing idempotence test#115
TomerAberbach wants to merge 1 commit intosindresorhus:mainfrom
TomerAberbach:main

Conversation

@TomerAberbach
Copy link

@TomerAberbach TomerAberbach commented Jun 14, 2025

I noticed that camelCase is not idempotent, which I think is a bug. i.e. if camelCase is meant to return a camel-cased version of the input, then camel-casing it again should not result in a diff because it's already been camel-cased.

I've added a failing property-based test for this, but haven't figured out what the implementation bug is exactly. Feel free to merge as-is, but I may update this PR with an actual bug fix if I have time.

An example of a case that fails is "{ A":

  • camelCase("{ A") -> "{A"
  • camelCase(camelCase("{ A")) -> "{a"

@sindresorhus
Copy link
Owner

Thanks for the detailed investigation and property-based test!

After analyzing this, the non-idempotent behavior is an intentional trade-off. The function preserves special characters like @, #, :: in the output (see tests for mGridCol6@md, A::a, etc.). Fixing idempotence would require treating these as separators, which would break existing behavior.

The edge case you found ("{ A""{A}""{a}") is extremely rare in practice, and the function is designed to convert to camelCase rather than be a no-op on already-camelCased input.

I've documented this behavior in the README to avoid confusion. Closing as won't fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants