Tusker/Packages/ComposeUI/Tests/ComposeUITests/CharacterCounterTests.swift

51 lines
1.9 KiB
Swift
Raw Normal View History

2018-09-29 21:16:45 -04:00
//
// CharacterCounterTests.swift
2023-05-08 16:58:50 -04:00
// ComposeUITests
2018-09-29 21:16:45 -04:00
//
// Created by Shadowfacts on 9/29/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import XCTest
2023-05-08 16:58:50 -04:00
@testable import ComposeUI
import InstanceFeatures
2018-09-29 21:16:45 -04:00
class CharacterCounterTests: XCTestCase {
override func setUp() {
}
override func tearDown() {
}
2023-05-08 16:58:50 -04:00
let features = InstanceFeatures()
2018-09-29 21:16:45 -04:00
2018-09-29 22:20:17 -04:00
func testCountEmpty() {
2023-05-08 16:58:50 -04:00
XCTAssertEqual(CharacterCounter.count(text: "", for: features), 0)
2018-09-29 22:20:17 -04:00
}
2018-09-29 21:16:45 -04:00
func testCountPlainText() {
2023-05-08 16:58:50 -04:00
XCTAssertEqual(CharacterCounter.count(text: "This is an example message", for: features), 26)
XCTAssertEqual(CharacterCounter.count(text: "This is an example message with an Emoji: 😄", for: features), 43)
XCTAssertEqual(CharacterCounter.count(text: "😄😄😄😄😄😄😄", for: features), 7)
2018-09-29 21:16:45 -04:00
}
func testCountLinks() {
2023-05-08 16:58:50 -04:00
XCTAssertEqual(CharacterCounter.count(text: "This is an example with a link: https://example.com", for: features), 55)
XCTAssertEqual(CharacterCounter.count(text: "This is an example with a link 😄: https://example.com", for: features), 57)
XCTAssertEqual(CharacterCounter.count(text: "😄😄😄😄😄😄😄: https://example.com", for: features), 32)
XCTAssertEqual(CharacterCounter.count(text: "This is an example with a link: https://a.much.longer.example.com/link?foo=bar#baz", for: features), 55)
2018-09-29 21:16:45 -04:00
}
func testCountLocalMentions() {
2023-05-08 16:58:50 -04:00
XCTAssertEqual(CharacterCounter.count(text: "hello @example", for: features), 14)
XCTAssertEqual(CharacterCounter.count(text: "@some_really_long_name", for: features), 22)
2018-09-29 21:16:45 -04:00
}
func testCountRemoteMentions() {
2023-05-08 16:58:50 -04:00
XCTAssertEqual(CharacterCounter.count(text: "hello @example@some.remote.social", for: features), 14)
XCTAssertEqual(CharacterCounter.count(text: "hello @some_really_long_name@some-long.remote-instance.social", for: features), 28)
2018-09-29 21:16:45 -04:00
}
}