Skip to content

Commit

Permalink
Update for Swift6, Swift testing and add editor config (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Sneath <[email protected]>
  • Loading branch information
Alex293 and timsneath authored Nov 30, 2024
1 parent ff716f2 commit 1304b04
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 44 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# editorconfig.org

root = true

[*.swift]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
65 changes: 32 additions & 33 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
import PackageDescription

let dependencies: [Target.Dependency] = [
.product(name: "Algorithms", package: "swift-algorithms"),
.product(name: "Collections", package: "swift-collections"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Algorithms", package: "swift-algorithms"),
.product(name: "Collections", package: "swift-collections"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]

let package = Package(
name: "AdventOfCode",
platforms: [.macOS(.v13), .iOS(.v16), .watchOS(.v9), .tvOS(.v16)],
dependencies: [
.package(
url: "https://github.com/apple/swift-algorithms.git",
.upToNextMajor(from: "1.2.0")),
.package(
url: "https://github.com/apple/swift-collections.git",
.upToNextMajor(from: "1.0.0")),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMajor(from: "1.2.0")),
.package(
url: "https://github.com/apple/swift-format.git",
.upToNextMajor(from: "509.0.0"))
],
targets: [
.executableTarget(
name: "AdventOfCode",
dependencies: dependencies,
resources: [.copy("Data")],
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
),
.testTarget(
name: "AdventOfCodeTests",
dependencies: ["AdventOfCode"] + dependencies,
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
)
]
name: "AdventOfCode",
platforms: [.macOS(.v13), .iOS(.v16), .watchOS(.v9), .tvOS(.v16)],
dependencies: [
.package(
url: "https://github.com/apple/swift-algorithms.git",
.upToNextMajor(from: "1.2.0")),
.package(
url: "https://github.com/apple/swift-collections.git",
.upToNextMajor(from: "1.1.4")),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMajor(from: "1.5.0")),
.package(
url: "https://github.com/swiftformat/swift-format.git",
.upToNextMajor(from: "600.0.0"))
],
targets: [
.executableTarget(
name: "AdventOfCode",
dependencies: dependencies,
resources: [.copy("Data")]
),
.testTarget(
name: "AdventOfCodeTests",
dependencies: ["AdventOfCode"] + dependencies
)
],
swiftLanguageModes: [.v6]
)
2 changes: 1 addition & 1 deletion Sources/AdventDay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@_exported import Collections
import Foundation

protocol AdventDay {
protocol AdventDay: Sendable {
associatedtype Answer = Int

/// The day of the Advent of Code challenge.
Expand Down
9 changes: 5 additions & 4 deletions Tests/AdventDay.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import XCTest
import Testing

@testable import AdventOfCode

// One off test to validate that basic data load testing works
final class AdventDayTests: XCTestCase {
func testInitData() throws {
struct AdventDayTests {

@Test func testInitData() async throws {
let challenge = Day00()
XCTAssertTrue(challenge.data.starts(with: "4514"))
#expect(challenge.data.starts(with: "4514"))
}
}
12 changes: 6 additions & 6 deletions Tests/Day00.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import XCTest
import Testing

@testable import AdventOfCode

// Make a copy of this file for every day to ensure the provided smoke tests
// pass.
final class Day00Tests: XCTestCase {
struct Day00Tests {
// Smoke test data provided in the challenge question
let testData = """
1000
Expand All @@ -24,13 +24,13 @@ final class Day00Tests: XCTestCase {
"""

func testPart1() throws {
@Test func testPart1() async throws {
let challenge = Day00(data: testData)
XCTAssertEqual(String(describing: challenge.part1()), "6000")
#expect(String(describing: challenge.part1()) == "6000")
}

func testPart2() throws {
@Test func testPart2() async throws {
let challenge = Day00(data: testData)
XCTAssertEqual(String(describing: challenge.part2()), "32000")
#expect(String(describing: challenge.part2()) == "32000")
}
}

0 comments on commit 1304b04

Please sign in to comment.