mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Swift Testing for Unit Tests PART 1 (#5119)
* migrated a lot of unit tests to Swift Testing and added a new implementation for deferred fulfillment more tests migration Cleaned the code manually to establish some good patterns more code improvements some more code improvements removed empty tests update project * more pr suggestions and cleanups * removed the TestSetup pattern * fixing claude not reusing tests * pr suggestion + added indent rule to swiftformat so that we can prevent AIs to change that
This commit is contained in:
@@ -7,76 +7,87 @@
|
||||
//
|
||||
|
||||
@testable import ElementX
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
final class GeoURITests: XCTestCase {
|
||||
func testValidPositiveCoordinates() throws {
|
||||
@Suite
|
||||
struct GeoURITests {
|
||||
@Test
|
||||
func validPositiveCoordinates() throws {
|
||||
let string = "geo:53.9980310155285,8.25347900390625;u=10.123"
|
||||
let uri = try XCTUnwrap(GeoURI(string: string))
|
||||
XCTAssertEqual(uri.latitude, 53.9980310155285)
|
||||
XCTAssertEqual(uri.longitude, 8.25347900390625)
|
||||
XCTAssertEqual(uri.uncertainty, 10.123)
|
||||
XCTAssertEqual(uri.string, string)
|
||||
let uri = try #require(GeoURI(string: string))
|
||||
#expect(uri.latitude == 53.9980310155285)
|
||||
#expect(uri.longitude == 8.25347900390625)
|
||||
#expect(uri.uncertainty == 10.123)
|
||||
#expect(uri.string == string)
|
||||
}
|
||||
|
||||
func testValidNegativeCoordinates() throws {
|
||||
|
||||
@Test
|
||||
func validNegativeCoordinates() throws {
|
||||
let string = "geo:-53.9980310155285,-8.25347900390625;u=10"
|
||||
let uri = try XCTUnwrap(GeoURI(string: string))
|
||||
XCTAssertEqual(uri.latitude, -53.9980310155285)
|
||||
XCTAssertEqual(uri.longitude, -8.25347900390625)
|
||||
XCTAssertEqual(uri.uncertainty, 10)
|
||||
XCTAssertEqual(uri.string, string)
|
||||
let uri = try #require(GeoURI(string: string))
|
||||
#expect(uri.latitude == -53.9980310155285)
|
||||
#expect(uri.longitude == -8.25347900390625)
|
||||
#expect(uri.uncertainty == 10)
|
||||
#expect(uri.string == string)
|
||||
}
|
||||
|
||||
func testValidMixedCoordinates() throws {
|
||||
|
||||
@Test
|
||||
func validMixedCoordinates() throws {
|
||||
let string = "geo:53.9980310155285,-8.25347900390625;u=10"
|
||||
let uri = try XCTUnwrap(GeoURI(string: string))
|
||||
XCTAssertEqual(uri.latitude, 53.9980310155285)
|
||||
XCTAssertEqual(uri.longitude, -8.25347900390625)
|
||||
XCTAssertEqual(uri.uncertainty, 10)
|
||||
XCTAssertEqual(uri.string, string)
|
||||
let uri = try #require(GeoURI(string: string))
|
||||
#expect(uri.latitude == 53.9980310155285)
|
||||
#expect(uri.longitude == -8.25347900390625)
|
||||
#expect(uri.uncertainty == 10)
|
||||
#expect(uri.string == string)
|
||||
}
|
||||
|
||||
func testValidCoordinatesNoUncertainty() throws {
|
||||
|
||||
@Test
|
||||
func validCoordinatesNoUncertainty() throws {
|
||||
let string = "geo:53.9980310155285,-8.25347900390625"
|
||||
let uri = try XCTUnwrap(GeoURI(string: string))
|
||||
XCTAssertEqual(uri.latitude, 53.9980310155285)
|
||||
XCTAssertEqual(uri.longitude, -8.25347900390625)
|
||||
XCTAssertNil(uri.uncertainty)
|
||||
XCTAssertEqual(uri.string, string)
|
||||
let uri = try #require(GeoURI(string: string))
|
||||
#expect(uri.latitude == 53.9980310155285)
|
||||
#expect(uri.longitude == -8.25347900390625)
|
||||
#expect(uri.uncertainty == nil)
|
||||
#expect(uri.string == string)
|
||||
}
|
||||
|
||||
func testValidIntegerCoordinates() throws {
|
||||
|
||||
@Test
|
||||
func validIntegerCoordinates() throws {
|
||||
let string = "geo:53,-8;u=35"
|
||||
let uri = try XCTUnwrap(GeoURI(string: string))
|
||||
XCTAssertEqual(uri.latitude, 53)
|
||||
XCTAssertEqual(uri.longitude, -8)
|
||||
XCTAssertEqual(uri.uncertainty, 35)
|
||||
XCTAssertEqual(uri.string, "geo:53,-8;u=35")
|
||||
let uri = try #require(GeoURI(string: string))
|
||||
#expect(uri.latitude == 53)
|
||||
#expect(uri.longitude == -8)
|
||||
#expect(uri.uncertainty == 35)
|
||||
#expect(uri.string == "geo:53,-8;u=35")
|
||||
}
|
||||
|
||||
func testFormattingExponentialNotation() {
|
||||
|
||||
@Test
|
||||
func formattingExponentialNotation() {
|
||||
let uri = GeoURI(latitude: 1e2, longitude: -1e-2, uncertainty: 1e-4)
|
||||
XCTAssertEqual(uri.string, "geo:100,-0.01;u=0.0001")
|
||||
#expect(uri.string == "geo:100,-0.01;u=0.0001")
|
||||
}
|
||||
|
||||
func testInvalidURI1() {
|
||||
|
||||
@Test
|
||||
func invalidURI1() {
|
||||
let string = "geo:53.99803101552848,-8.25347900390625;" // final ; without a u=number
|
||||
XCTAssertNil(GeoURI(string: string))
|
||||
#expect(GeoURI(string: string) == nil)
|
||||
}
|
||||
|
||||
func testInvalidURI2() {
|
||||
|
||||
@Test
|
||||
func invalidURI2() {
|
||||
let string = "geo:53.99803101552848, -8.25347900390625;" // spaces in the middle
|
||||
XCTAssertNil(GeoURI(string: string))
|
||||
#expect(GeoURI(string: string) == nil)
|
||||
}
|
||||
|
||||
func testInvalidURI3() {
|
||||
|
||||
@Test
|
||||
func invalidURI3() {
|
||||
let string = "geo:+53.99803101552848,-8.25347900390625" // '+' before a number
|
||||
XCTAssertNil(GeoURI(string: string))
|
||||
#expect(GeoURI(string: string) == nil)
|
||||
}
|
||||
|
||||
func testInvalidURI4() {
|
||||
|
||||
@Test
|
||||
func invalidURI4() {
|
||||
let string = "geo:53.99803101552848,-8.25347900390625;u=-20" // u is negative
|
||||
XCTAssertNil(GeoURI(string: string))
|
||||
#expect(GeoURI(string: string) == nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user