Skip to content

Commit

Permalink
#97 fixes inflector test
Browse files Browse the repository at this point in the history
  • Loading branch information
lopezca committed Jun 26, 2023
1 parent 350d8b3 commit 9912037
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/Glorp-Unit-Tests/GlorpInflectorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ GlorpInflectorTest >> camelToUnderscoreData [
'SpecialGuest' -> 'special_guest'.
'ApplicationController' -> 'application_controller'.
'Area51Controller' -> 'area51_controller'.
'UNIQUE' -> 'unique'
'UNIQUE' -> 'unique'.
'SumOfEVENTS' -> 'sum_of_events'.
'BigRANDOMBag' -> 'big_random_bag'
}


Expand Down Expand Up @@ -458,7 +460,7 @@ GlorpInflectorTest >> testCamelToUnderscore [

{ #category : #'tests-data' }
GlorpInflectorTest >> testCamelToUnderscoreWithoutReverse [
<expectedFailure>

self camelToUnderscoreWithoutReverse do: [ :ea |
self
assert: (inflector underscore: ea key)
Expand Down
31 changes: 18 additions & 13 deletions src/Glorp/ActiveRecordInflector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,22 @@ ActiveRecordInflector >> uncountableRegexFrom: aString [

{ #category : #accessing }
ActiveRecordInflector >> underscore: aString [
^String streamContents: [:s || in c first |
in := ReadStream on: aString.
c := in next.
first := true.
[c notNil and: [c isUppercase]] whileTrue: [
(in atEnd not and: [in peek isLowercase and: [ first not ]]) ifTrue: [s nextPut: $_].
s nextPut: c asLowercase. c := in next. first := false].
[ c notNil ] whileTrue: [
c isUppercase ifTrue: [ s nextPut: $_ ].
s nextPut: c asLowercase.
c := in next]
]


^ String streamContents: [ :s |
| in c first prev |
in := ReadStream on: aString.
c := in next.
first := true.
prev := nil.

[ c notNil ] whileTrue: [
c isUppercase ifTrue: [
(first not and: [ in atEnd not ]) ifTrue: [
(in peek isLowercase or: [ prev isLowercase ]) ifTrue: [
s nextPut: $_ ] ] ].

prev := c.
s nextPut: c asLowercase.
c := in next.
first := false ] ]
]

0 comments on commit 9912037

Please sign in to comment.