|
| 1 | +import MarkdownAST |
| 2 | +import MarkdownParsing |
| 3 | +import MarkdownSemantics |
| 4 | +import SourceDiagnostics |
| 5 | +import Testing |
| 6 | + |
| 7 | +@_spi(testable) |
| 8 | +import SymbolGraphLinker |
| 9 | + |
| 10 | +@Suite |
| 11 | +struct Bindings |
| 12 | +{ |
| 13 | + private |
| 14 | + let markdownParser:Markdown.Parser<Markdown.SwiftFlavor> |
| 15 | + private |
| 16 | + var ignore:Diagnostics<SSGC.Symbolicator> |
| 17 | + |
| 18 | + init() |
| 19 | + { |
| 20 | + self.markdownParser = .init() |
| 21 | + self.ignore = .init() |
| 22 | + } |
| 23 | + |
| 24 | + @Test mutating |
| 25 | + func Basic() throws |
| 26 | + { |
| 27 | + let markdown:Markdown.Source = """ |
| 28 | + # ``Taylor`` |
| 29 | +
|
| 30 | + I think for me, um. |
| 31 | + """ |
| 32 | + |
| 33 | + let documentation:SSGC.Supplement = try markdown.parse( |
| 34 | + markdownParser: self.markdownParser, |
| 35 | + snippetsTable: [:], |
| 36 | + diagnostics: &self.ignore) |
| 37 | + |
| 38 | + #expect(documentation.type.binding?.text.string == "Taylor") |
| 39 | + } |
| 40 | + @Test mutating |
| 41 | + func TrailingComment() throws |
| 42 | + { |
| 43 | + let markdown:Markdown.Source = """ |
| 44 | + # ``Taylor`` <!-- Allison --> |
| 45 | +
|
| 46 | + I think for me, um. |
| 47 | + """ |
| 48 | + |
| 49 | + let documentation:SSGC.Supplement = try markdown.parse( |
| 50 | + markdownParser: self.markdownParser, |
| 51 | + snippetsTable: [:], |
| 52 | + diagnostics: &self.ignore) |
| 53 | + |
| 54 | + #expect(documentation.type.binding?.text.string == "Taylor") |
| 55 | + } |
| 56 | + @Test mutating |
| 57 | + func Tutorial() throws |
| 58 | + { |
| 59 | + let markdown:Markdown.Source = """ |
| 60 | + @Tutorial(time: 0) { |
| 61 | + @Intro(title: "How to meet Taylor") { |
| 62 | + Learn how to meet Taylor Swift. |
| 63 | + } |
| 64 | + } |
| 65 | + """ |
| 66 | + let documentation:SSGC.Supplement = try markdown.parse( |
| 67 | + markdownParser: self.markdownParser, |
| 68 | + snippetsTable: [:], |
| 69 | + diagnostics: &self.ignore) |
| 70 | + |
| 71 | + guard |
| 72 | + case .tutorial(let headline) = documentation.type |
| 73 | + else |
| 74 | + { |
| 75 | + Issue.record() |
| 76 | + return |
| 77 | + } |
| 78 | + |
| 79 | + #expect(headline == "How to meet Taylor") |
| 80 | + } |
| 81 | + @Test mutating |
| 82 | + func TutorialUntitled() throws |
| 83 | + { |
| 84 | + let markdown:Markdown.Source = """ |
| 85 | + @Tutorial(time: 0) { |
| 86 | + @Intro(title: "") { |
| 87 | + Learn how to meet Taylor Swift. |
| 88 | + } |
| 89 | + } |
| 90 | + """ |
| 91 | + |
| 92 | + #expect(throws: (any Error).self) |
| 93 | + { |
| 94 | + try markdown.parse( |
| 95 | + markdownParser: self.markdownParser, |
| 96 | + snippetsTable: [:], |
| 97 | + diagnostics: &self.ignore) |
| 98 | + } |
| 99 | + } |
| 100 | + @Test mutating |
| 101 | + func SupplementUntitled() throws |
| 102 | + { |
| 103 | + let markdown:Markdown.Source = """ |
| 104 | + ## ``Taylor`` <!-- Allison --> |
| 105 | +
|
| 106 | + I think for me, um. |
| 107 | + """ |
| 108 | + |
| 109 | + #expect(throws: (any Error).self) |
| 110 | + { |
| 111 | + try markdown.parse( |
| 112 | + markdownParser: self.markdownParser, |
| 113 | + snippetsTable: [:], |
| 114 | + diagnostics: &self.ignore) |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments