Skip to content

Commit

Permalink
Don't use # for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardiman committed Apr 26, 2019
1 parent 0e139ca commit 09c32b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Sources/Config/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ enum PropertyType: String {
}

func valueDeclaration(for value: Any, iv: IV, key: String?) -> String {
let stringValue = {
"#\"\(value)\"#"
let stringValue = { () -> String in
if let string = value as? String, string.isEmpty {
return "\"\""
}
return "#\"\(value)\"#"
}
switch self {
case .string:
Expand Down
12 changes: 10 additions & 2 deletions Tests/ConfigTests/ConfigurationPropertyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ConfigurationPropertyTests: XCTestCase {
"defaultValue": "test value",
"overrides": [
"hello": "hello value",
"pattern": "pattern value"
"pattern": "pattern value",
"empty": ""
]
])
}
Expand All @@ -34,6 +35,13 @@ class ConfigurationPropertyTests: XCTestCase {
expect(actualValue).to(equal(expectedValue))
}

func testItCanWriteADeclarationForAnEmptyStringProperty() throws {
let stringProperty = givenAStringProperty()
let expectedValue = ##" static let test: String = """##
let actualValue = try whenTheDeclarationIsWritten(for: stringProperty, scheme: "empty")
expect(actualValue).to(equal(expectedValue))
}

func testItAddsAPublicAccessorWhenRequired() throws {
let stringProperty = givenAStringProperty()
let expectedValue = ##" public static let test: String = #"test value"#"##
Expand Down Expand Up @@ -125,7 +133,7 @@ class ConfigurationPropertyTests: XCTestCase {
func testItCanWriteABoolProperty() throws {
let floatProperty = ConfigurationProperty<Bool>(key: "test", typeHint: "Bool", dict: [
"defaultValue": true,
])
])
let expectedValue = #" static let test: Bool = true"#
let actualValue = try whenTheDeclarationIsWritten(for: floatProperty)
expect(actualValue).to(equal(expectedValue))
Expand Down

0 comments on commit 09c32b0

Please sign in to comment.