diff --git a/exercises/concept/log-lines/.docs/hints.md b/exercises/concept/log-lines/.docs/hints.md index fe10cc87..68c73e24 100644 --- a/exercises/concept/log-lines/.docs/hints.md +++ b/exercises/concept/log-lines/.docs/hints.md @@ -16,5 +16,5 @@ - The keyword `self` refers to the enum value inside a method's body. [string-docs]: https://developer.apple.com/documentation/swift/string/ -[switch-statement]: https://docs.swift.org/swift-book/LanguageGuide/ControlFlow.html#ID129 -[enum-raw-values]: https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html#ID149 +[switch-statement]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/controlflow/#Switch +[enum-raw-values]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/enumerations/#Raw-Values diff --git a/exercises/concept/log-lines/.docs/instructions.md b/exercises/concept/log-lines/.docs/instructions.md index efe6c7a0..6e8b7f08 100644 --- a/exercises/concept/log-lines/.docs/instructions.md +++ b/exercises/concept/log-lines/.docs/instructions.md @@ -33,14 +33,15 @@ Next, implement the `LogLevel` initializer to parse the log level of a log line: ```swift LogLevel("[INF]: File deleted") -// => LogLevel.info +// returns LogLevel.info LogLevel("Something went wrong!") -// => LogLevel.unknown +// returns LogLevel.unknown ``` ## 3. Convert log line to short format -The log level of a log line is quite verbose. To reduce the disk space needed to store the log lines, a short format is developed: `":"`. +The log level of a log line is quite verbose. +To reduce the disk space needed to store the log lines, a short format is developed: `":"`. The encoded log level is simple mapping of a log level to a number: @@ -57,5 +58,5 @@ Implement the `shortFormat(message: String) -> String` method that can output th ```swift let overflow = LogLevel.error overflow.shortFormat(message: "Stack overflow") -// => "6:Stack overflow" +// returns "6:Stack overflow" ``` diff --git a/exercises/concept/log-lines/Package.swift b/exercises/concept/log-lines/Package.swift index fdf7434a..33c433fc 100644 --- a/exercises/concept/log-lines/Package.swift +++ b/exercises/concept/log-lines/Package.swift @@ -1,28 +1,28 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( - name: "LogLines", - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "LogLines", - targets: ["LogLines"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. - .target( - name: "LogLines", - dependencies: []), - .testTarget( - name: "LogLinesTests", - dependencies: ["LogLines"]), - ] + name: "LogLines", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "LogLines", + targets: ["LogLines"]) + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "LogLines", + dependencies: []), + .testTarget( + name: "LogLinesTests", + dependencies: ["LogLines"]), + ] ) diff --git a/exercises/concept/log-lines/Tests/LogLinesTests/LogLinesTests.swift b/exercises/concept/log-lines/Tests/LogLinesTests/LogLinesTests.swift index 0276c4a9..992162d2 100644 --- a/exercises/concept/log-lines/Tests/LogLinesTests/LogLinesTests.swift +++ b/exercises/concept/log-lines/Tests/LogLinesTests/LogLinesTests.swift @@ -1,98 +1,100 @@ -import XCTest +import Foundation +import Testing @testable import LogLines -final class LogLinesTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct LogLinesTests { + @Test("init trace") func testInitTrace() { let line = "[TRC]: Line 84 - Console.WriteLine('Hello World');" - XCTAssertEqual(LogLevel(line), LogLevel.trace) + #expect(LogLevel(line) == LogLevel.trace) } - func testInitDebug() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init debug", .enabled(if: RUNALL)) + func testInitDebug() { let line = "[DBG]: ; expected" - XCTAssertEqual(LogLevel(line), LogLevel.debug) + #expect(LogLevel(line) == LogLevel.debug) } - func testInitInfo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init info", .enabled(if: RUNALL)) + func testInitInfo() { let line = "[INF]: Timezone changed" - XCTAssertEqual(LogLevel(line), LogLevel.info) + #expect(LogLevel(line) == LogLevel.info) } - func testInitWarning() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init warning", .enabled(if: RUNALL)) + func testInitWarning() { let line = "[WRN]: Timezone not set" - XCTAssertEqual(LogLevel(line), LogLevel.warning) + #expect(LogLevel(line) == LogLevel.warning) } - func testInitError() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init error", .enabled(if: RUNALL)) + func testInitError() { let line = "[ERR]: Disk full" - XCTAssertEqual(LogLevel(line), LogLevel.error) + #expect(LogLevel(line) == LogLevel.error) } - func testInitFatal() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init fatal", .enabled(if: RUNALL)) + func testInitFatal() { let line = "[FTL]: Not enough memory" - XCTAssertEqual(LogLevel(line), LogLevel.fatal) + #expect(LogLevel(line) == LogLevel.fatal) } - func testInitUnknownEmpty() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init unknown empty", .enabled(if: RUNALL)) + func testInitUnknownEmpty() { let line = "Something terrible has happened!" - XCTAssertEqual(LogLevel(line), LogLevel.unknown) + #expect(LogLevel(line) == LogLevel.unknown) } - func testInitUnknownNonStandard() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("init unknown non-standard", .enabled(if: RUNALL)) + func testInitUnknownNonStandard() { let line = "[XYZ]: Gibberish message.. beep boop.." - XCTAssertEqual(LogLevel(line), LogLevel.unknown) + #expect(LogLevel(line) == LogLevel.unknown) } - func testShortTrace() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short trace", .enabled(if: RUNALL)) + func testShortTrace() { let message = "Line 13 - int myNum = 42;" - XCTAssertEqual(LogLevel.trace.shortFormat(message: message), "0:Line 13 - int myNum = 42;") + #expect(LogLevel.trace.shortFormat(message: message) == "0:Line 13 - int myNum = 42;") } - func testShortDebug() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short debug", .enabled(if: RUNALL)) + func testShortDebug() { let message = "The name 'LogLevel' does not exist in the current context" - XCTAssertEqual( - LogLevel.debug.shortFormat(message: message), - "1:The name 'LogLevel' does not exist in the current context") + #expect( + LogLevel.debug.shortFormat(message: message) + == "1:The name 'LogLevel' does not exist in the current context") } - func testShortInfo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short info", .enabled(if: RUNALL)) + func testShortInfo() { let message = "File moved" - XCTAssertEqual(LogLevel.info.shortFormat(message: message), "4:File moved") + #expect(LogLevel.info.shortFormat(message: message) == "4:File moved") } - func testShortWarning() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short warning", .enabled(if: RUNALL)) + func testShortWarning() { let message = "Unsafe password" - XCTAssertEqual(LogLevel.warning.shortFormat(message: message), "5:Unsafe password") + #expect(LogLevel.warning.shortFormat(message: message) == "5:Unsafe password") } - func testShortError() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short error", .enabled(if: RUNALL)) + func testShortError() { let message = "Stack overflow" - XCTAssertEqual(LogLevel.error.shortFormat(message: message), "6:Stack overflow") + #expect(LogLevel.error.shortFormat(message: message) == "6:Stack overflow") } - func testShortFatal() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short fatal", .enabled(if: RUNALL)) + func testShortFatal() { let message = "Dumping all files" - XCTAssertEqual(LogLevel.fatal.shortFormat(message: message), "7:Dumping all files") + #expect(LogLevel.fatal.shortFormat(message: message) == "7:Dumping all files") } - func testShortUnknownEmpty() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("short unknown empty", .enabled(if: RUNALL)) + func testShortUnknownEmpty() { let message = "Wha happon?" - XCTAssertEqual(LogLevel.unknown.shortFormat(message: message), "42:Wha happon?") + #expect(LogLevel.unknown.shortFormat(message: message) == "42:Wha happon?") } }