damus

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

commit ef5a3030a68aded431c4b99fafc0aad8efa5425d
parent f0b8dcc5e95131767ef56c041288dc95a753b9ea
Author: Daniel D‘Aquino <daniel@daquino.me>
Date:   Thu,  3 Aug 2023 03:38:49 +0000

Add unit tests surrounding creation of posts with non-latin hashtags, as well as the rendering of non-latin hashtag

Signed-off-by: Daniel D‘Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
AdamusTests/NoteContentViewTests.swift | 27+++++++++++++++++++++++++++
MdamusTests/damusTests.swift | 8+++++---
3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -375,6 +375,7 @@ BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; }; BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */; }; D2277EEA2A089BD5006C3807 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2277EE92A089BD5006C3807 /* Router.swift */; }; + D78525252A7B2EA4002FA637 /* NoteContentViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D78525242A7B2EA4002FA637 /* NoteContentViewTests.swift */; }; E4FA1C032A24BB7F00482697 /* SearchSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4FA1C022A24BB7F00482697 /* SearchSettingsView.swift */; }; E990020F2955F837003BBC5A /* EditMetadataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E990020E2955F837003BBC5A /* EditMetadataView.swift */; }; E9E4ED0B295867B900DD7078 /* ThreadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E4ED0A295867B900DD7078 /* ThreadView.swift */; }; @@ -918,6 +919,7 @@ BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = "<group>"; }; BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = "<group>"; }; D2277EE92A089BD5006C3807 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; }; + D78525242A7B2EA4002FA637 /* NoteContentViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteContentViewTests.swift; sourceTree = "<group>"; }; E4FA1C022A24BB7F00482697 /* SearchSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSettingsView.swift; sourceTree = "<group>"; }; E990020E2955F837003BBC5A /* EditMetadataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditMetadataView.swift; sourceTree = "<group>"; }; E9E4ED0A295867B900DD7078 /* ThreadView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadView.swift; sourceTree = "<group>"; }; @@ -1705,6 +1707,7 @@ 4C4F14A62A2A61A30045A0B9 /* NostrScriptTests.swift */, 4C19AE542A5D977400C90DB7 /* HashtagTests.swift */, 3AAC7A012A60FE72002B50DF /* LocalizationUtilTests.swift */, + D78525242A7B2EA4002FA637 /* NoteContentViewTests.swift */, ); path = damusTests; sourceTree = "<group>"; @@ -2409,6 +2412,7 @@ 501F8C822A0224EB001AFC1D /* KeychainStorageTests.swift in Sources */, 3ACBCB78295FE5C70037388A /* TimeAgoTests.swift in Sources */, 4C4F14A72A2A61A30045A0B9 /* NostrScriptTests.swift in Sources */, + D78525252A7B2EA4002FA637 /* NoteContentViewTests.swift in Sources */, 4C3EA67B28FF7B3900C48A62 /* InvoiceTests.swift in Sources */, 4C363A9E2828A822006E126D /* ReplyTests.swift in Sources */, 4C7D097E2A0C58B900943473 /* WalletConnectTests.swift in Sources */, diff --git a/damusTests/NoteContentViewTests.swift b/damusTests/NoteContentViewTests.swift @@ -0,0 +1,27 @@ +// +// NoteContentViewTests.swift +// damusTests +// +// Created by Daniel D’Aquino on 2023-08-02. +// + +import XCTest +@testable import damus + +class NoteContentViewTests: XCTestCase { + func testRenderBlocksWithNonLatinHashtags() { + let parsed: Blocks = parse_note_content(content: "Damusはかっこいいです #cool #かっこいい", tags: [["t", "かっこいい"]]) + + let testState = test_damus_state() + + let text: NoteArtifactsSeparated = render_blocks(blocks: parsed, profiles: testState.profiles) + let attributedText: AttributedString = text.content.attributed + + let runs: AttributedString.Runs = attributedText.runs + let runArray: [AttributedString.Runs.Run] = Array(runs) + print(runArray.description) + XCTAssertEqual(runArray[1].link?.absoluteString, "damus:t:cool", "Latin-character hashtag is missing. Runs description :\(runArray.description)") + XCTAssertEqual(runArray[3].link?.absoluteString.removingPercentEncoding!, "damus:t:かっこいい", "Non-latin-character hashtag is missing. Runs description :\(runArray.description)") + } + +} diff --git a/damusTests/damusTests.swift b/damusTests/damusTests.swift @@ -180,15 +180,17 @@ class damusTests: XCTestCase { } func testMakeHashtagPost() { - let post = NostrPost(content: "#damus some content #bitcoin derp", references: []) + let post = NostrPost(content: "#damus some content #bitcoin derp #かっこいい wow", references: []) let ev = post_to_event(post: post, keypair: test_keypair_full)! - XCTAssertEqual(ev.tags.count, 2) - XCTAssertEqual(ev.content, "#damus some content #bitcoin derp") + XCTAssertEqual(ev.tags.count, 3) + XCTAssertEqual(ev.content, "#damus some content #bitcoin derp #かっこいい wow") XCTAssertEqual(ev.tags[0][0], "t") XCTAssertEqual(ev.tags[0][1], "damus") XCTAssertEqual(ev.tags[1][0], "t") XCTAssertEqual(ev.tags[1][1], "bitcoin") + XCTAssertEqual(ev.tags[2][0], "t") + XCTAssertEqual(ev.tags[2][1], "かっこいい") } func testParseMentionOnlyText() {