a native ios client for gitbay

client ios swift

https://gitbay.org

gitbayTests/ReadmeOrgTests.swift

ui-smoke
gitbay-ios/gitbayTests/ReadmeOrgTests.swift history · blame · raw

98 lines · 2916 bytes

 1import Foundation
 2import Testing
 3@testable import gitbay
 4
 5/// README.org rendered as Org, not Markdown (krz/gitbay-ios#4). The
 6/// markdown block parser turned `#+title:` into a heading and left
 7/// `[[link]]` raw.
 8struct OrgDocumentTests {
 9
10    @Test func titleAndStarHeadingsBecomeHeadings() {
11        let doc = OrgDocument.parse("""
12            #+title: orgo
13            #+author: krz
14
15            * Install
16            ** From source
17            """)
18
19        #expect(doc.blocks == [
20            .heading(level: 1, text: "orgo"),
21            .heading(level: 1, text: "Install"),
22            .heading(level: 2, text: "From source"),
23        ])
24    }
25
26    @Test func metadataOtherThanTitleIsDropped() {
27        let doc = OrgDocument.parse("#+options: toc:nil\n#+startup: showall\n\nProse.")
28        #expect(doc.blocks == [.paragraph("Prose.")])
29    }
30
31    @Test func sourceBlocksKeepTheirLanguageAndBody() {
32        let doc = OrgDocument.parse("""
33            #+begin_src sh
34            gitbay repo list
35            gitbay mr create
36            #+end_src
37            """)
38        #expect(doc.blocks == [
39            .code(language: "sh", text: "gitbay repo list\ngitbay mr create"),
40        ])
41    }
42
43    @Test func examplesAndQuotesAreTheirOwnBlocks() {
44        let doc = OrgDocument.parse("""
45            #+begin_example
46            $ gitbay whoami
47            #+end_example
48
49            #+begin_quote
50            SSH is the API.
51            #+end_quote
52            """)
53        #expect(doc.blocks == [
54            .code(language: "", text: "$ gitbay whoami"),
55            .quote("SSH is the API."),
56        ])
57    }
58
59    @Test func bothListFormsParse() {
60        let doc = OrgDocument.parse("""
61            - one
62            + two
63
64            1. first
65            2) second
66            """)
67        #expect(doc.blocks == [
68            .bullet(["one", "two"]),
69            .ordered(["first", "second"]),
70        ])
71    }
72
73    @Test func aBoldStarLineIsNotAHeading() {
74        // "*bold*" has no space after the star, so it is prose.
75        let doc = OrgDocument.parse("*bold* opening line")
76        #expect(doc.blocks == [.paragraph("*bold* opening line")])
77    }
78
79    @Test func paragraphsRunUntilABlankLineOrBlockStart() {
80        let doc = OrgDocument.parse("""
81            One sentence
82            continued here.
83            * Heading
84            """)
85        #expect(doc.blocks == [
86            .paragraph("One sentence continued here."),
87            .heading(level: 1, text: "Heading"),
88        ])
89    }
90
91    @Test func readmeViewPicksTheRendererByExtension() {
92        // Only the name decides; content is not sniffed.
93        #expect(ReadmeView(name: "README.org", content: "* x").isOrg)
94        #expect(ReadmeView(name: "readme.ORG", content: "* x").isOrg)
95        #expect(!ReadmeView(name: "README.md", content: "# x").isOrg)
96        #expect(!ReadmeView(name: "README", content: "x").isOrg)
97    }
98}