damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

NIP19Tests.swift (2468B)


      1 //
      2 //  NIP19Tests.swift
      3 //  damusTests
      4 //
      5 //  Created by William Casarin on 2023-04-09.
      6 //
      7 
      8 import XCTest
      9 @testable import damus
     10 
     11 final class NIP19Tests: XCTestCase {
     12 
     13     override func setUpWithError() throws {
     14         // Put setup code here. This method is called before the invocation of each test method in the class.
     15     }
     16 
     17     override func tearDownWithError() throws {
     18         // Put teardown code here. This method is called after the invocation of each test method in the class.
     19     }
     20 
     21     /*
     22     func test_parse_nprofile() throws {
     23         let res = parse_note_content(content: .content("nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p")).blocks
     24         XCTAssertEqual(res.count, 1)
     25         let expected_ref = ReferencedId(ref_id: "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", relay_id: "wss://r.x.com", key: "p")
     26         let expected_mention = Mention(index: nil, type: .pubkey, ref: expected_ref)
     27         XCTAssertEqual(res[0], .mention(expected_mention))
     28     }
     29      */
     30 
     31     func test_parse_npub() throws {
     32         let res = parse_note_content(content: .content("nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg ",nil)).blocks
     33         XCTAssertEqual(res.count, 2)
     34         let expected_ref = Pubkey(hex: "7e7e9c42a91bfef19fa929e5fda1b72e0ebc1a4c1141673e2794234d86addf4e")!
     35         let expected_mention: Mention<MentionRef> = Mention(index: nil, ref: .pubkey(expected_ref))
     36         XCTAssertEqual(res[0], .mention(expected_mention))
     37     }
     38     
     39     func test_parse_note() throws {
     40         let res = parse_note_content(content: .content(" nostr:note1s4p70596lv50x0zftuses32t6ck8x6wgd4edwacyetfxwns2jtysux7vep",nil)).blocks
     41         XCTAssertEqual(res.count, 2)
     42         let note_id = NoteId(hex:"8543e7d0bafb28f33c495f2198454bd62c7369c86d72d77704cad2674e0a92c9")!
     43         XCTAssertEqual(res[1], .mention(.any(.note(note_id))))
     44     }
     45     
     46     func test_mention_with_adjacent() throws {
     47         let res = parse_note_content(content: .content(" nostr:note1s4p70596lv50x0zftuses32t6ck8x6wgd4edwacyetfxwns2jtysux7vep?",nil)).blocks
     48         XCTAssertEqual(res.count, 3)
     49         let note_id = NoteId(hex: "8543e7d0bafb28f33c495f2198454bd62c7369c86d72d77704cad2674e0a92c9")!
     50         XCTAssertEqual(res[0], .text(" "))
     51         XCTAssertEqual(res[1], .mention(.any(.note(note_id))))
     52         XCTAssertEqual(res[2], .text("?"))
     53     }
     54     
     55 }