From cc8fc77ece1063e280f1f2addd566154141181f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Tue, 21 May 2024 18:43:24 +0200 Subject: [PATCH] Adding some tests + make sure that we can ask any element about the file it was placed on --- src/Microdown-Tests/MicrodownTest.class.st | 46 ++++++++++++++++++++++ src/Microdown/MicElement.class.st | 6 +++ src/Microdown/MicRootBlock.class.st | 5 +++ 3 files changed, 57 insertions(+) diff --git a/src/Microdown-Tests/MicrodownTest.class.st b/src/Microdown-Tests/MicrodownTest.class.st index 874db2d9..9effffbe 100644 --- a/src/Microdown-Tests/MicrodownTest.class.st +++ b/src/Microdown-Tests/MicrodownTest.class.st @@ -4,11 +4,29 @@ A MicrodownTest is a test class for testing the behavior of Microdown Class { #name : 'MicrodownTest', #superclass : 'TestCase', + #instVars : [ + 'file', + 'filesystem' + ], #category : 'Microdown-Tests-Core', #package : 'Microdown-Tests', #tag : 'Core' } +{ #category : 'running' } +MicrodownTest >> setUp [ + super setUp. + filesystem := FileSystem memory. + file := filesystem workingDirectory / 'anExample1.md'. + file writeStreamDo: [ :stream | stream nextPutAll: '# Foo +Pharo is cool + +``` + this is a code snippet +``` +' ]. +] + { #category : 'tests - parent/children' } MicrodownTest >> testAddedAsChildWhenUsingParent [ @@ -45,6 +63,34 @@ MicrodownTest >> testFigureLabelAreNotReified [ ] +{ #category : 'tests' } +MicrodownTest >> testFromFileIfAbsent [ + + | root | + root := Microdown parse: (filesystem workingDirectory / 'anExample1.md') contents. + self deny: root hasFile +] + +{ #category : 'tests' } +MicrodownTest >> testFromFileInAnyElement [ + + | root | + root := Microdown parseFile: filesystem workingDirectory / 'anExample1.md'. + self assert: root children first children first fromFile equals: (filesystem workingDirectory / 'anExample1.md') fullName + + +] + +{ #category : 'tests' } +MicrodownTest >> testFromFileInRootDocument [ + + | root | + root := Microdown parseFile: filesystem workingDirectory / 'anExample1.md'. + self assert: root fromFile equals: (filesystem workingDirectory / 'anExample1.md') fullName + + +] + { #category : 'tests - parent/children' } MicrodownTest >> testMathCaptionIsReified [ "And as such their parent is the math block" diff --git a/src/Microdown/MicElement.class.st b/src/Microdown/MicElement.class.st index 79ff0df2..5bd523c1 100644 --- a/src/Microdown/MicElement.class.st +++ b/src/Microdown/MicElement.class.st @@ -47,6 +47,12 @@ MicElement >> basicParent: aMicBlock [ parent := aMicBlock ] +{ #category : 'accessing' } +MicElement >> fromFile [ + "Let us bubble up to the root to get the file" + ^ self parent fromFile +] + { #category : 'properties' } MicElement >> hasProperty: aKey [ "Answer whether there is a property named aKey." diff --git a/src/Microdown/MicRootBlock.class.st b/src/Microdown/MicRootBlock.class.st index e04f3cc7..bdf4fcd9 100644 --- a/src/Microdown/MicRootBlock.class.st +++ b/src/Microdown/MicRootBlock.class.st @@ -44,6 +44,11 @@ MicRootBlock >> fromFile: aFile [ self propertyAt: #file put: aFile ] +{ #category : 'testing' } +MicRootBlock >> hasFile [ + ^ self hasProperty: #file +] + { #category : 'accessing' } MicRootBlock >> indent [ ^0