Skip to content

Commit c27727f

Browse files
author
Aaron McTavish
authored
Rename postcode countries to lowercase (#68)
Resolves #57 Update 'PostcodeCountries' to Lowercase Enum. - Rename postcode countries (enum cases) to lowercase - Also removes no longer neccessary swiftlint workaround.
1 parent 825fd6b commit c27727f

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

Sources/Configurations/PostcodeConfiguration.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@ import Foundation
1111

1212
/// Countries that are supported by `PostcodeCondition`. Each postcode is an ISO 3166-1 alpha-3 country code. There is a `regex` property that returns the regex for validating that country's postcode.
1313
public enum PostcodeCountries: String {
14-
15-
// swiftlint:disable identifier_name
16-
case Sweden = "SWE"
17-
case Turkey = "TUR"
18-
case UnitedKingdom = "GBR"
19-
case UnitedStates = "USA"
20-
// swiftlint:enable identifier_name
14+
15+
case sweden = "SWE"
16+
case turkey = "TUR"
17+
case unitedKingdom = "GBR"
18+
case unitedStates = "USA"
2119

2220
/// The regex for validating the country's postcode.
2321
public var regex: String {
2422
switch self {
25-
case .Sweden:
23+
case .sweden:
2624
return "^(SE-)?[0-9]{3}\\s?[0-9]{2}$"
27-
case .Turkey:
25+
case .turkey:
2826
return "^[0-9]{5}$"
29-
case .UnitedKingdom:
27+
case .unitedKingdom:
3028
return "^([A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKS-UWa-hjks-uw])\\ {0,1}[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}|([Gg][Ii][Rr]\\ 0[Aa][Aa])|([Ss][Aa][Nn]\\ {0,1}[Tt][Aa]1)|([Bb][Ff][Pp][Oo]\\ {0,1}([Cc]\\/[Oo]\\ )?[0-9]{1,4})|(([Aa][Ss][Cc][Nn]|[Bb][Bb][Nn][Dd]|[BFSbfs][Ii][Qq][Qq]|[Pp][Cc][Rr][Nn]|[Ss][Tt][Hh][Ll]|[Tt][Dd][Cc][Uu]|[Tt][Kk][Cc][Aa])\\ {0,1}1[Zz][Zz]))$"
31-
case .UnitedStates:
29+
case .unitedStates:
3230
return "^[0-9]{5}(?:[-|\\s][0-9]{4})?$"
3331
}
3432
}
3533

36-
public static let allValues: [PostcodeCountries] = [.Sweden, .Turkey, .UnitedKingdom, .UnitedStates]
34+
public static let allValues: [PostcodeCountries] = [.sweden, .turkey, .unitedKingdom, .unitedStates]
3735
}
3836

3937

@@ -49,10 +47,10 @@ public struct PostcodeConfiguration: Configuration {
4947
// MARK: - Initializers
5048

5149
public init() {
52-
self.init(country: .UnitedKingdom)
50+
self.init(country: .unitedKingdom)
5351
}
5452

55-
public init(country: PostcodeCountries = .UnitedKingdom) {
53+
public init(country: PostcodeCountries = .unitedKingdom) {
5654
self.country = country
5755
}
5856

Tests/Unit Tests/Conditions/PostcodeConditionTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,41 @@ final class PostcodeConditionTests: XCTestCase {
2323

2424
var successInputs: [String] {
2525
switch country {
26-
case .Sweden:
26+
case .sweden:
2727
return ["112 50",
2828
"11434",
2929
"SE-111 21",
3030
"SE-11637",
3131
"se-11637"]
32-
case .Turkey:
32+
case .turkey:
3333
return ["34345"]
34-
case .UnitedKingdom:
34+
case .unitedKingdom:
3535
return ["M1 1BA"]
36-
case .UnitedStates:
36+
case .unitedStates:
3737
return ["20500",
3838
"95014-2083"]
3939
}
4040
}
4141

4242
var failureInputs: [String?] {
4343
switch country {
44-
case .Sweden:
44+
case .sweden:
4545
return ["113 4",
4646
"116233",
4747
"us-125 41",
4848
"us-125e1",
4949
nil]
50-
case .Turkey:
50+
case .turkey:
5151
return ["3411",
5252
"347001",
5353
"34 700",
5454
"3470a",
5555
nil]
56-
case .UnitedKingdom:
56+
case .unitedKingdom:
5757
return ["M1AA 1BA",
5858
"M1 1BAA",
5959
nil]
60-
case .UnitedStates:
60+
case .unitedStates:
6161
return ["1234",
6262
"12345-1",
6363
nil]
@@ -99,11 +99,11 @@ final class PostcodeConditionTests: XCTestCase {
9999
var condition = PostcodeCondition()
100100

101101
// When
102-
condition.configuration.country = .Sweden
102+
condition.configuration.country = .sweden
103103

104104
// Then
105-
XCTAssertEqual(condition.configuration.country, PostcodeCountries.Sweden)
106-
XCTAssertEqual(condition.regex, PostcodeCountries.Sweden.regex)
105+
XCTAssertEqual(condition.configuration.country, PostcodeCountries.sweden)
106+
XCTAssertEqual(condition.regex, PostcodeCountries.sweden.regex)
107107
}
108108

109109
}

0 commit comments

Comments
 (0)