Skip to content

Commit 706ea17

Browse files
committed
run ci on ubuntu with swift testing
1 parent f56e831 commit 706ea17

File tree

3 files changed

+167
-163
lines changed

3 files changed

+167
-163
lines changed

.github/workflows/test.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ on:
1010
branches: ["main"]
1111

1212
jobs:
13-
build:
14-
runs-on: macos-latest
15-
13+
linux_test:
14+
name: Test Linux
15+
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- name: Build
19-
run: swift build -v
20-
- name: Run tests
21-
run: swift test -v
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Install swiftly
20+
run: curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash -s -- -y
21+
- name: Install the latest Swift toolchain
22+
run: swiftly install latest
23+
- name: Test
24+
run: swift test --enable-code-coverage

Package.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.10
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -20,7 +20,7 @@ let package = Package(
2020
],
2121
dependencies: [
2222
// Dependencies declare other packages that this package depends on.
23-
// .package(url: /* package url */, from: "1.0.0"),
23+
.package(url: "https://github.com/apple/swift-testing.git", from: "0.99.0"),
2424
],
2525
targets: [
2626
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -31,7 +31,10 @@ let package = Package(
3131
),
3232
.testTarget(
3333
name: "QuiltTests",
34-
dependencies: ["Quilt"]
34+
dependencies: [
35+
"Quilt",
36+
.product(name: "Testing", package: "swift-testing"),
37+
]
3538
),
3639
]
3740
)

Tests/QuiltTests/QuiltTests.swift

+150-152
Original file line numberDiff line numberDiff line change
@@ -5,171 +5,169 @@
55
// Created by Theodore Lampert on 29.01.23.
66
//
77

8+
import Foundation
9+
import Testing
810
@testable import Quilt
911
import XCTest
1012

11-
final class QuiltTests: XCTestCase {
12-
// MARK: - Test Setup
13-
let user = UUID(uuidString: "E2DFDB75-A3D9-4B55-9312-111EF297D566")!
14-
let otherUser = UUID(uuidString: "F3DFDB75-A3D9-4B55-9312-111EF297D567")!
13+
let user = UUID(uuidString: "E2DFDB75-A3D9-4B55-9312-111EF297D566")!
14+
let otherUser = UUID(uuidString: "F3DFDB75-A3D9-4B55-9312-111EF297D567")!
1515

16-
func testAddRemoveOps() throws {
17-
var quilt = Quilt(user: user)
1816

19-
quilt.insert(character: "T", atIndex: 0)
17+
@Test func testAddRemoveOps() throws {
18+
var quilt = Quilt(user: user)
2019

21-
XCTAssertEqual(
22-
quilt.operations[0],
23-
Operation(
24-
opId: OpID(counter: 0, id: user),
25-
type: .insert("T"),
26-
afterId: nil
27-
)
20+
quilt.insert(character: "T", atIndex: 0)
21+
22+
XCTAssertEqual(
23+
quilt.operations[0],
24+
Operation(
25+
opId: OpID(counter: 0, id: user),
26+
type: .insert("T"),
27+
afterId: nil
2828
)
29+
)
2930

30-
quilt.insert(character: "H", atIndex: 1)
31+
quilt.insert(character: "H", atIndex: 1)
3132

32-
XCTAssertEqual(
33-
quilt.operations[1],
34-
Operation(
35-
opId: OpID(counter: 1, id: user),
36-
type: .insert("H"),
37-
afterId: quilt.operations[0].id
38-
)
33+
XCTAssertEqual(
34+
quilt.operations[1],
35+
Operation(
36+
opId: OpID(counter: 1, id: user),
37+
type: .insert("H"),
38+
afterId: quilt.operations[0].id
3939
)
40+
)
41+
42+
quilt.remove(atIndex: 1)
43+
44+
XCTAssertEqual(
45+
quilt.operations[2],
46+
Operation(
47+
opId: OpID(counter: 2, id: user),
48+
type: .remove(quilt.operations[1].id)
49+
)
50+
)
51+
}
4052

41-
quilt.remove(atIndex: 1)
53+
@Test func testAddRemoveMarkOps() throws {
54+
var quilt = Quilt(user: user)
55+
quilt.insert(character: "H", atIndex: 0)
56+
quilt.insert(character: "e", atIndex: 1)
57+
quilt.insert(character: "l", atIndex: 2)
58+
quilt.insert(character: "l", atIndex: 3)
59+
quilt.insert(character: "o", atIndex: 4)
4260

43-
XCTAssertEqual(
44-
quilt.operations[2],
45-
Operation(
46-
opId: OpID(counter: 2, id: user),
47-
type: .remove(quilt.operations[1].id)
48-
)
61+
quilt.addMark(mark: .bold, fromIndex: 0, toIndex: 4)
62+
63+
XCTAssertEqual(quilt.operations[5], Operation(
64+
opId: OpID(counter: 5, id: user),
65+
type: .addMark(
66+
type: .bold,
67+
start: .before(OpID(counter: 0, id: user)),
68+
end: .before(OpID(counter: 4, id: user))
4969
)
50-
}
51-
52-
func testAddRemoveMarkOps() throws {
53-
var quilt = Quilt(user: user)
54-
quilt.insert(character: "H", atIndex: 0)
55-
quilt.insert(character: "e", atIndex: 1)
56-
quilt.insert(character: "l", atIndex: 2)
57-
quilt.insert(character: "l", atIndex: 3)
58-
quilt.insert(character: "o", atIndex: 4)
59-
60-
quilt.addMark(mark: .bold, fromIndex: 0, toIndex: 4)
61-
62-
XCTAssertEqual(quilt.operations[5], Operation(
63-
opId: OpID(counter: 5, id: user),
64-
type: .addMark(
65-
type: .bold,
66-
start: .before(OpID(counter: 0, id: user)),
67-
end: .before(OpID(counter: 4, id: user))
68-
)
69-
))
70-
71-
quilt.removeMark(
72-
mark: .bold,
73-
fromIndex: 0,
74-
toIndex: 4
70+
))
71+
72+
quilt.removeMark(
73+
mark: .bold,
74+
fromIndex: 0,
75+
toIndex: 4
76+
)
77+
78+
XCTAssertEqual(quilt.operations[6], Operation(
79+
opId: OpID(counter: 6, id: user),
80+
type: .removeMark(
81+
type: .bold,
82+
start: .before(OpID(counter: 0, id: user)),
83+
end: .before(OpID(counter: 4, id: user))
7584
)
85+
))
86+
}
87+
88+
@Test func testArraySafeIndex() {
89+
let array = [1, 2, 3]
90+
91+
XCTAssertEqual(array[safeIndex: 0], 1)
92+
XCTAssertEqual(array[safeIndex: 2], 3)
93+
XCTAssertNil(array[safeIndex: -1])
94+
XCTAssertNil(array[safeIndex: 3])
95+
}
96+
97+
// MARK: - OpID Tests
98+
99+
@Test func testOpIDComparison() {
100+
let id1 = OpID(counter: 1, id: user)
101+
let id2 = OpID(counter: 2, id: user)
102+
let id3 = OpID(counter: 2, id: otherUser)
103+
104+
XCTAssertLessThan(id1, id2)
105+
XCTAssertGreaterThan(id2, id1)
106+
107+
// Test same counter, different UUIDs
108+
XCTAssertNotEqual(id2, id3)
109+
// Since user UUID < otherUser UUID
110+
XCTAssertLessThan(id2, id3)
111+
}
112+
113+
@Test func testOpIDDescription() {
114+
let id = OpID(counter: 42, id: user)
115+
XCTAssertEqual(id.description, "42@\(user)")
116+
}
117+
118+
// MARK: - Quilt Merge Tests
119+
120+
@Test func testMergeQuilt() {
121+
var quilt1 = Quilt(user: user)
122+
var quilt2 = Quilt(user: otherUser)
123+
124+
quilt1.insert(character: "A", atIndex: 0)
125+
quilt2.insert(character: "B", atIndex: 0)
126+
127+
quilt1.merge(quilt2)
128+
129+
XCTAssertEqual(quilt1.operations.count, 2)
130+
XCTAssertEqual(quilt1.appliedOps.count, 2)
131+
}
132+
133+
@Test func testMergeDuplicateOperations() {
134+
var quilt1 = Quilt(user: user)
135+
var quilt2 = Quilt(user: otherUser) // Changed to different user
136+
137+
quilt1.insert(character: "A", atIndex: 0)
138+
quilt2.operations = quilt1.operations
139+
quilt2.insert(character: "B", atIndex: 1)
140+
141+
quilt1.merge(quilt2)
142+
143+
// Should add both operations since they're from different users
144+
XCTAssertEqual(quilt1.operations.count, 2)
145+
XCTAssertEqual(quilt1.appliedOps.count, 2)
146+
}
147+
148+
// MARK: - Edge Cases Tests
149+
150+
@Test func testRemoveFromEmptyQuilt() {
151+
var quilt = Quilt(user: user)
152+
153+
// Should not crash
154+
quilt.remove(atIndex: 0)
155+
XCTAssertEqual(quilt.operations.count, 0)
156+
}
157+
158+
@Test func testRemoveFromInvalidIndex() {
159+
var quilt = Quilt(user: user)
160+
quilt.insert(character: "A", atIndex: 0)
161+
162+
// Should not crash and should add the remove operation
163+
quilt.remove(atIndex: 1)
164+
XCTAssertEqual(quilt.operations.count, 2)
165+
}
166+
167+
@Test func testInsertAtInvalidIndex() {
168+
var quilt = Quilt(user: user)
76169

77-
XCTAssertEqual(quilt.operations[6], Operation(
78-
opId: OpID(counter: 6, id: user),
79-
type: .removeMark(
80-
type: .bold,
81-
start: .before(OpID(counter: 0, id: user)),
82-
end: .before(OpID(counter: 4, id: user))
83-
)
84-
))
85-
}
86-
87-
// MARK: - Array Extension Tests
88-
89-
func testArraySafeIndex() {
90-
let array = [1, 2, 3]
91-
92-
XCTAssertEqual(array[safeIndex: 0], 1)
93-
XCTAssertEqual(array[safeIndex: 2], 3)
94-
XCTAssertNil(array[safeIndex: -1])
95-
XCTAssertNil(array[safeIndex: 3])
96-
}
97-
98-
// MARK: - OpID Tests
99-
100-
func testOpIDComparison() {
101-
let id1 = OpID(counter: 1, id: user)
102-
let id2 = OpID(counter: 2, id: user)
103-
let id3 = OpID(counter: 2, id: otherUser)
104-
105-
XCTAssertLessThan(id1, id2)
106-
XCTAssertGreaterThan(id2, id1)
107-
108-
// Test same counter, different UUIDs
109-
XCTAssertNotEqual(id2, id3)
110-
// Since user UUID < otherUser UUID
111-
XCTAssertLessThan(id2, id3)
112-
}
113-
114-
func testOpIDDescription() {
115-
let id = OpID(counter: 42, id: user)
116-
XCTAssertEqual(id.description, "42@\(user)")
117-
}
118-
119-
// MARK: - Quilt Merge Tests
120-
121-
func testMergeQuilt() {
122-
var quilt1 = Quilt(user: user)
123-
var quilt2 = Quilt(user: otherUser)
124-
125-
quilt1.insert(character: "A", atIndex: 0)
126-
quilt2.insert(character: "B", atIndex: 0)
127-
128-
quilt1.merge(quilt2)
129-
130-
XCTAssertEqual(quilt1.operations.count, 2)
131-
XCTAssertEqual(quilt1.appliedOps.count, 2)
132-
}
133-
134-
func testMergeDuplicateOperations() {
135-
var quilt1 = Quilt(user: user)
136-
var quilt2 = Quilt(user: otherUser) // Changed to different user
137-
138-
quilt1.insert(character: "A", atIndex: 0)
139-
quilt2.operations = quilt1.operations
140-
quilt2.insert(character: "B", atIndex: 1)
141-
142-
quilt1.merge(quilt2)
143-
144-
// Should add both operations since they're from different users
145-
XCTAssertEqual(quilt1.operations.count, 2)
146-
XCTAssertEqual(quilt1.appliedOps.count, 2)
147-
}
148-
149-
// MARK: - Edge Cases Tests
150-
151-
func testRemoveFromEmptyQuilt() {
152-
var quilt = Quilt(user: user)
153-
154-
// Should not crash
155-
quilt.remove(atIndex: 0)
156-
XCTAssertEqual(quilt.operations.count, 0)
157-
}
158-
159-
func testRemoveFromInvalidIndex() {
160-
var quilt = Quilt(user: user)
161-
quilt.insert(character: "A", atIndex: 0)
162-
163-
// Should not crash and should add the remove operation
164-
quilt.remove(atIndex: 1)
165-
XCTAssertEqual(quilt.operations.count, 2)
166-
}
167-
168-
func testInsertAtInvalidIndex() {
169-
var quilt = Quilt(user: user)
170-
171-
// Should still work by inserting at the end
172-
quilt.insert(character: "A", atIndex: 999)
173-
XCTAssertEqual(quilt.operations.count, 1)
174-
}
170+
// Should still work by inserting at the end
171+
quilt.insert(character: "A", atIndex: 999)
172+
XCTAssertEqual(quilt.operations.count, 1)
175173
}

0 commit comments

Comments
 (0)