Tests/OrgEditorAppKitTests/MarkdownImportGateTests.swift
36 lines · 1951 bytes
1 symbol in this file
1import Foundation
2import OrgApp
3import Testing
4
5/// Gate for File ▸ Import ▸ Obsidian Vault…: planning and writing a vault of 1,000 notes.
6extension GateTests {
7 @Test func importingAThousandNoteVault() async throws {
8 let scratch = try Self.scratch()
9 defer { try? FileManager.default.removeItem(at: scratch) }
10 let vault = scratch.appendingPathComponent("Vault")
11 let destination = scratch.appendingPathComponent("dest")
12 try FileManager.default.createDirectory(at: destination, withIntermediateDirectories: true)
13 try FileManager.default.createDirectory(at: vault.appendingPathComponent("img"), withIntermediateDirectories: true)
14 for n in 0..<1_000 {
15 let dir = vault.appendingPathComponent("area \(n % 10)")
16 try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
17 var text = "---\ntags: [t\(n % 7)]\n---\n# Note \(n) #tag\(n % 5)\n"
18 for p in 0..<10 {
19 text += "Paragraph \(p) with **bold**, *italic*, `code`, [[Note \((n + p + 1) % 1_000)]] and [[Note \((n + 2) % 1_000)#Section]].\n\n"
20 }
21 text += "## Section\n- [ ] task 📅 2026-12-01\n- item\n\n| a | b |\n|---|---|\n| \(n) | x |\n\n![[pic \(n % 20).png]]\n"
22 try Data(text.utf8).write(to: dir.appendingPathComponent("Note \(n).md"))
23 }
24 for k in 0..<20 { try Data("png".utf8).write(to: vault.appendingPathComponent("img/pic \(k).png")) }
25
26 var notes = 0
27 let time = try await ContinuousClock().measure {
28 let plan = try await Task.detached { try MarkdownImport.plan(.obsidian, sources: [vault], into: destination) }.value
29 notes = plan.notes
30 _ = try await Task.detached { try MarkdownImport.write(plan) }.value
31 }
32 print("import 1,000-note vault: \(time)")
33 #expect(notes == 1_000)
34 #expect(time < .seconds(5))
35 }
36}