diff --git a/src/NewTools-DocumentationReader-Tests/StGithubDocSpecificationTest.class.st b/src/NewTools-DocumentationReader-Tests/StGithubDocSpecificationTest.class.st new file mode 100644 index 0000000..1358b92 --- /dev/null +++ b/src/NewTools-DocumentationReader-Tests/StGithubDocSpecificationTest.class.st @@ -0,0 +1,26 @@ +" +A StGithubDocSpecificationTest is a test class for testing the behavior of StGithubDocSpecification +" +Class { + #name : #StGithubDocSpecificationTest, + #superclass : #TestCase, + #category : #'NewTools-DocumentationReader-Tests' +} + +{ #category : #tests } +StGithubDocSpecificationTest >> testUrlForDocFolder [ + | spec | + spec := StGithubDocSpecification new branch: 'Pharo10'. + self + assert: spec urlForDocFolder + equals: 'https://api.github.com/repos/pharo-project/pharo/git/trees/Pharo10' +] + +{ #category : #tests } +StGithubDocSpecificationTest >> testUrlForFile [ + | spec | + spec := StGithubDocSpecification new branch: 'Pharo10'. + self + assert: (spec urlForFile: 'foo/bar.md') + equals: 'https://raw.githubusercontent.com/pharo-project/pharo/Pharo10/doc/foo/bar.md' +] diff --git a/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st b/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st index ccb1599..4b2f784 100644 --- a/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st +++ b/src/NewTools-DocumentationReader-Tests/StHelpBrowserPresenterTest.class.st @@ -77,89 +77,15 @@ StHelpBrowserPresenterTest >> tearDown [ super tearDown. ] -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCache [ - - | docFolder file cache save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: 'this is a text' ]. - self presenterClass internalizeHelpFrom: docFolder. - cache := self presenterClass helpCache. - self assert: cache basenameWithoutExtension equals: 'doc'. - self - assert: cache children first basenameWithoutExtension - equals: 'file' ] ensure: [ self presenterClass helpCache: save ] -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCacheHandleShittyFiles [ - - | docFolder file cache save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: 'this is a text' ]. - - file := filesystem workingDirectory / 'doc' / '.DS_Store'. - file writeStreamDo: [ :stream | stream nextPutAll: 'crap crap' ]. - self presenterClass internalizeHelpFrom: docFolder. - cache := self presenterClass helpCache. - self assert: cache basenameWithoutExtension equals: 'doc'. - self assert: cache children size equals: 1 ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCacheOnlyAcceptFolderAndMicFiles [ - - | docFolder file cache save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: 'this is a text' ]. - - file := filesystem workingDirectory / 'doc' / 'Stupid.txt'. - file writeStreamDo: [ :stream | - stream nextPutAll: 'This is a stupid mistyped extension text' ]. - - filesystem createDirectory: 'doc/Epicea'. - file := filesystem workingDirectory / 'doc' / 'Epicea' / 'fileEp.mic'. - file writeStreamDo: [ :stream | - stream nextPutAll: 'this is a text about Epicea' ]. - self presenterClass internalizeHelpFrom: docFolder. - cache := self presenterClass helpCache. - self assert: cache children size equals: 2. - self assert: cache allChildren size equals: 4 ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testHelpCacheReturnFileReferenceEmptyIfNil [ - - | cache | - cache := self presenterClass helpCache. - self presenterClass emptyHelpCache. - self assert: self presenterClass helpCache hasChildren not. - self presenterClass helpCache: cache -] - { #category : #'tests - interaction' } StHelpBrowserPresenterTest >> testOpenIsWorkingSmokeTest [ - + "When this fails we have found a default way to open the help browser, then this test should be changed" | browser | - browser := self presenterClass new. - window := browser openWithSpec + self + should: [ + browser := self presenterClass new. + window := browser openWithSpec] + raise: Exception ] { #category : #'tests - interaction' } @@ -185,94 +111,6 @@ StHelpBrowserPresenterTest >> testOpenOnCustomHelp2 [ window := browser openWithSpec ] -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithClass [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: self presenterClass. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithDescription [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: SUnitTutorial. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: 'Tutorial'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithMethod [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: - self presenterClass >> #rootTopic:. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithObject [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: Object new. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnCustomHelpWithString [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnCustomHelp: - self presenterClass >> #rootTopic:. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testOpenOnDoesNotExistFolder [ - - | browser rootTopic save | - [ - save := self presenterClass helpCache. - self presenterClass emptyHelpCache. - browser := self presenterClass openOnHelpFolder: - FileSystem workingDirectory - / 'ojdoajdjvsaidqsjkjfzeuican'. - rootTopic := browser rootTopic. - self assert: rootTopic title equals: '/'. - window := browser window ] ensure: [ - self presenterClass helpCache: save ] -] - { #category : #tests } StHelpBrowserPresenterTest >> testOpenOnSystemHelp2 [ @@ -283,140 +121,3 @@ StHelpBrowserPresenterTest >> testOpenOnSystemHelp2 [ self assert: rootTopic icon isNil. window := browser openWithSpec ] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotHelpTopicVisitorPerDefault [ - - | visitor browser | - browser := self presenterClass new. - visitor := browser helpTopicVisitor. - self assert: visitor equals: StTopicBuilderVisitor -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotHelpTopicVisitorThatISpecify [ - - | visitor browser | - browser := self presenterClass new. - browser helpTopicVisitor: StTopicBuilderVisitor. - visitor := browser helpTopicVisitor. - self assert: visitor equals: StTopicBuilderVisitor -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotRootTopicThatISpecify [ - - | topic browser | - browser := self presenterClass new. - topic := self helpTopicClass named: 'Test'. - browser rootTopic: topic. - self assert: browser rootTopic equals: topic -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotTopicsPerDefault [ - - | topic browser | - browser := self presenterClass new. - topic := browser rootTopic. - self assert: topic title equals: 'Help' -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserGotTopicsThatISpecify [ - - | topic browser | - browser := self presenterClass new. - browser rootTopic: (self helpTopicClass named: 'foo'). - topic := browser rootTopic. - self assert: topic title equals: 'foo' -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterDocTopicFromFileSystemOnFile [ - - | file browser rootTopic | - file := filesystem workingDirectory / 'fd1.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - browser := self presenterClass new. - rootTopic := browser createTopicsFromFileOrFolder: file. - self assert: rootTopic size equals: 2 -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterDocTopicFromSystem [ - - | file directory browser rootTopic | - filesystem createDirectory: 'test'. - directory := filesystem workingDirectory / 'test'. - file := filesystem workingDirectory / 'test/fd1.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - browser := self presenterClass new. - rootTopic := (browser createRootTopicFromFolder: directory) rootTopic. - self assert: rootTopic subtopics size equals: 2 -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterOpenADirectory [ - - | directory browser | - directory := filesystem workingDirectory / self class spDirectoryName. - filesystem createDirectory: self class spDirectoryName. - browser := self presenterClass new. - browser createRootTopicFromFolder: directory. - - self - assert: browser rootTopic title - equals: directory basenameWithoutExtension capitalized -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterTopicFromSystemOnDirectoryWithFiles [ - - | directory file1 file2 browser rootTopic | - filesystem createDirectory: 'test'. - directory := filesystem workingDirectory / 'test'. - - - file1 := filesystem workingDirectory / 'test/fd1.mic'. - file1 writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - - file2 := filesystem workingDirectory / 'test/fd2.mic'. - file2 writeStreamDo: [ :stream | stream nextPutAll: self class spFd2 ]. - - browser := self presenterClass new. - rootTopic := (browser createRootTopicFromFolder: directory) rootTopic. - self assert: rootTopic subtopics size equals: 3 -] - -{ #category : #tests } -StHelpBrowserPresenterTest >> testSpHelpBrowserPresenterTopicFromSystemOnFile [ - - | file browser rootTopic | - file := filesystem workingDirectory / 'fd1.mic'. - file writeStreamDo: [ :stream | stream nextPutAll: self class spFd1 ]. - browser := self presenterClass new. - rootTopic := (browser createRootTopicFromFolder: file) rootTopic. - self assert: rootTopic subtopics size equals: 2 -] - -{ #category : #'tests - cache' } -StHelpBrowserPresenterTest >> testTopicsWithCacheFrom [ - - | docFolder file browser save | - [ - save := self presenterClass helpCache. - - filesystem createDirectory: 'doc'. - docFolder := filesystem workingDirectory / 'doc'. - file := filesystem workingDirectory / 'doc' / 'file.mic'. - file writeStreamDo: [ :stream | - stream nextPutAll: '# section -this is a text' ]. - self presenterClass internalizeHelpFrom: docFolder. - browser := self presenterClass open. - window := browser window. - self assert: browser rootTopic title equals: 'Doc'. - self assert: browser rootTopic subtopics size equals: 1 ] ensure: [ - self presenterClass helpCache: save ] -] diff --git a/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st b/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st index bc9996b..87cd334 100644 --- a/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st +++ b/src/NewTools-DocumentationReader-Tests/StTopicBuilderVisitorTest.class.st @@ -1,10 +1,6 @@ Class { #name : #StTopicBuilderVisitorTest, #superclass : #TestCase, - #instVars : [ - 'filesystem', - 'visitor' - ], #category : #'NewTools-DocumentationReader-Tests' } @@ -70,125 +66,85 @@ StTopicBuilderVisitorTest class >> spFileName [ ^ 'test.md' ] -{ #category : #tests } -StTopicBuilderVisitorTest >> helpTopicClass [ - - ^ StNodeHelpTopic -] - -{ #category : #running } -StTopicBuilderVisitorTest >> setUp [ - super setUp. - filesystem := FileSystem memory. - visitor := StTopicBuilderVisitor new - -] - { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorVisitHeader [ - | file text header | + | text topic | text := '# SectionTest This is a paragraphe'. - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: text ]. - header := (MicroDownParser new parse: file contents) children first. - visitor visitHeader: header. - self assert: visitor helpTopics subtopics first title equals: 'SectionTest'. - self assert: visitor helpTopics subtopics first contents equals: '' + topic := self topicIn: text. + self assert: topic subtopics first title equals: 'SectionTest'. + self assert: topic subtopics first subtopics isEmpty ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorVisitHeaderAtLevel2 [ - | file text header | + | text topic | text := '## SectionTest This is a paragraphe'. - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: text ]. - header := (MicroDownParser new parse: file contents) children first. - visitor visitHeader: header. - self assert: visitor helpTopics subtopics first title equals: 'SectionTest'. - self assert: visitor helpTopics subtopics first contents equals: '' + topic := self topicIn: text. + self assert: topic subtopics first title equals: 'SectionTest'. + self assert: topic subtopics first subtopics isEmpty ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithLevelsSections [ - | file topics | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsLevelsSections ]. - self visitFile: file. - topics := visitor helpTopics subtopics. - self assert: topics first title equals: 'Section 1'. - self assert: topics first subtopics first title equals: 'Section 2'. + | topic | + + topic := self topicIn: self class spFileContentsLevelsSections. + self assert: topic subtopics first title equals: 'Section 1'. + self assert: topic subtopics first subtopics first title equals: 'Section 2'. ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithMoreSections [ - - | file | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsMoreSections ]. - self visitFile: file. - self assert: (visitor helpTopics subtopics second) title equals: 'Section 2'. - self assert: visitor helpTopics subtopics size equals: 2 + | topic | + topic := self topicIn: self class spFileContentsMoreSections. + self assert: topic subtopics second title equals: 'Section 2'. + self assert: topic subtopics size equals: 2 ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithMoreSubSection [ - - | file | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsWithMoreSubSection ]. - self visitFile: file. + | topic | + + topic := self topicIn: self class spFileContentsWithMoreSubSection. self - assert: (visitor helpTopics subtopics first subtopics second) title + assert: (topic subtopics first subtopics second) title equals: 'Section 3'. - self assert: visitor helpTopics subtopics size equals: 1. - self assert: visitor helpTopics subtopics first subtopics size equals: 2 + self assert: topic subtopics size equals: 1. + self assert: topic subtopics first subtopics size equals: 2 ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithOneSection [ - - | file text | - text := ' -blabla -blabla -'. - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsOneSection ]. - self visitFile: file. - self assert: (visitor helpTopics subtopics first) title equals: 'Section 1'. - self assert: visitor helpTopics subtopics size equals: 1 + + | topic | + topic := self topicIn: self class spFileContentsOneSection. + self assert: topic subtopics first title equals: 'Section 1'. + self assert: topic subtopics size equals: 1 ] { #category : #tests } StTopicBuilderVisitorTest >> testTopicBuilderVisitorWithOneSubSection [ - | file | - (file := filesystem workingDirectory / self class spFileName) - writeStreamDo: [ :stream | - stream nextPutAll: self class spFileContentsWithOneSubSection ]. - self visitFile: file. + | topic | + topic := self topicIn: self class spFileContentsWithOneSubSection. self - assert: ((visitor helpTopics subtopics first) subtopics first) title + assert: topic subtopics first subtopics first title equals: 'Section 2'. - self assert: visitor helpTopics subtopics size equals: 1. - self assert: visitor helpTopics subtopics first subtopics size equals: 1 + self assert: topic subtopics size equals: 1. + self assert: topic subtopics first subtopics size equals: 1 ] { #category : #helper } -StTopicBuilderVisitorTest >> visitFile: file [ - - visitor visit: (MicroDownParser new parse: file contents) +StTopicBuilderVisitorTest >> topicIn: aString [ + | visitor | + visitor := StTopicBuilderVisitor new. + visitor visit: (MicroDownParser new parse: aString). + ^ visitor helpTopic ] diff --git a/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st b/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st new file mode 100644 index 0000000..b23f00b --- /dev/null +++ b/src/NewTools-DocumentationReader-Tests/StTopicFromFileFolderBuilderTest.class.st @@ -0,0 +1,179 @@ +" +A StTopicFromFileFolderBuilderTest is a test class for testing the behavior of StTopicFromFileFolderBuilder +" +Class { + #name : #StTopicFromFileFolderBuilderTest, + #superclass : #TestCase, + #instVars : [ + 'docDir', + 'rootTopic' + ], + #category : #'NewTools-DocumentationReader-Tests' +} + +{ #category : #'as yet unclassified' } +StTopicFromFileFolderBuilderTest class >> eyeballTest [ + "This should be able to open the HelpBrowser on the test data" +