Cotton code
28 lines · 1.1 KB · SwiftRaw
// A markdown table on a page is a table, never pipes (295 E12). Every text is invented.import XCTest@testable import CottonUIfinal class MarkdownTableTests: XCTestCase {    /// RULE: A row of pipes over a dash separator is a table — its head, then each row padded or cut to the head's cells — and the lines around it stay what they were; pipes with no separator under them are words.    func testAPipeTableIsATableAndPipesWithoutASeparatorAreWords() {        let blocks = MarkdownBlocks.parse("""        Before.        | Fern | Water |        |:---|---:|        | Invented fern | Weekly |        | Cactus |        After.        a | b        """)        XCTAssertEqual(blocks, [            .line("Before."),            .table(header: ["Fern", "Water"], rows: [["Invented fern", "Weekly"], ["Cactus", ""]]),            .line("After."),            .line("a | b"),        ])        XCTAssertEqual(MarkdownBlocks.parse("| a |\n|---|"), [.table(header: ["a"], rows: [])])        XCTAssertEqual(MarkdownBlocks.parse("| a | b |\n| c | d |"), [.line("| a | b |"), .line("| c | d |")])    }}