import Foundation import Testing @testable import OrgSocialKit /// The App layer keeps mention rewrite logic (encode/decode) close to the /// Compose / Edit views so the lib stays unaware of UI concerns. That said, /// the renderer's inline `@nick` output is part of the public contract — /// it's what callers rely on to display the body. These tests pin the /// renderer behaviour used by both directions. @Suite("OrgBodyRenderer – mention round-trip") struct OrgBodyMentionRoundtripTests { @Test("inline text shows @nick in place of the Org link") func inlineShortForm() { let body = "Hey [[org-social:https://alice.test/social.org][alice]], how are you?" let rendered = OrgBodyRenderer.render(body) let inline = String(rendered.inline.characters) #expect(inline.contains("Hey @alice, how are you?")) #expect(!inline.contains("[[org-social")) } @Test("multiple mentions are each rewritten inline and side-carred") func multipleMentions() { let body = """ [[org-social:https://a.test/social.org][alice]] and \ [[org-social:https://b.test/social.org][bob]] chat. """ let rendered = OrgBodyRenderer.render(body) let inline = String(rendered.inline.characters) #expect(inline.contains("@alice")) #expect(inline.contains("@bob")) #expect(rendered.mentions.count == 2) } @Test("inline mentions carry a link attribute to the feed URL") func inlineLinkAttribute() { let body = "Hi [[org-social:https://alice.test/social.org][alice]]" let rendered = OrgBodyRenderer.render(body) // Walk the runs; find the one over "@alice" and check its link. var foundLink: URL? for run in rendered.inline.runs { let slice = String(rendered.inline[run.range].characters) if slice == "@alice" { foundLink = run.link break } } #expect(foundLink?.absoluteString == "https://alice.test/social.org") } }