From e221ad40748f3c4070247116545a4f08191eecc3 Mon Sep 17 00:00:00 2001 From: Kenta Kubo <601636+kkebo@users.noreply.github.com> Date: Tue, 19 Nov 2024 00:31:22 +0900 Subject: [PATCH] style: swift-format --- Sources/Models/Text/ListComparer.swift | 171 +++++++++--------- Sources/Pages/Text/ListComparerView.swift | 4 +- .../Pages/Text/ListComparerViewState.swift | 7 +- 3 files changed, 93 insertions(+), 89 deletions(-) diff --git a/Sources/Models/Text/ListComparer.swift b/Sources/Models/Text/ListComparer.swift index 3bc3d45..299fc1b 100644 --- a/Sources/Models/Text/ListComparer.swift +++ b/Sources/Models/Text/ListComparer.swift @@ -66,106 +66,105 @@ struct ListComparer { } #if TESTING_ENABLED -import Foundation -import PlaygroundTester - -@objcMembers -final class ListComparerTests: TestCase { - func testIntersectionCaseInsensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .intersection) + import Foundation + import PlaygroundTester + + @objcMembers + final class ListComparerTests: TestCase { + func testIntersectionCaseInsensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .intersection) + } + AssertEqual("", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("c", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("B", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("c", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("B", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("", other: compare(a: "", b: "d\nE\nf")) - } - func testIntersectionCaseSensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .intersection) + func testIntersectionCaseSensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .intersection) + } + AssertEqual("", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("c", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("c", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("", other: compare(a: "", b: "d\nE\nf")) - } - func testUnionCaseInsensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .union) + func testUnionCaseInsensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .union) + } + AssertEqual("a\nB\nc\nd\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("a\nB\nc\nE\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("a\nB\nc\nE\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("a\nB\nc\nd\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("a\nB\nc\nd\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("a\nB\nc\nE\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("a\nB\nc\nE\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("a\nB\nc\nd\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) - } - func testUnionCaseSensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .union) + func testUnionCaseSensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .union) + } + AssertEqual("a\nB\nc\nd\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("a\nB\nc\nE\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("a\nB\nc\nb\nE\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("a\nB\nc\nb\nd\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("a\nB\nc\nd\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("a\nB\nc\nE\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("a\nB\nc\nb\nE\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("a\nB\nc\nb\nd\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) - } - func testAOnlyCaseInsensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .aOnly) + func testAOnlyCaseInsensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .aOnly) + } + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("a\nB", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("a\nc", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("a\nB", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("a\nc", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("", other: compare(a: "", b: "d\nE\nf")) - } - func testAOnlyCaseSensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .aOnly) + func testAOnlyCaseSensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .aOnly) + } + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("a\nB", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("a\nB\nc\nb", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("a\nB", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("a\nB\nc\nb", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("a\nB\nc", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("", other: compare(a: "", b: "d\nE\nf")) - } - func testBOnlyCaseInsensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .bOnly) + func testBOnlyCaseInsensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: false, mode: .bOnly) + } + AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("E\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("E\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("E\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("E\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) - } - func testBOnlyCaseSensitive() { - func compare(a: String, b: String) -> String { - ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .bOnly) + func testBOnlyCaseSensitive() { + func compare(a: String, b: String) -> String { + ListComparer.compare(a: a, b: b, caseSensitive: true, mode: .bOnly) + } + AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) + AssertEqual("E\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) + AssertEqual("b\nE\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) + AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) + AssertEqual("", other: compare(a: "a\nB\nc", b: "")) + AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) } - AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc", b: "d\nE\nf")) - AssertEqual("E\nf", other: compare(a: "a\nB\nc", b: "c\nE\nf")) - AssertEqual("b\nE\nf", other: compare(a: "a\nB\nc", b: "b\nE\nf")) - AssertEqual("d\nE\nf", other: compare(a: "a\nB\nc\nb", b: "d\nE\nf")) - AssertEqual("", other: compare(a: "a\nB\nc", b: "")) - AssertEqual("d\nE\nf", other: compare(a: "", b: "d\nE\nf")) } -} #endif - diff --git a/Sources/Pages/Text/ListComparerView.swift b/Sources/Pages/Text/ListComparerView.swift index b4bc70b..9d8148c 100644 --- a/Sources/Pages/Text/ListComparerView.swift +++ b/Sources/Pages/Text/ListComparerView.swift @@ -13,11 +13,11 @@ extension ListComparerView: View { var body: some View { ToyPage { ToySection("Configuration") { - ConfigurationRow("Case sensitive comparison", systemImage: "textformat") { + ConfigurationRow("Case sensitive comparison", systemImage: "textformat") { Toggle("", isOn: self.$state.isCaseSensitive).labelsHidden() } ConfigurationRow("Comparison mode", systemImage: "brain") { - Picker("", selection: self.$state.comparisonMode) { + Picker("", selection: self.$state.comparisonMode) { ForEach(ListComparisonMode.allCases, id: \.self) { Text(LocalizedStringKey($0.description)) } diff --git a/Sources/Pages/Text/ListComparerViewState.swift b/Sources/Pages/Text/ListComparerViewState.swift index 72f010d..db67815 100644 --- a/Sources/Pages/Text/ListComparerViewState.swift +++ b/Sources/Pages/Text/ListComparerViewState.swift @@ -17,6 +17,11 @@ final class ListComparerViewState { private(set) var output = "" private func didUpdate() { - self.output = ListComparer.compare(a: self.a, b: self.b, caseSensitive: self.isCaseSensitive, mode: self.comparisonMode) + self.output = ListComparer.compare( + a: self.a, + b: self.b, + caseSensitive: self.isCaseSensitive, + mode: self.comparisonMode + ) } }