import Foundation import Testing @testable import gitbay /// README.org rendered as Org, not Markdown (krz/gitbay-ios#4). The /// markdown block parser turned `#+title:` into a heading and left /// `[[link]]` raw. struct OrgDocumentTests { @Test func titleAndStarHeadingsBecomeHeadings() { let doc = OrgDocument.parse(""" #+title: orgo #+author: krz * Install ** From source """) #expect(doc.blocks == [ .heading(level: 1, text: "orgo"), .heading(level: 1, text: "Install"), .heading(level: 2, text: "From source"), ]) } @Test func metadataOtherThanTitleIsDropped() { let doc = OrgDocument.parse("#+options: toc:nil\n#+startup: showall\n\nProse.") #expect(doc.blocks == [.paragraph("Prose.")]) } @Test func sourceBlocksKeepTheirLanguageAndBody() { let doc = OrgDocument.parse(""" #+begin_src sh gitbay repo list gitbay mr create #+end_src """) #expect(doc.blocks == [ .code(language: "sh", text: "gitbay repo list\ngitbay mr create"), ]) } @Test func examplesAndQuotesAreTheirOwnBlocks() { let doc = OrgDocument.parse(""" #+begin_example $ gitbay whoami #+end_example #+begin_quote SSH is the API. #+end_quote """) #expect(doc.blocks == [ .code(language: "", text: "$ gitbay whoami"), .quote("SSH is the API."), ]) } @Test func bothListFormsParse() { let doc = OrgDocument.parse(""" - one + two 1. first 2) second """) #expect(doc.blocks == [ .bullet(["one", "two"]), .ordered(["first", "second"]), ]) } @Test func aBoldStarLineIsNotAHeading() { // "*bold*" has no space after the star, so it is prose. let doc = OrgDocument.parse("*bold* opening line") #expect(doc.blocks == [.paragraph("*bold* opening line")]) } @Test func paragraphsRunUntilABlankLineOrBlockStart() { let doc = OrgDocument.parse(""" One sentence continued here. * Heading """) #expect(doc.blocks == [ .paragraph("One sentence continued here."), .heading(level: 1, text: "Heading"), ]) } @Test func readmeViewPicksTheRendererByExtension() { // Only the name decides; content is not sniffed. #expect(ReadmeView(name: "README.org", content: "* x").isOrg) #expect(ReadmeView(name: "readme.ORG", content: "* x").isOrg) #expect(!ReadmeView(name: "README.md", content: "# x").isOrg) #expect(!ReadmeView(name: "README", content: "x").isOrg) } }