Skip to content

Commit

Permalink
Merge pull request #98 from lopezca/97-active-rectord-inflector-test-…
Browse files Browse the repository at this point in the history
…fail-fix

#97 fixes inflector test
  • Loading branch information
astares authored Jun 26, 2023
2 parents fbec968 + 9912037 commit 632288f
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 632288f

Please sign in to comment.