diff --git a/Sources/Config/EnumConfiguration.swift b/Sources/Config/EnumConfiguration.swift index c87355e..4f4acf0 100644 --- a/Sources/Config/EnumConfiguration.swift +++ b/Sources/Config/EnumConfiguration.swift @@ -60,7 +60,7 @@ struct EnumConfiguration: Template { let propertyDeclarations = properties.compactMap { property -> String? in guard let configProperty = property.value as? ConfigurationProperty else { return nil } let value = configProperty.value(for: self.scheme) - return " case \(configProperty.key)" + (value.isEmpty ? "" : #" = "\#(value.replacingOccurrences(of: #"\"#, with: #"\\"#))""#) + return " case \(configProperty.key)" + (value.isEmpty ? "" : ##" = #"\##(value)"#"##) } .sorted() .joined(separator: "\n") diff --git a/Sources/Config/Property.swift b/Sources/Config/Property.swift index a494c43..ee8eac3 100644 --- a/Sources/Config/Property.swift +++ b/Sources/Config/Property.swift @@ -83,13 +83,13 @@ enum PropertyType: String { func valueDeclaration(for value: Any, iv: IV, key: String?) -> String { let stringValue = { - #""\#(value)""# + "#\"\(value)\"#" } switch self { case .string: return stringValue() case .url: - return "URL(string: \(stringValue()))!" + return #"URL(string: "\#(value)")!"# case .encryptionKey: return byteArrayOutput(from: Array("\(value)".utf8)) case .encrypted: @@ -103,7 +103,7 @@ enum PropertyType: String { case .colour: return colourValue(for: value as? String) case .image: - return "UIImage(named: \(stringValue()))!" + return #"UIImage(named: "\#(value)")!"# case .bool: return "\(value as! Bool)" default: diff --git a/Tests/ConfigTests/ConfigGeneratorTests.swift b/Tests/ConfigTests/ConfigGeneratorTests.swift index 1500925..f0fedaa 100644 --- a/Tests/ConfigTests/ConfigGeneratorTests.swift +++ b/Tests/ConfigTests/ConfigGeneratorTests.swift @@ -99,8 +99,8 @@ private let expectedStrings = [ public enum enumconfig: String { case emptyCase - case firstCase = "Some Value" - case secondCase = "Another Value" + case firstCase = #"Some Value"# + case secondCase = #"Another Value"# } """, @@ -113,7 +113,7 @@ private let expectedStrings = [ public enum standard { public static let float: Float = 0.0 - public static let schemeName: String = "any" + public static let schemeName: String = #"any"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command diff --git a/Tests/ConfigTests/ConfigurationFileTests.swift b/Tests/ConfigTests/ConfigurationFileTests.swift index 2c52553..fa754ad 100644 --- a/Tests/ConfigTests/ConfigurationFileTests.swift +++ b/Tests/ConfigTests/ConfigurationFileTests.swift @@ -29,7 +29,7 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { - public static let schemeName: String = "any" + public static let schemeName: String = #"any"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command @@ -72,7 +72,7 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { - public static let schemeName: String = "any" + public static let schemeName: String = #"any"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command @@ -94,7 +94,7 @@ class ConfigurationFileTests: XCTestCase { public static let encryptionKeyIV: [UInt8] = [UInt8(97), UInt8(53), UInt8(101), UInt8(49), UInt8(49), UInt8(97), UInt8(100), UInt8(57), UInt8(98), UInt8(53), UInt8(56), UInt8(55), UInt8(52), UInt8(56), UInt8(101), UInt8(48), UInt8(52), UInt8(56), UInt8(57), UInt8(57), UInt8(56), UInt8(97), UInt8(102), UInt8(53), UInt8(55), UInt8(55), UInt8(97), UInt8(55), UInt8(98), UInt8(97), UInt8(48), UInt8(102)] - public static let schemeName: String = "any" + public static let schemeName: String = #"any"# public static let somethingSecret: [UInt8] = [UInt8(72), UInt8(248), UInt8(24), UInt8(73), UInt8(30), UInt8(207), UInt8(159), UInt8(0), UInt8(65), UInt8(147), UInt8(20), UInt8(183), UInt8(214), UInt8(231), UInt8(169), UInt8(3)] } @@ -116,9 +116,9 @@ class ConfigurationFileTests: XCTestCase { public enum Test { public static let anotherProperty: Int = 1 - public static let schemeName: String = "scheme" + public static let schemeName: String = #"scheme"# - public static let testProperty: String = "A test" + public static let testProperty: String = #"A test"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command @@ -136,11 +136,11 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { - public static let property: String = "A test" + public static let property: String = #"A test"# public static let referenceProperty: String = property - public static let schemeName: String = "scheme" + public static let schemeName: String = #"scheme"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command @@ -159,7 +159,7 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { @nonobjc public static var schemeName: String { - return "any" + return #"any"# } } @@ -178,10 +178,10 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { - public static let schemeName: String = "scheme" + public static let schemeName: String = #"scheme"# public enum FirstGroup { - public static let testProperty: String = "A test" + public static let testProperty: String = #"A test"# } public enum SecondGroup { @@ -205,11 +205,11 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { /// API Host - public static let host: String = "dev.dave.com" + public static let host: String = #"dev.dave.com"# - public static let hostKey: String = "a-secret-key" + public static let hostKey: String = #"a-secret-key"# - public static let schemeName: String = "scheme" + public static let schemeName: String = #"scheme"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command @@ -228,11 +228,11 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { /// API Host - public static let host: String = "dave.com" + public static let host: String = #"dave.com"# - public static let hostKey: String = "the-prod-key" + public static let hostKey: String = #"the-prod-key"# - public static let schemeName: String = "prod" + public static let schemeName: String = #"prod"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command @@ -256,7 +256,7 @@ class ConfigurationFileTests: XCTestCase { public static let float: Float = 0.0 - public static let schemeName: String = "any" + public static let schemeName: String = #"any"# public static let stringArray: [String] = [] } @@ -276,9 +276,9 @@ class ConfigurationFileTests: XCTestCase { // swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command public enum Test { - public static let property: CustomType = CustomType(param: "Value") + public static let property: CustomType = CustomType(param: #"Value"#) - public static let schemeName: String = "any" + public static let schemeName: String = #"any"# } // swiftlint:enable force_unwrapping type_body_length file_length superfluous_disable_command diff --git a/Tests/ConfigTests/ConfigurationPropertyTests.swift b/Tests/ConfigTests/ConfigurationPropertyTests.swift index d0b8d7a..4d0df84 100644 --- a/Tests/ConfigTests/ConfigurationPropertyTests.swift +++ b/Tests/ConfigTests/ConfigurationPropertyTests.swift @@ -29,21 +29,21 @@ class ConfigurationPropertyTests: XCTestCase { func testItCanWriteADeclarationForAStringPropertyUsingTheDefaultValue() throws { let stringProperty = givenAStringProperty() - let expectedValue = #" static let test: String = "test value""# + let expectedValue = ##" static let test: String = #"test value"#"## let actualValue = try whenTheDeclarationIsWritten(for: stringProperty) expect(actualValue).to(equal(expectedValue)) } func testItAddsAPublicAccessorWhenRequired() throws { let stringProperty = givenAStringProperty() - let expectedValue = #" public static let test: String = "test value""# + let expectedValue = ##" public static let test: String = #"test value"#"## let actualValue = try whenTheDeclarationIsWritten(for: stringProperty, isPublic: true) expect(actualValue).to(equal(expectedValue)) } func testItCanIndentADeclaration() throws { let stringProperty = givenAStringProperty() - let expectedValue = #" static let test: String = "test value""# + let expectedValue = ##" static let test: String = #"test value"#"## let actualValue = try whenTheDeclarationIsWritten(for: stringProperty, indentWidth: 3) expect(actualValue).to(equal(expectedValue)) } @@ -52,7 +52,7 @@ class ConfigurationPropertyTests: XCTestCase { let stringProperty = givenAStringProperty() let expectedValue = """ @nonobjc static var test: String { - return "test value" + return #"test value"# } """ let actualValue = try whenTheDeclarationIsWritten(for: stringProperty, requiresNonObjC: true) @@ -61,14 +61,14 @@ class ConfigurationPropertyTests: XCTestCase { func testItCanGetAnOverrideForAnExactMatch() throws { let stringProperty = givenAStringProperty() - let expectedValue = #" static let test: String = "hello value""# + let expectedValue = ##" static let test: String = #"hello value"#"## let actualValue = try whenTheDeclarationIsWritten(for: stringProperty, scheme: "hello") expect(actualValue).to(equal(expectedValue)) } func testItCanGetAnOverrideForAPatternMatch() throws { let stringProperty = givenAStringProperty() - let expectedValue = #" static let test: String = "pattern value""# + let expectedValue = ##" static let test: String = #"pattern value"#"## let actualValue = try whenTheDeclarationIsWritten(for: stringProperty, scheme: "match-a-pattern") expect(actualValue).to(equal(expectedValue)) } @@ -80,7 +80,7 @@ class ConfigurationPropertyTests: XCTestCase { ]) let expectedValue = """ /// A comment to add - static let test: String = "test value" + static let test: String = #"test value"# """ let actualValue = try whenTheDeclarationIsWritten(for: stringProperty) expect(actualValue).to(equal(expectedValue)) diff --git a/Tests/ConfigTests/CustomPropertyTests.swift b/Tests/ConfigTests/CustomPropertyTests.swift index 7637b26..3579216 100644 --- a/Tests/ConfigTests/CustomPropertyTests.swift +++ b/Tests/ConfigTests/CustomPropertyTests.swift @@ -85,7 +85,7 @@ class CustomPropertyTests: XCTestCase { ]), dict: givenADictionaryWithValues()) let expectedValue = """ /// A description - public static let test: CustomType = CustomType(thingy: "firstValue") + public static let test: CustomType = CustomType(thingy: #"firstValue"#) """ expect(property.propertyDeclaration(for: "any", iv: try IV(dict: [:]), encryptionKey: nil, requiresNonObjCDeclarations: false, isPublic: true, indentWidth: 0)).to(equal(expectedValue)) } @@ -94,7 +94,7 @@ class CustomPropertyTests: XCTestCase { let property = CustomProperty(key: "test", customType: givenACustomType(for: givenATypeDictionaryWithTypeAnnotations()), dict: givenADictionaryWithTypedValues()) let expectedValue = """ /// A description - public static let test: CustomType = CustomType(oneThing: "firstValue", secondThing: true) + public static let test: CustomType = CustomType(oneThing: #"firstValue"#, secondThing: true) """ expect(property.propertyDeclaration(for: "any", iv: try IV(dict: [:]), encryptionKey: nil, requiresNonObjCDeclarations: false, isPublic: true, indentWidth: 0)).to(equal(expectedValue)) } @@ -102,7 +102,7 @@ class CustomPropertyTests: XCTestCase { func testItOutputsAStringWithEscapedSlashesCorrectly() { let property = CustomProperty(key: "test", customType: givenACustomType(for: regexCustomType), dict: regexDictionary) let expectedValue = """ - public static let test: NSRegularExpression = try! NSRegularExpression(expression: "^.*\\@.*\\.[a-zA-Z]{2,3}$", options: []) + public static let test: NSRegularExpression = try! NSRegularExpression(expression: #"^.*\\@.*\\.[a-zA-Z]{2,3}$"#, options: []) """ expect(property.propertyDeclaration(for: "any", iv: try IV(dict: [:]), encryptionKey: nil, requiresNonObjCDeclarations: false, isPublic: true, indentWidth: 0)).to(equal(expectedValue)) } @@ -110,7 +110,7 @@ class CustomPropertyTests: XCTestCase { func testItOutputsAStringWithEscapedSlashesCorrectlyForSingleValue() { let property = CustomProperty(key: "test", customType: givenACustomType(for: regexCustomType), dict: regexSingleValueDictionary) let expectedValue = """ - public static let test: NSRegularExpression = try! NSRegularExpression(expression: "^.*\\@.*\\.[a-zA-Z]{2,3}$", options: []) + public static let test: NSRegularExpression = try! NSRegularExpression(expression: #"^.*\\@.*\\.[a-zA-Z]{2,3}$"#, options: []) """ expect(property.propertyDeclaration(for: "any", iv: try IV(dict: [:]), encryptionKey: nil, requiresNonObjCDeclarations: false, isPublic: true, indentWidth: 0)).to(equal(expectedValue)) } @@ -137,7 +137,7 @@ class CustomPropertyArrayTests: XCTestCase { let property = CustomPropertyArray(key: "test", customType: givenACustomType(for: givenATypeDictionaryWithTypeAnnotations()), dict: givenADictionaryWithArrayValues()) let expectedValue = """ /// A description - public static let test: [CustomType] = [CustomType(oneThing: "firstValue", secondThing: true)] + public static let test: [CustomType] = [CustomType(oneThing: #"firstValue"#, secondThing: true)] """ expect(property.propertyDeclaration(for: "any", iv: try IV(dict: [:]), encryptionKey: nil, requiresNonObjCDeclarations: false, isPublic: true, indentWidth: 0)).to(equal(expectedValue)) } @@ -146,7 +146,7 @@ class CustomPropertyArrayTests: XCTestCase { let property = CustomPropertyArray(key: "test", customType: givenACustomType(for: givenATypeDictionaryWithTypeAnnotations()), dict: givenADictionaryWithArrayValues()) let expectedValue = """ /// A description - public static let test: [CustomType] = [CustomType(oneThing: "firstOverriddenValue", secondThing: false)] + public static let test: [CustomType] = [CustomType(oneThing: #"firstOverriddenValue"#, secondThing: false)] """ expect(property.propertyDeclaration(for: "override", iv: try IV(dict: [:]), encryptionKey: nil, requiresNonObjCDeclarations: false, isPublic: true, indentWidth: 0)).to(equal(expectedValue)) } diff --git a/Tests/ConfigTests/EnumConfigurationTests.swift b/Tests/ConfigTests/EnumConfigurationTests.swift index 850c8f4..6fa0b3b 100644 --- a/Tests/ConfigTests/EnumConfigurationTests.swift +++ b/Tests/ConfigTests/EnumConfigurationTests.swift @@ -70,8 +70,8 @@ class EnumConfigurationTests: XCTestCase { public enum Test: String { case emptyCase - case firstCase = "Some Value" - case secondCase = "Overridden Value" + case firstCase = #"Some Value"# + case secondCase = #"Overridden Value"# } """