Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh support sync method definition #877

Merged
merged 11 commits into from
Sep 11, 2024
237 changes: 237 additions & 0 deletions src/Microdown-BookTester-Tests/MicMethodBodySyncTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
Class {
#name : 'MicMethodBodySyncTest',
#superclass : 'TestCase',
#category : 'Microdown-BookTester-Tests',
#package : 'Microdown-BookTester-Tests'
}

{ #category : 'data' }
MicMethodBodySyncTest class >> simpleCode [
"The comment of simpleCode"

^ 100 slowFactorial
]

{ #category : 'data' }
MicMethodBodySyncTest >> parseAndTest: docText [

| doc bTester |
doc := Microdown parse: docText.
bTester := MicBookTesterVisitor new.
bTester start: doc.
^ bTester
]

{ #category : 'data' }
MicMethodBodySyncTest >> simpleCode [
"The comment of simpleCode"

^ 100 slowFactorial
]

{ #category : 'tests - not reported' }
MicMethodBodySyncTest >> testCodeblockIsNotInSyncButShouldNotBeReported [

| bTester headerString methodDef |
headerString := '```sync=false&origin=MicMethodBodySyncTest>>#simpleCode'.
methodDef :=
'simpleCode
"This is not the definition of simpleCode"

^ 100 slowFactorial + 100'.

bTester := self parseAndTest: headerString, Character cr asString , methodDef, Character cr asString, '```'.
self assert: bTester results isEmpty.

]

{ #category : 'tests' }
MicMethodBodySyncTest >> testCodeblockIsNotInSyncCheckingResultAttributes [

| bTester brokenCodeResult headerString methodDef |
headerString := '```sync=true&origin=MicMethodBodySyncTest>>#simpleCode'.
methodDef :=
'simpleCode
"This is not the definition of simpleCode"

^ 100 slowFactorial + 100'.

bTester := self parseAndTest: headerString, Character cr asString , methodDef, Character cr asString, '```'.
brokenCodeResult := bTester results first.

self
assert: brokenCodeResult originString
equals: 'MicMethodBodySyncTest>>#simpleCode'.
self
assert: brokenCodeResult bookContents
equals: methodDef.
self
assert: brokenCodeResult imageContents
equals: (self class >> #simpleCode) sourceCode
]

{ #category : 'tests - broken input' }
MicMethodBodySyncTest >> testMetaclassInOriginSpecification [

| docText bTester |
docText := '```sync=true&origin=MicMethodBodySyncTest class>>#simpleCode
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
self assert: bTester results isEmpty
]

{ #category : 'tests - broken input' }
MicMethodBodySyncTest >> testMetaclassWithSpacesInOriginSpecification [

| docText bTester |
docText := '```sync=true&origin=MicMethodBodySyncTest class >>#simpleCode
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
self assert: bTester results isEmpty
]

{ #category : 'tests - broken input' }
MicMethodBodySyncTest >> testMetaclassWithStartingSpacesInOriginSpecification [

| docText bTester |
docText := '```sync=true&origin= MicMethodBodySyncTest class >>#simpleCode
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
self assert: bTester results isEmpty
]

{ #category : 'tests - broken input' }
MicMethodBodySyncTest >> testReportCodeBlockInSyncWithMetaclassMethod [

| docText bTester |
docText := '```sync=true&origin=MicMethodBodySyncTest class>>#simpleCode
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
self assert: bTester results isEmpty
]

{ #category : 'tests' }
MicMethodBodySyncTest >> testReportCodeblockIsInSync [

| docText bTester |
docText := '```sync=true&origin=MicMethodBodySyncTest>>#simpleCode
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
self assert: bTester results isEmpty

]

{ #category : 'tests - broken sync' }
MicMethodBodySyncTest >> testReportCodeblockWithBrokenSync [
"even if the code is in sync reports that the sync declaration is bogus"

| bTester brokenHeaderString methodDef report |
brokenHeaderString := '```sync=FooBar&origin=MicMethodBodySyncTest>>#simpleCode'.
methodDef :=
'simpleCode
"The comment of simpleCode"

^ 100 slowFactorial'.

bTester := self parseAndTest: brokenHeaderString, Character cr asString, methodDef, Character cr asString, '```'.

self assert: (self class >> #simpleCode) sourceCode equals: methodDef.
report := bTester results first.
self assert: report class equals: MicBrokenSyncDefinition.
self assert: report syncValue equals: 'FooBar'

]

{ #category : 'tests - broken sync' }
MicMethodBodySyncTest >> testReportCodeblockWithBrokenSyncDeclaration [

| bTester headerString methodDef |
headerString := '```sync=fooBar&origin=MicMethodBodySyncTest>>#simpleCode'.
methodDef :=
'simpleCode
"This is not the definition of simpleCode"

^ 100 slowFactorial + 100'.

bTester := self parseAndTest: headerString, Character cr asString , methodDef, Character cr asString, '```'.
self deny: bTester results isEmpty.

]

{ #category : 'tests' }
MicMethodBodySyncTest >> testReportsCodeblockIsNotInSync [

| bTester brokenCodeResult headerString methodDef |
headerString := '```sync=true&origin=MicMethodBodySyncTest>>#simpleCode'.
methodDef :=
'simpleCode
"This is not the definition of simpleCode"

^ 100 slowFactorial + 100'.

bTester := self parseAndTest: headerString, Character cr asString , methodDef, Character cr asString, '```'.
brokenCodeResult := bTester results first.

self
assert: brokenCodeResult originString
equals: 'MicMethodBodySyncTest>>#simpleCode'.
]

{ #category : 'tests - broken input' }
MicMethodBodySyncTest >> testUnexistingClassInOriginSpecification [

| docText bTester result |
docText := '```sync=true&origin=MicMethodBodySyncTestDOESNNO>>#simpleCode
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
result := bTester results first.
self assert: result class equals: MicBrokenSyncOriginDefinition

]

{ #category : 'tests - broken input' }
MicMethodBodySyncTest >> testUnexistingMethodInOriginSpecification [

| docText bTester result |
docText := '```sync=true&origin=MicMethodBodySyncTest>>#DoesNotExist
simpleCode
"The comment of simpleCode"

^ 100 slowFactorial
``` '.

bTester := self parseAndTest: docText.
result := bTester results first.
self assert: result class equals: MicBrokenSyncOriginDefinition

]
10 changes: 10 additions & 0 deletions src/Microdown-BookTester/Association.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : 'Association' }

{ #category : '*Microdown-BookTester' }
Association >> isMicPaired [
"
7+3 >>> 10
"

^ self key = self value
]
23 changes: 23 additions & 0 deletions src/Microdown-BookTester/MicBookTesterNullStrategy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"
When there is no tag other than none or language, does not verify the code block.
"
Class {
#name : 'MicBookTesterNullStrategy',
#superclass : 'MicBookTesterStrategy',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
}

{ #category : 'hook' }
MicBookTesterNullStrategy class >> handleKey [

^ #language

]

{ #category : 'main API' }
MicBookTesterNullStrategy >> verify: aMicCodeBlock [



]
21 changes: 21 additions & 0 deletions src/Microdown-BookTester/MicBookTesterStrategy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Class {
#name : 'MicBookTesterStrategy',
#superclass : 'Object',
#instVars : [
'results'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
}

{ #category : 'hook' }
MicBookTesterStrategy class >> handleKey [

^ self subclassResponsibility

]

{ #category : 'accessing' }
MicBookTesterStrategy >> results: aCollection [
results := aCollection
]
Loading
Loading