mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 23:45:18 +00:00
* Expand coverage for transport, chat, and media flows * Stabilize transport and media coverage tests --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
51 lines
1.8 KiB
Swift
51 lines
1.8 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import bitchat
|
|
|
|
@Suite("AutocompleteService Tests")
|
|
struct AutocompleteServiceTests {
|
|
|
|
@Test("Mention suggestions are sorted, capped, and include replacement range")
|
|
func mentionSuggestionsAreSortedAndCapped() {
|
|
let service = AutocompleteService()
|
|
let text = "hi @al"
|
|
|
|
let result = service.getSuggestions(
|
|
for: text,
|
|
peers: ["zoe", "alice", "albert", "bob", "alex", "ally", "alpha"],
|
|
cursorPosition: text.count
|
|
)
|
|
|
|
#expect(result.suggestions == ["@albert", "@alex", "@alice", "@ally", "@alpha"])
|
|
#expect(result.range == NSRange(location: 3, length: 3))
|
|
}
|
|
|
|
@Test("Suggestions are empty when cursor is not at a trailing mention")
|
|
func suggestionsRequireTrailingMentionContext() {
|
|
let service = AutocompleteService()
|
|
let text = "hi @al there"
|
|
|
|
let result = service.getSuggestions(
|
|
for: text,
|
|
peers: ["alice", "albert"],
|
|
cursorPosition: text.count
|
|
)
|
|
|
|
#expect(result.suggestions.isEmpty)
|
|
#expect(result.range == nil)
|
|
}
|
|
|
|
@Test("Applying suggestions replaces the range and adds command spacing only when needed")
|
|
func applySuggestionReplacesRangeAndHandlesCommandSpacing() {
|
|
let service = AutocompleteService()
|
|
|
|
let mentionResult = service.applySuggestion("@alice", to: "hi @al", range: NSRange(location: 3, length: 3))
|
|
let msgCommand = service.applySuggestion("/msg", to: "/m", range: NSRange(location: 0, length: 2))
|
|
let clearCommand = service.applySuggestion("/clear", to: "/c", range: NSRange(location: 0, length: 2))
|
|
|
|
#expect(mentionResult == "hi @alice")
|
|
#expect(msgCommand == "/msg ")
|
|
#expect(clearCommand == "/clear")
|
|
}
|
|
}
|