Skip to content

Commit

Permalink
style: swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Nov 18, 2024
1 parent e4a2665 commit e221ad4
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 89 deletions.
171 changes: 85 additions & 86 deletions Sources/Models/Text/ListComparer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions Sources/Pages/Text/ListComparerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Pages/Text/ListComparerViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

0 comments on commit e221ad4

Please sign in to comment.