180 lines
4.5 KiB
Smalltalk
180 lines
4.5 KiB
Smalltalk
|
Class {
|
||
|
#name : 'PPCommonMarkInlineTest',
|
||
|
#superclass : 'PPCompositeParserTest',
|
||
|
#category : 'PetitMarkdown-Tests'
|
||
|
}
|
||
|
|
||
|
{ #category : 'support' }
|
||
|
PPCommonMarkInlineTest >> assert: something type: type [
|
||
|
self assert: (something isKindOf: type).
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : 'support' }
|
||
|
PPCommonMarkInlineTest >> parserClass [
|
||
|
^ PPCommonMarkInlinesParser
|
||
|
]
|
||
|
|
||
|
{ #category : 'support' }
|
||
|
PPCommonMarkInlineTest >> setUp [
|
||
|
super setUp.
|
||
|
self parserInstance initialize.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-paragraph' }
|
||
|
PPCommonMarkInlineTest >> testAmpersand [
|
||
|
self parse: 'ab'.
|
||
|
self assert: result first text = 'ab'.
|
||
|
|
||
|
self parse: 'a&b'.
|
||
|
self assert: result first text = 'a'.
|
||
|
self assert: result second text = '&'.
|
||
|
self assert: result third text = 'b'.
|
||
|
|
||
|
self parse: 'a\&b'.
|
||
|
self assert: result first text = 'a'.
|
||
|
self assert: result second text = '&'.
|
||
|
self assert: result third text = 'b'.
|
||
|
|
||
|
self parse: 'a&b'.
|
||
|
self assert: result first text = 'a'.
|
||
|
self assert: result second text = '&'.
|
||
|
self assert: result third text = 'b'.
|
||
|
|
||
|
self parse: 'a\&b'.
|
||
|
self assert: result first text = 'a'.
|
||
|
self assert: result second text = '&'.
|
||
|
self assert: result third text = 'amp;b'.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-links' }
|
||
|
PPCommonMarkInlineTest >> testAutolink [
|
||
|
self parse: '<http://foo.bar.baz>' rule: #autolink.
|
||
|
self assert: result type: PPCMLink.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-emphasize' }
|
||
|
PPCommonMarkInlineTest >> testEmphasize [
|
||
|
self parse: '*bar*' rule: #emphasize.
|
||
|
self assert: result type: PPCMEmphasize.
|
||
|
self assert: result text = 'bar'.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-emphasize' }
|
||
|
PPCommonMarkInlineTest >> testEmphasize2 [
|
||
|
self fail: '\*bar*' rule: #emphasize.
|
||
|
self fail: '*bar\*' rule: #emphasize.
|
||
|
]
|
||
|
|
||
|
{ #category : 'tests' }
|
||
|
PPCommonMarkInlineTest >> testEscaped [
|
||
|
| escaped |
|
||
|
escaped := self parserInstanceFor: #escaped.
|
||
|
parser := #any asParser, escaped, 'a' asParser.
|
||
|
|
||
|
self assert: parser parse: '\a'.
|
||
|
self assert: parser fail: 'ba'.
|
||
|
|
||
|
escaped := self parserInstanceFor: #escaped.
|
||
|
parser := #any asParser, #any asParser, escaped, 'a' asParser.
|
||
|
|
||
|
self assert: parser parse: 'a\a'.
|
||
|
self assert: parser fail: '\\a'.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-links' }
|
||
|
PPCommonMarkInlineTest >> testLinkDestination [
|
||
|
self parse: '/url' rule: #linkDestination.
|
||
|
self assert: result = '/url'.
|
||
|
|
||
|
self parse: '<my url>' rule: #linkDestination.
|
||
|
self assert: result = 'my%20url'.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-links' }
|
||
|
PPCommonMarkInlineTest >> testLinkInLabel [
|
||
|
parser := self parserInstanceFor: #linkInLabel.
|
||
|
|
||
|
self assert: parser parse: 'bar [baz](/uri)' end: 4.
|
||
|
self assert: parser parse: 'foo *[bar [baz](/uri)](/uri)*' end: 10.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-links' }
|
||
|
PPCommonMarkInlineTest >> testLinkRef [
|
||
|
parser := self parserInstanceFor: #linkRef.
|
||
|
|
||
|
self assert: parser fail: '[foo]'.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-links' }
|
||
|
PPCommonMarkInlineTest >> testLinkRef2 [
|
||
|
| refDef |
|
||
|
refDef := PPCMLinkRefDef new
|
||
|
label: 'foo';
|
||
|
destination: 'url';
|
||
|
title: 'title';
|
||
|
yourself.
|
||
|
self parserInstance registerLinkRefDef: refDef.
|
||
|
parser := self parserInstanceFor: #linkRef.
|
||
|
|
||
|
self assert: parser parse: '[foo]'.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-paragraph' }
|
||
|
PPCommonMarkInlineTest >> testParagraphBreak [
|
||
|
self parse: 'foo
|
||
|
bar'.
|
||
|
self assert: result first type: PPCMText.
|
||
|
self assert: result first text = 'foo'.
|
||
|
self assert: result second type: PPCMSoftBreak.
|
||
|
self assert: result third type: PPCMText.
|
||
|
self assert: result third text = 'bar'.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-paragraph' }
|
||
|
PPCommonMarkInlineTest >> testParagraphEscape [
|
||
|
self parse: 'a *a*'.
|
||
|
self assert: result size = 2.
|
||
|
self assert: result second type: PPCMEmphasize.
|
||
|
|
||
|
self parse: 'a \*a\*'.
|
||
|
self assert: result size = 4.
|
||
|
self assert: result first text = 'a '.
|
||
|
self assert: result second text = '*'.
|
||
|
self assert: result third text = 'a'.
|
||
|
self assert: result fourth text = '*'.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-html' }
|
||
|
PPCommonMarkInlineTest >> testRawHtml [
|
||
|
self parse: '<foo><bar>'.
|
||
|
|
||
|
self assert: result size = 2.
|
||
|
self assert: result first type: PPCMHtml.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-emphasize' }
|
||
|
PPCommonMarkInlineTest >> testText [
|
||
|
self parse: 'foo *bar*'.
|
||
|
self assert: result size = 2.
|
||
|
self assert: result first type: PPCMText.
|
||
|
self assert: result second type: PPCMEmphasize.
|
||
|
]
|
||
|
|
||
|
{ #category : 'test-paragraph' }
|
||
|
PPCommonMarkInlineTest >> testText2 [
|
||
|
self parse: '*bar*'.
|
||
|
self assert: result first type: PPCMEmphasize.
|
||
|
self assert: result first text = 'bar'.
|
||
|
|
||
|
self parse: 'foo*bar*'.
|
||
|
self assert: result first type: PPCMText.
|
||
|
self assert: result second type: PPCMEmphasize.
|
||
|
self assert: result first text = 'foo'.
|
||
|
self assert: result second text = 'bar'.
|
||
|
]
|