Skip to content

Commit

Permalink
Merge pull request #483 from jecisc/extract-returns-from-conditionals
Browse files Browse the repository at this point in the history
extract-returns-from-conditionals
  • Loading branch information
Ducasse authored May 26, 2020
2 parents be9906b + 48f3ef8 commit 9f6ae72
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/Pillar-BookTester/PRCodeblock.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ PRCodeblock >> isTestDefinition [
{ #category : #'*Pillar-BookTester' }
PRCodeblock >> textForExample [
"returns a preformated text for codeblock testing"

"(PRCodeblock content: ' 3+4 >>> 7 ' parameters: (OrderedDictionary newFromKeys: #('example') andValues: #(true))) textForExample
>>> '(3+4)>>>7'"

('*>>>*' match: self text)
ifTrue: [ ^ '(', (self text splitOn: '>>>') first trimBoth,
')','>>>', (self text splitOn: '>>>') second trimBoth ]
ifFalse: [ ^ self text ]


^ ('*>>>*' match: self text)
ifTrue: [ '(' , (self text splitOn: '>>>') first trimBoth , ')' , '>>>' , (self text splitOn: '>>>') second trimBoth ]
ifFalse: [ self text ]
]

{ #category : #'*Pillar-BookTester' }
Expand All @@ -80,18 +79,27 @@ PRCodeblock >> textForMethodDefinition [
-Class Name
-Method Name
-Method Body"

"(PRCodeblock content: 'classname >> methodName
blabla
blabla' parameters: nil) textForMethodDefinitionParameter >>> #('classname' 'methodName' 'blabla
blabla') "

('*>>*' match: self text)
ifTrue: [ ^ Array with: ((self text splitOn: '>>') first trimBoth splitOn: ' ') asArray
with: (((self text splitOn: '>>') second) splitOn: '

^ ('*>>*' match: self text)
ifTrue: [ Array
with: ((self text splitOn: '>>') first trimBoth splitOn: ' ') asArray
with:
((self text splitOn: '>>') second
splitOn:
'
') first trimBoth
with: ('
' join: (((self text splitOn: '>>') second) splitOn: '
with:
('
'
join:
((self text splitOn: '>>') second
splitOn:
'
') allButFirst) trimBoth ]
ifFalse: [ ^ 'Method definition syntax not respected. Please use: YourClass>>yourMethod ...' ]

ifFalse: [ 'Method definition syntax not respected. Please use: YourClass>>yourMethod ...' ]
]

0 comments on commit 9f6ae72

Please sign in to comment.