MarkdownTests.swift (3349B)
1 // 2 // MarkdownTests.swift 3 // damusTests 4 // 5 // Created by Lionello Lunesu on 2022-12-28. 6 // 7 8 import XCTest 9 @testable import damus 10 11 class MarkdownTests: XCTestCase { 12 let md_opts: AttributedString.MarkdownParsingOptions = 13 .init(interpretedSyntax: .inlineOnlyPreservingWhitespace) 14 15 override func setUpWithError() throws { 16 // Put setup code here. This method is called before the invocation of each test method in the class. 17 } 18 19 override func tearDownWithError() throws { 20 // Put teardown code here. This method is called after the invocation of each test method in the class. 21 } 22 23 func test_convert_link() throws { 24 let helper = Markdown() 25 let md = helper.process("prologue https://nostr.build epilogue") 26 let expected = try AttributedString(markdown: "prologue [https://nostr.build](https://nostr.build) epilogue", options: md_opts) 27 XCTAssertEqual(md, expected) 28 } 29 30 func test_convert_link_no_scheme() throws { 31 let helper = Markdown() 32 let md = helper.process("prologue damus.io epilogue") 33 let expected = try AttributedString(markdown: "prologue [damus.io](https://damus.io) epilogue", options: md_opts) 34 XCTAssertEqual(md, expected) 35 } 36 37 func test_longform_rendering() throws { 38 let st = test_damus_state() 39 let artifacts = render_note_content(ev: test_longform_event.event, profiles: st.profiles, privkey: st.keypair.privkey) 40 41 switch artifacts { 42 case .separated: 43 XCTAssert(false) 44 case .parts(let parts): 45 XCTAssertEqual(parts.parts.count, 1) 46 } 47 } 48 49 func test_convert_links() throws { 50 let helper = Markdown() 51 let md = helper.process("prologue damus.io https://nostr.build epilogue") 52 let expected = try AttributedString(markdown: "prologue [damus.io](https://damus.io) [https://nostr.build](https://nostr.build) epilogue", options: md_opts) 53 XCTAssertEqual(md, expected) 54 } 55 56 func test_convert_http() throws { 57 let helper = Markdown() 58 let md = helper.process("prologue http://example.com epilogue") 59 let expected = try AttributedString(markdown: "prologue [http://example.com](http://example.com) epilogue", options: md_opts) 60 XCTAssertEqual(md, expected) 61 } 62 63 func test_convert_mailto() throws { 64 let helper = Markdown() 65 let md = helper.process("prologue test@example.com epilogue") 66 let expected = try AttributedString(markdown: "prologue [test@example.com](mailto:test@example.com) epilogue", options: md_opts) 67 XCTAssertEqual(md, expected) 68 } 69 70 func test_convert_mailto_implicit() throws { 71 let helper = Markdown() 72 let md = helper.process("prologue mailto:test@example.com epilogue") 73 let expected = try AttributedString(markdown: "prologue [mailto:test@example.com](mailto:test@example.com) epilogue", options: md_opts) 74 XCTAssertEqual(md, expected) 75 } 76 77 func test_parse_shrug() throws { 78 let md = Markdown.parse(content: "¯\\_(ツ)_/¯") 79 XCTAssertEqual(NSMutableAttributedString(md).string, "¯\\_(ツ)_/¯") 80 } 81 82 func test_parse_backslash() throws { 83 let md = Markdown.parse(content: "\\a") 84 XCTAssertEqual(NSMutableAttributedString(md).string, "\\a") 85 } 86 87 }