From cf39915562b21180c19d7fe88ca27b5b9c994a78 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 22 Sep 2024 06:32:40 +1000 Subject: [PATCH] Further DRY by generating example 5 start from 4 end --- 05-fixtures/0-start/.gitignore | 1 + .../0-start/Albertos/AlbertosApp.swift | 26 ----- .../AccentColor.colorset/Contents.json | 11 --- .../AppIcon.appiconset/Contents.json | 98 ------------------- .../Albertos/Assets.xcassets/Contents.json | 6 -- 05-fixtures/0-start/Albertos/Info.plist | 50 ---------- .../0-start/Albertos/MenuGrouping.swift | 7 -- 05-fixtures/0-start/Albertos/MenuItem.swift | 10 -- 05-fixtures/0-start/Albertos/MenuList.swift | 17 ---- .../0-start/Albertos/MenuSection.swift | 10 -- .../Preview Assets.xcassets/Contents.json | 6 -- .../AlbertosTests/Collection+Safe.swift | 7 -- 05-fixtures/0-start/AlbertosTests/Info.plist | 22 ----- .../AlbertosTests/MenuGroupingTests.swift | 44 --------- 05-fixtures/0-start/project.yml | 36 +++---- 15 files changed, 20 insertions(+), 331 deletions(-) delete mode 100644 05-fixtures/0-start/Albertos/AlbertosApp.swift delete mode 100644 05-fixtures/0-start/Albertos/Assets.xcassets/AccentColor.colorset/Contents.json delete mode 100644 05-fixtures/0-start/Albertos/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 05-fixtures/0-start/Albertos/Assets.xcassets/Contents.json delete mode 100644 05-fixtures/0-start/Albertos/Info.plist delete mode 100644 05-fixtures/0-start/Albertos/MenuGrouping.swift delete mode 100644 05-fixtures/0-start/Albertos/MenuItem.swift delete mode 100644 05-fixtures/0-start/Albertos/MenuList.swift delete mode 100644 05-fixtures/0-start/Albertos/MenuSection.swift delete mode 100644 05-fixtures/0-start/Albertos/Preview Content/Preview Assets.xcassets/Contents.json delete mode 100644 05-fixtures/0-start/AlbertosTests/Collection+Safe.swift delete mode 100644 05-fixtures/0-start/AlbertosTests/Info.plist delete mode 100644 05-fixtures/0-start/AlbertosTests/MenuGroupingTests.swift diff --git a/05-fixtures/0-start/.gitignore b/05-fixtures/0-start/.gitignore index f5ee019..0f22386 100644 --- a/05-fixtures/0-start/.gitignore +++ b/05-fixtures/0-start/.gitignore @@ -29,3 +29,4 @@ DerivedData # # Pods/ +*.xcodeproj diff --git a/05-fixtures/0-start/Albertos/AlbertosApp.swift b/05-fixtures/0-start/Albertos/AlbertosApp.swift deleted file mode 100644 index 8aa9c85..0000000 --- a/05-fixtures/0-start/Albertos/AlbertosApp.swift +++ /dev/null @@ -1,26 +0,0 @@ -import SwiftUI - -@main -struct AlbertosApp: App { - - var body: some Scene { - WindowGroup { - NavigationView { - MenuList(sections: groupMenuByCategory(menu)) - .navigationTitle("Alberto's 🇮🇹") - } - } - } -} - -// In this first iteration the menu is an hard-coded array -let menu = [ - MenuItem(category: "starters", name: "Caprese Salad"), - MenuItem(category: "starters", name: "Arancini Balls"), - MenuItem(category: "pastas", name: "Penne all'Arrabbiata"), - MenuItem(category: "pastas", name: "Spaghetti Carbonara"), - MenuItem(category: "drinks", name: "Water"), - MenuItem(category: "drinks", name: "Red Wine"), - MenuItem(category: "desserts", name: "Tiramisù"), - MenuItem(category: "desserts", name: "Crema Catalana"), -] diff --git a/05-fixtures/0-start/Albertos/Assets.xcassets/AccentColor.colorset/Contents.json b/05-fixtures/0-start/Albertos/Assets.xcassets/AccentColor.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/05-fixtures/0-start/Albertos/Assets.xcassets/AccentColor.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/05-fixtures/0-start/Albertos/Assets.xcassets/AppIcon.appiconset/Contents.json b/05-fixtures/0-start/Albertos/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 9221b9b..0000000 --- a/05-fixtures/0-start/Albertos/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "20x20" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "20x20" - }, - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "29x29" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "29x29" - }, - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "40x40" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "40x40" - }, - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "60x60" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "60x60" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "20x20" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "20x20" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "29x29" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "29x29" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "40x40" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "40x40" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "76x76" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "76x76" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "83.5x83.5" - }, - { - "idiom" : "ios-marketing", - "scale" : "1x", - "size" : "1024x1024" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/05-fixtures/0-start/Albertos/Assets.xcassets/Contents.json b/05-fixtures/0-start/Albertos/Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/05-fixtures/0-start/Albertos/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/05-fixtures/0-start/Albertos/Info.plist b/05-fixtures/0-start/Albertos/Info.plist deleted file mode 100644 index efc211a..0000000 --- a/05-fixtures/0-start/Albertos/Info.plist +++ /dev/null @@ -1,50 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - $(PRODUCT_BUNDLE_PACKAGE_TYPE) - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UIApplicationSceneManifest - - UIApplicationSupportsMultipleScenes - - - UIApplicationSupportsIndirectInputEvents - - UILaunchScreen - - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - - diff --git a/05-fixtures/0-start/Albertos/MenuGrouping.swift b/05-fixtures/0-start/Albertos/MenuGrouping.swift deleted file mode 100644 index f665496..0000000 --- a/05-fixtures/0-start/Albertos/MenuGrouping.swift +++ /dev/null @@ -1,7 +0,0 @@ -func groupMenuByCategory(_ menu: [MenuItem]) -> [MenuSection] { - guard menu.isEmpty == false else { return [] } - - return Dictionary(grouping: menu, by: { $0.category }) - .map { key, value in MenuSection(category: key, items: value) } - .sorted { $0.category > $1.category } -} diff --git a/05-fixtures/0-start/Albertos/MenuItem.swift b/05-fixtures/0-start/Albertos/MenuItem.swift deleted file mode 100644 index 7d7b7d4..0000000 --- a/05-fixtures/0-start/Albertos/MenuItem.swift +++ /dev/null @@ -1,10 +0,0 @@ -struct MenuItem { - - let category: String - let name: String -} - -extension MenuItem: Identifiable { - - var id: String { name } -} diff --git a/05-fixtures/0-start/Albertos/MenuList.swift b/05-fixtures/0-start/Albertos/MenuList.swift deleted file mode 100644 index 7d9194a..0000000 --- a/05-fixtures/0-start/Albertos/MenuList.swift +++ /dev/null @@ -1,17 +0,0 @@ -import SwiftUI - -struct MenuList: View { - let sections: [MenuSection] - - var body: some View { - List { - ForEach(sections) { section in - Section(header: Text(section.category)) { - ForEach(section.items) { item in - Text(item.name) - } - } - } - } - } -} diff --git a/05-fixtures/0-start/Albertos/MenuSection.swift b/05-fixtures/0-start/Albertos/MenuSection.swift deleted file mode 100644 index 18777ef..0000000 --- a/05-fixtures/0-start/Albertos/MenuSection.swift +++ /dev/null @@ -1,10 +0,0 @@ -struct MenuSection { - - let category: String - let items: [MenuItem] -} - -extension MenuSection: Identifiable { - - var id: String { category } -} diff --git a/05-fixtures/0-start/Albertos/Preview Content/Preview Assets.xcassets/Contents.json b/05-fixtures/0-start/Albertos/Preview Content/Preview Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/05-fixtures/0-start/Albertos/Preview Content/Preview Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/05-fixtures/0-start/AlbertosTests/Collection+Safe.swift b/05-fixtures/0-start/AlbertosTests/Collection+Safe.swift deleted file mode 100644 index 0d7daad..0000000 --- a/05-fixtures/0-start/AlbertosTests/Collection+Safe.swift +++ /dev/null @@ -1,7 +0,0 @@ -extension Collection { - - /// Returns the element at the specified index if it is within range, otherwise nil. - subscript(safe index: Index) -> Element? { - return indices.contains(index) ? self[index] : nil - } -} diff --git a/05-fixtures/0-start/AlbertosTests/Info.plist b/05-fixtures/0-start/AlbertosTests/Info.plist deleted file mode 100644 index 64d65ca..0000000 --- a/05-fixtures/0-start/AlbertosTests/Info.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - $(PRODUCT_BUNDLE_PACKAGE_TYPE) - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - diff --git a/05-fixtures/0-start/AlbertosTests/MenuGroupingTests.swift b/05-fixtures/0-start/AlbertosTests/MenuGroupingTests.swift deleted file mode 100644 index 370fc3f..0000000 --- a/05-fixtures/0-start/AlbertosTests/MenuGroupingTests.swift +++ /dev/null @@ -1,44 +0,0 @@ -@testable import Albertos -import XCTest - -class MenuGroupingTests: XCTestCase { - - func testMenuWithManyCategoriesReturnsAsManySectionsInReverseAlphabeticalOrder() { - let menu = [ - MenuItem(category: "pastas", name: "a pasta"), - MenuItem(category: "drinks", name: "a drink"), - MenuItem(category: "pastas", name: "another pasta"), - MenuItem(category: "desserts", name: "a dessert"), - ] - - let sections = groupMenuByCategory(menu) - - XCTAssertEqual(sections.count, 3) - XCTAssertEqual(sections[safe: 0]?.category, "pastas") - XCTAssertEqual(sections[safe: 1]?.category, "drinks") - XCTAssertEqual(sections[safe: 2]?.category, "desserts") - } - - func testMenuWithOneCategoryReturnsOneSection() throws { - let menu = [ - MenuItem(category: "pastas", name: "name"), - MenuItem(category: "pastas", name: "other name") - ] - - let sections = groupMenuByCategory(menu) - - XCTAssertEqual(sections.count, 1) - let section = try XCTUnwrap(sections.first) - XCTAssertEqual(section.items.count, 2) - XCTAssertEqual(section.items.first?.name, "name") - XCTAssertEqual(section.items.last?.name, "other name") - } - - func testEmptyMenuReturnsEmptySections() { - let menu = [MenuItem]() - - let sections = groupMenuByCategory(menu) - - XCTAssertEqual(sections.count, 0) - } -} diff --git a/05-fixtures/0-start/project.yml b/05-fixtures/0-start/project.yml index d3ad1e0..feb71d4 100644 --- a/05-fixtures/0-start/project.yml +++ b/05-fixtures/0-start/project.yml @@ -1,19 +1,21 @@ include: - ../../constants.yml -targets: - Albertos: - type: application - platform: iOS - sources: [Albertos] - scheme: - testTargets: [AlbertosTests] - AlbertosTests: - target: Albertos - type: bundle.unit-test - platform: iOS - sources: [AlbertosTests] - settings: - # No need for code signing in this demo, plus, it's the test target - CODE_SIGNING_ALLOWED: NO - dependencies: - - target: Albertos + - ../../04-tdd-in-the-real-world/1-end/project.yml + +# targets: +# Albertos: +# type: application +# platform: iOS +# sources: [Albertos] +# scheme: +# testTargets: [AlbertosTests] +# AlbertosTests: +# target: Albertos +# type: bundle.unit-test +# platform: iOS +# sources: [AlbertosTests] +# settings: +# # No need for code signing in this demo, plus, it's the test target +# CODE_SIGNING_ALLOWED: NO +# dependencies: +# - target: Albertos