Create helper extensions for Block and update tests for the Block helper model

Closes: https://github.com/damus-io/damus/pull/1528
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Grimless
2023-09-01 11:32:01 -04:00
committed by William Casarin
parent a64f898df7
commit 6ee0be40e9
8 changed files with 205 additions and 89 deletions

View File

@@ -0,0 +1,56 @@
//
// Block+Tests.swift
// damusTests
//
// Created by Kyle Roucis on 9/1/23.
//
import Foundation
@testable import damus
extension Block {
var asText: String? {
switch self {
case .text(let text):
return text
default:
return nil
}
}
var isText: Bool {
return self.asText != nil
}
var asURL: URL? {
switch self {
case .url(let url):
return url
default:
return nil
}
}
var isURL: Bool {
return self.asURL != nil
}
var asMention: Mention<MentionRef>? {
switch self {
case .mention(let mention):
return mention
default:
return nil
}
}
var asHashtag: String? {
switch self {
case .hashtag(let hashtag):
return hashtag
default:
return nil
}
}
}