Class { #name : 'PPCommonMarkBlockTest', #superclass : 'PPCompositeParserTest', #instVars : [ 'context', 'quote', 'string', 'expected' ], #category : 'PetitMarkdown-Tests' } { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> assert: something type: type [ self assert: (something isKindOf: type). ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> assertResult: expectedResult [ self assert: expectedResult = result. " (TextDiffBuilder from: result to: expectedResult) buildDisplayPatch. " ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> context [ ^ context ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> parse: input rule: rule to: expectedResult [ self parse: input rule: rule. self assert: expectedResult = result. " (TextDiffBuilder from: result to: expectedResult) buildDisplayPatch. " ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> parserClass [ ^ PPCommonMarkBlockParser ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> setUp [ context := PPContext new. quote := self parserInstanceFor: #quote ] { #category : 'test-headers' } PPCommonMarkBlockTest >> testATXHeader [ self parse: '# foo' rule: #ATXHeader. self assert: result title text = 'foo'. self parse: '# foo#' rule: #ATXHeader. self assert: result title text = 'foo#'. self parse: '# foo #' rule: #ATXHeader. self assert: result title text = 'foo'. ] { #category : 'test-headers' } PPCommonMarkBlockTest >> testATXHeader2 [ self parse: '#' rule: #ATXHeader. self assert: result title text = ''. self parse: '# ' rule: #ATXHeader. self assert: result title text = ''. self parse: '# #' rule: #ATXHeader. self assert: result title text = ''. self parse: '### ###' rule: #ATXHeader. self assert: result title text = ''. ] { #category : 'test-code' } PPCommonMarkBlockTest >> testFencedCode [ self parse: '``` abc def ```' rule: #code. self assert: result type: PPCMFencedCode. self assert: result code = 'abc def'. ] { #category : 'test-code' } PPCommonMarkBlockTest >> testFencedCode2 [ context := PPContext new. context indentStack push: ' ' asParser. self parse: '``` abc def ```' rule: #code. self assert: result type: PPCMFencedCode. self assert: result code = 'abc def'. ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> testHorizontalRule [ self parse: '***' rule: #horizontalRule. self parse: ' - - -' rule: #horizontalRule. ] { #category : 'test-html blocks' } PPCommonMarkBlockTest >> testHtmlBlock [ self parse: '
' rule: #htmlBlock. self assert: result type: PPCMHtmlBlock. ] { #category : 'test-code' } PPCommonMarkBlockTest >> testIndentedCode [ self parse: ' abc' rule: #code. self assert: result type: PPCMIndentedCode. self assert: result code = 'abc'. self parse: ' abc def' rule: #code. self assert: result code = 'abc def'. self parse: ' this is a code' rule: #code. self assert: result code = 'this is a code'. self parse: ' this is a code' rule: #code. self assert: result code = ' this is a code'. self parse: ' this is a code ' rule: #code. self assert: result code = ' this is a code'. self parse: ' chunk1 chunk2 chunk3' rule: #code. self assert: result code = 'chunk1 chunk2 chunk3'. self parse: ' chunk1 chunk2' rule: #code. self assert: result code = 'chunk1 chunk2'. ] { #category : 'test-paragraph' } PPCommonMarkBlockTest >> testLazyParagraphPrefix [ self parse: '' rule: #lazyParagraphPrefix. context := PPContext new. context indentStack push: quote. self parse: '> ' rule: #lazyParagraphPrefix. context := PPContext new. context indentStack push: quote. self fail: '> >' rule: #lazyParagraphPrefix. context := PPContext new. context indentStack push: quote. context indentStack push: quote. self parse: ' > >' rule: #lazyParagraphPrefix. ] { #category : 'test-links' } PPCommonMarkBlockTest >> testLinkRef [ self parse: '[foo]' rule: #paragraph. self assert: result type: PPCMParagraph. self assert: result text = '[foo]'. ] { #category : 'test-links' } PPCommonMarkBlockTest >> testLinkRefDef [ self parse: '[foo]: /url "title"' rule: #linkRefDef. self assert: result type: PPCMLinkRefDefPlaceholder. self assert: context links size = 1. self assert: context links anyOne type: PPCMLinkRefDef. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testList [ context := PPContext new. self parse: '- one' rule: #list. self assert: result type: PPCMList. self assert: result children size = 1. self assert: result child text = 'one'. self assert: context indentStack isEmpty. context := PPContext new. self parse: '- one - two' rule: #list. self assert: result type: PPCMList. self assert: result children size = 2. self assert: result firstChild text = 'one'. self assert: result secondChild text = 'two'. self assert: context indentStack isEmpty. context := PPContext new. self parse: '- one - two' rule: #list. self assert: result type: PPCMList. self assert: result children size = 3. self assert: result firstChild text trim = 'one'. self assert: result thirdChild text = 'two'. self assert: context indentStack isEmpty. self assert: context indentStack isEmpty. context := PPContext new. context indentStack push: quote. self parse: '- one >- two' rule: #list. self assert: result type: PPCMList. self assert: result children size = 2. self assert: result firstChild text = 'one'. self assert: result secondChild text = 'two'. self assert: context indentStack size = 1. context := PPContext new. self parse: '- one - ' rule: #list. self assert: result type: PPCMList. self assert: result children size = 2. self assert: result firstChild text = 'one'. self assert: result secondChild text = ''. self assert: context indentStack isEmpty. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testList2 [ context := PPContext new. self parse: '1. one' rule: #list. self assert: result type: PPCMList. self assert: result children size = 1. self assert: result child text = 'one'. self assert: context indentStack isEmpty. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListBullet [ context := PPContext new. context listItemType: $- asParser. self parse: '- ' rule: #listBullet. self assert: context indentStack size = 1. self assert: context indentStack top literal = ' '. context := PPContext new. context listItemType: $- asParser. self parse: ' - ' rule: #listBullet. self assert: context indentStack size = 1. self assert: context indentStack top literal = ' '. context := PPContext new. context listItemType: $- asParser. parser := self parserInstanceFor: #listBullet. self assert: parser parse: ' - ' end: 3. self assert: context indentStack size = 1. self assert: context indentStack top literal = ' '. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListBullet2 [ context := PPContext new. context listItemType: $* asParser. self fail: '- ' rule: #listBullet. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListContent [ context := PPContext new. context indentStack push: quote. context indentStack push: ' ' asParser. self parse: 'one > two' rule: #listContent. self assert: result text = 'one two'. context := PPContext new. context indentStack push: quote. context indentStack push: ' ' asParser. self parse: 'one > two' rule: #listContent. self assert: result text = 'one two'. context := PPContext new. context indentStack push: quote. context indentStack push: ' ' asParser. self parse: '> one > > two' rule: #listContent. self assert: result firstChild type: PPCMBlockQuote. self assert: result firstChild text = 'one two'. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListItem [ context := PPContext new. context listItemType: $- asParser. self parse: '- one' rule: #listItem. self assert: result type: PPCMListItem. self assert: result text = 'one'. self assert: context indentStack size = 0. context := PPContext new. context listItemType: $- asParser. context indentStack push: quote. self parse: '- > one > > two' rule: #listItem. self assert: result type: PPCMListItem. self assert: result child child type: PPCMBlockQuote. self assert: result child child text = 'one two'. context := PPContext new. context indentStack push: quote. context listItemType: $- asParser. self parse: '- > one > > > two' rule: #listItem. self assert: result type: PPCMListItem. self assert: result child children size = 3. self assert: result child children first type: PPCMBlockQuote. self assert: result child children third type: PPCMIndentedCode. context := PPContext new. context listItemType: $- asParser. self parse: '- ' rule: #listItem. self assert: result type: PPCMListItem. self assert: result text = ''. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListItemCode [ context := PPContext new. context listItemType: $- asParser. self parse: '- one' rule: #listItem. self assert: result child child type: PPCMIndentedCode. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListItemEmpty [ context := PPContext new. context listItemType: $- asParser. self parse: '- ' rule: #listItem. self assert: result type: PPCMListItem. self assert: result text = ''. self assert: context indentStack size = 0. context := PPContext new. context listItemType: $- asParser. self parse: '-' rule: #listItem. self assert: result type: PPCMListItem. self assert: result text = ''. self assert: context indentStack size = 0. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListNested01 [ context := PPContext new. self parse: '- one - two' rule: #list. self assert: result type: PPCMList. self assert: result children size = 1. self assert: result child child firstChild text = 'one'. self assert: result child child secondChild type: PPCMList. self assert: result child child secondChild child text = 'two'. self assert: context indentStack isEmpty. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListNested02 [ context := PPContext new. self parse: '- one - two - three' rule: #list. self assert: result type: PPCMList. self assert: result children size = 1. self assert: result child child firstChild text = 'one'. self assert: result child child secondChild type: PPCMList. self assert: result child child secondChild child child firstChild text = 'two'. self assert: result child child secondChild child child secondChild type: PPCMList. self assert: result child child secondChild child child secondChild text = 'three'. self assert: context indentStack isEmpty. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListNested03 [ context := PPContext new. self parse: '- one - two - three - four' rule: #list. self assert: result type: PPCMList. self assert: result children size = 1. self assert: result child child firstChild text = 'one'. self assert: result child child secondChild type: PPCMList. self assert: result child child secondChild firstChild child firstChild text = 'two'. self assert: result child child secondChild firstChild child secondChild type: PPCMList. self assert: result child child secondChild firstChild child secondChild text = 'three'. self assert: result child child secondChild secondChild child firstChild text = 'four'. self assert: context indentStack isEmpty. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListNested04 [ context := PPContext new. self parse: '- one - two - three - four five' rule: #list. self assert: result type: PPCMList. self assert: result children size = 1. self assert: result child child firstChild text = 'one'. self assert: result child child secondChild type: PPCMList. self assert: result child child secondChild firstChild child firstChild text = 'two'. self assert: result child child secondChild firstChild child secondChild type: PPCMList. self assert: result child child secondChild firstChild child secondChild text = 'three'. self assert: result child child secondChild secondChild child firstChild text = 'four'. self assert: result child child secondChild secondChild child thirdChild text = 'five'. self assert: context indentStack isEmpty. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListTight [ context := PPContext new. self parse: '- one - two' rule: #list. self assert: result type: PPCMList. self assert: result isTight. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListTight2 [ context := PPContext new. self parse: '- one - two' rule: #list. self assert: result type: PPCMList. self assert: result children size = 3. self assert: result isTight not. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListTight3 [ context := PPContext new. self parse: '- one two' rule: #list. self assert: result type: PPCMList. self assert: result isTight. ] { #category : 'test-lists' } PPCommonMarkBlockTest >> testListTight4 [ context := PPContext new. self parse: '- one two' rule: #list. self assert: result type: PPCMList. self assert: result isTight. ] { #category : 'test-paragraph' } PPCommonMarkBlockTest >> testParagraph [ self parse: 'abc def' rule: #paragraph. self assert: result text = 'abc def'. self parse: 'abc def' rule: #paragraph. self assert: result text = 'abc def'. context := PPContext new. context indentStack push: quote. self parse: ' abc def' rule: #paragraph. self assert: result text = 'abc def'. context := PPContext new. context indentStack push: quote. self parse: 'abc > def' rule: #paragraph. self assert: result text = 'abc def'. ] { #category : 'test-paragraph' } PPCommonMarkBlockTest >> testParagraph2 [ self parse: 'foo # bar' rule: #paragraph. self assert: result text = 'foo # bar'. ] { #category : 'as yet unclassified' } PPCommonMarkBlockTest >> testPrefix [ self parse: '' rule: #prefix. context := PPContext new. context indentStack push: quote. self parse: '> ' rule: #prefix ] { #category : 'test-quotes' } PPCommonMarkBlockTest >> testQuote [ self parse: '>' rule: #quote. self assertResult: '>'. self parse: '> ' rule: #quote. self assertResult: '> '. self fail: ('>', String cr) rule: #quote. ] { #category : 'test-quotes' } PPCommonMarkBlockTest >> testQuoteBlock [ self parse: '> foo' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. self assert: result children size = 1. self assert: result child text = 'foo'. context := PPContext new. self parse: '> foo > bar' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. self assert: result children size = 1. self assert: result child text = 'foo bar'. context := PPContext new. self parse: '>> foo >> bar' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. self assert: result child child type: PPCMBlockQuote. self assert: result child child text = 'foo bar'. context := PPContext new. self parse: '># Foo' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. self assert: result child child type: PPCMHeader. self assert: result child child text = 'Foo'. context := PPContext new. self parse: '> foo > > bar' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. self assert: result child child type: PPCMIndentedCode. context := PPContext new. self parse: '>' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. context := PPContext new. self parse: '> > > ' rule: #quoteBlock. self assert: result type: PPCMBlockQuote. ] { #category : 'test-quotes' } PPCommonMarkBlockTest >> testQuoteDedent [ parser := self parserInstanceFor: #quoteDedent. context := PPContext new. context indentStack push: quote. self assert: parser parse: '' end: 0. self assert: context indentStack size = 0. self assert: parser fail: '' end: 0. context := PPContext new. self assert: parser fail: ''. context := PPContext new. context indentStack push: quote. self assert: parser fail: '>' end: 0. context := PPContext new. context indentStack push: quote. context indentStack push: quote. self assert: parser parse: ' > ' end: 0. context := PPContext new. context indentStack push: quote. context indentStack push: ' ' asParser. self assert: parser fail: ' > ' end: 0. context := PPContext new. context indentStack push: quote. context indentStack push: quote. context indentStack push: quote. self assert: parser parse: ' > > ' end: 0. context := PPContext new. context indentStack push: quote. context indentStack push: quote. self assert: parser parse: '' end: 0. self assert: parser parse: '' end: 0. self assert: parser fail: '' end: 0. ] { #category : 'test-quotes' } PPCommonMarkBlockTest >> testQuoteIndent [ parser := self parserInstanceFor: #quoteIndent. context := PPContext new. self assert: parser parse: '>' end: 1. self assert: context indentStack size = 1. self assert: context indentStack top = quote. context := PPContext new. self assert: parser parse: ' > ' end: 5. context := PPContext new. self assert: parser parse: ' >' end: 3. context := PPContext new. self assert: parser parse: ' >' end: 2. context := PPContext new. self assert: parser fail: ' >'. context := PPContext new. context indentStack push: quote. self assert: parser parse: '>' end: 1. self assert: context indentStack size = 2. self assert: context indentStack top = quote. context := PPContext new. context indentStack push: quote. self assert: parser parse: '> > ' end: 2. context := PPContext new. context indentStack push: quote. self assert: parser parse: ' > > ' end: 3. ] { #category : 'test-headers' } PPCommonMarkBlockTest >> testSetextHeader [ self parse: 'Foo ---' rule: #setextHeader. self assert: result title text = 'Foo'. ]