SPB Git

Repository Public

MarkdownTests.swift 3.1 KB 72 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Tests/CoreTests/MarkdownTests.swift3// Description: Block parsing of agent reports, including a document cut in the middle of streaming.4import Testing5@testable import VQuantCore67@Suite struct MarkdownTests {8    @Test func reportStructure() {9        let md = """10        # Titre11        Un paragraphe12        sur deux lignes.1314        | Société | Prix | Var. |15        |:--|--:|:-:|16        | Apple | 352,45 | +0,1 % |17        | A \\| B | `x|y` |1819        ![Figure 1 — Tendance](/figures/fig-1-0.png)2021        - un22          - deux23        1. premier24        2) second2526        > citation27        > suite2829        ---30        ```python31        print("| pas une table |")32        ```33        $$34        \\sigma^2_t = \\omega35        $$36        """37        let b = MarkdownParser.parse(md)38        #expect(b[0] == .heading(level: 1, text: "Titre"))39        #expect(b[1] == .paragraph("Un paragraphe\nsur deux lignes."))40        #expect(b[2] == .table(header: ["Société", "Prix", "Var."], rows: [["Apple", "352,45", "+0,1 %"], ["A | B", "`x|y`", ""]], alignments: [.leading, .trailing, .center]))41        #expect(b[3] == .image(alt: "Figure 1 — Tendance", url: "/figures/fig-1-0.png"))42        #expect(b[4] == .list(items: [.init(depth: 0, marker: "•", text: "un"), .init(depth: 1, marker: "•", text: "deux"), .init(depth: 0, marker: "1.", text: "premier"), .init(depth: 0, marker: "2.", text: "second")]))43        #expect(b[5] == .quote("citation\nsuite"))44        #expect(b[6] == .rule)45        #expect(b[7] == .code(language: "python", text: "print(\"| pas une table |\")"))46        #expect(b[8] == .math("\\sigma^2_t = \\omega"))47        #expect(b.count == 9)48    }4950    @Test func streamingDocumentWithOpenFence() {51        let b = MarkdownParser.parse("Texte\n```python\nx = 1\ny = ")52        #expect(b == [.paragraph("Texte"), .code(language: "python", text: "x = 1\ny = ")])53        #expect(MarkdownParser.parse("| a | b |") == [.paragraph("| a | b |")])   // header alone is not yet a table54        #expect(MarkdownParser.parse("") == [])55    }5657    @Test func notHeadingsOrLists() {58        #expect(MarkdownParser.parse("#hashtag") == [.paragraph("#hashtag")])59        #expect(MarkdownParser.parse("-5 % sur la séance") == [.paragraph("-5 % sur la séance")])60        #expect(MarkdownParser.parse("2026. Une année") == [.list(items: [.init(depth: 0, marker: "2026.", text: "Une année")])])61        #expect(MarkdownParser.parse("Texte ![x](y) en ligne") == [.paragraph("Texte ![x](y) en ligne")])62    }6364    @Test func markers() {65        #expect(ReportMarkers.split(":gold: Apple :up: +2 %") == [.marker("gold"), .text(" Apple "), .marker("up"), .text(" +2 %")])66        #expect(ReportMarkers.split("ratio 3:1:2 et https://x/a:up:/b") == [.text("ratio 3:1:2 et https://x/a:up:/b")])67        #expect(ReportMarkers.split("✅ validé") == [.marker("check"), .text(" validé")])68        #expect(ReportMarkers.split(":unknown: reste") == [.text(":unknown: reste")])69        #expect(ReportMarkers.split("12:30:00") == [.text("12:30:00")])70    }71}72
Files main
Menu

Theme