Skip to content

Commit

Permalink
Merge pull request #127 from mumuki/issue-#123-ruby-case-not-acceptin…
Browse files Browse the repository at this point in the history
…g-special-chars

Issue #123 ruby case not accepting special chars
  • Loading branch information
flbulgarelli authored Dec 25, 2017
2 parents 8fc9fa1 + cf68a7b commit 6d0ceca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions spec/DomainLanguageSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ spec = do
context "rubyCase language" $ do
let run = hasWrongCaseIdentifiers (DomainLanguage english rubyCase 3 jargon)

it "is True when method name is camelCase" $ do
run (SimpleMethod "helloWorld" [] MuNull) `shouldBe` True

it "is False when method name is snake_case" $ do
run (SimpleMethod "hello_world" [] MuNull) `shouldBe` False

it "is False when method name is snake_case!" $ do
run (SimpleMethod "hello_world!" [] MuNull) `shouldBe` False

it "is False when method name is snake_case?" $ do
run (SimpleMethod "hello_world?" [] MuNull) `shouldBe` False

it "is False when method is a symbol" $ do
run (SimpleMethod "+" [] MuNull) `shouldBe` False

it "is True when there are lower camel case identifier" $ do
run (Variable "helloWorld" MuNull) `shouldBe` True

Expand Down
6 changes: 4 additions & 2 deletions src/Text/Inflections/Tokenizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ snakeCase :: CaseStyle
snakeCase = parseSnakeCase []

rubyCase :: CaseStyle
rubyCase word | (isLower.head) word = snakeCase word
| otherwise = camelCase word
rubyCase word | (isLower.head) word = snakeCase baseWord
| otherwise = camelCase baseWord

where baseWord = filter (`notElem` "!?+-=[]<>|&*/") word

canTokenize :: CaseStyle -> String -> Bool
canTokenize style = isRight . style
Expand Down

0 comments on commit 6d0ceca

Please sign in to comment.