2020-07-13 04:02:53 +00:00
//
// D o c u m e n t T e s t s . s w i f t
// G e m i n i F o r m a t T e s t s
//
// C r e a t e d b y S h a d o w f a c t s o n 7 / 1 2 / 2 0 .
//
import XCTest
@ testable import GeminiFormat
class DocumentTests : XCTestCase {
func testLineText ( ) {
XCTAssertEqual ( Document . Line . text ( " some text " ) . geminiText ( ) , " some text " )
XCTAssertEqual ( Document . Line . link ( URL ( string : " gemini://example.com/foo?bar " ) ! , text : " some link " ) . geminiText ( ) , " => gemini://example.com/foo?bar some link " )
XCTAssertEqual ( Document . Line . link ( URL ( string : " gemini://example.com/foo?bar " ) ! , text : nil ) . geminiText ( ) , " => gemini://example.com/foo?bar " )
XCTAssertEqual ( Document . Line . preformattedToggle ( alt : " blah " ) . geminiText ( ) , " ```blah " )
XCTAssertEqual ( Document . Line . preformattedToggle ( alt : nil ) . geminiText ( ) , " ``` " )
XCTAssertEqual ( Document . Line . preformattedText ( " test " ) . geminiText ( ) , " test " )
XCTAssertEqual ( Document . Line . heading ( " one " , level : . h1 ) . geminiText ( ) , " # one " )
XCTAssertEqual ( Document . Line . heading ( " two " , level : . h2 ) . geminiText ( ) , " ## two " )
XCTAssertEqual ( Document . Line . heading ( " three " , level : . h3 ) . geminiText ( ) , " ### three " )
XCTAssertEqual ( Document . Line . unorderedListItem ( " list item " ) . geminiText ( ) , " * list item " )
XCTAssertEqual ( Document . Line . quote ( " quoted " ) . geminiText ( ) , " > quoted " )
}
func testDocumentText ( ) {
let doc = Document ( url : URL ( string : " gemini://example.com " ) ! , lines : [
. text ( " text " ) ,
. link ( URL ( string : " gemini://example.com/ " ) ! , text : " a link " ) ,
. link ( URL ( string : " gemini://example.com/foo?bar " ) ! , text : nil ) ,
. preformattedToggle ( alt : " blah " ) ,
. preformattedText ( " test " ) ,
. preformattedToggle ( alt : nil ) ,
. heading ( " one " , level : . h1 ) ,
. heading ( " two " , level : . h2 ) ,
. heading ( " three " , level : . h3 ) ,
. unorderedListItem ( " list item " ) ,
. quote ( " quoted " ) ,
] )
XCTAssertEqual ( doc . toGeminiText ( ) , " " "
text
= > gemini : // e x a m p l e . c o m / a l i n k
= > gemini : // e x a m p l e . c o m / f o o ? b a r
` ` ` blah
test
` ` `
# one
# # two
# # # three
* list item
> quoted
" " " )
}
2020-12-22 02:35:51 +00:00
func testGetTitle ( ) {
let h1 = Document ( url : URL ( string : " gemini://example.com/ " ) ! , lines : [
. heading ( " Test " , level : . h1 )
] )
XCTAssertEqual ( h1 . title , " Test " )
let h2 = Document ( url : URL ( string : " gemini://example.com/ " ) ! , lines : [
. heading ( " Test " , level : . h2 )
] )
XCTAssertEqual ( h2 . title , " Test " )
let h3 = Document ( url : URL ( string : " gemini://example.com/ " ) ! , lines : [
. heading ( " Test " , level : . h3 )
] )
XCTAssertEqual ( h3 . title , " Test " )
let multiple = Document ( url : URL ( string : " gemini://example.com/ " ) ! , lines : [
. heading ( " Two " , level : . h2 ) ,
. heading ( " One " , level : . h1 ) ,
. heading ( " Three " , level : . h3 ) ,
] )
XCTAssertEqual ( multiple . title , " Two " )
}
2020-07-13 04:02:53 +00:00
}