Skip to content

Commit

Permalink
value -> rawValue
Browse files Browse the repository at this point in the history
  • Loading branch information
tib committed Feb 8, 2024
1 parent 9c823fc commit a7ec5dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions Sources/NanoID/NanoID.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public struct NanoID {
public let value: String
public let rawValue: String

public init(
size: Int = 21
Expand All @@ -13,7 +13,7 @@ public struct NanoID {
)
value.append(Self.alphabet[index])
}
self.value = value
self.rawValue = value
}
}

Expand All @@ -23,7 +23,7 @@ public extension NanoID {
}

public extension NanoID {
var size: Int { value.count }
var size: Int { rawValue.count }
}

extension NanoID: Sendable {}
Expand All @@ -32,7 +32,7 @@ extension NanoID: Hashable {}
extension NanoID: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.value)
try container.encode(self.rawValue)
}
}
extension NanoID: Decodable {
Expand All @@ -47,7 +47,7 @@ extension NanoID: Decodable {
"""
)
}
self.value = id.value
self.rawValue = id.rawValue
}
}

Expand All @@ -59,10 +59,10 @@ extension NanoID: LosslessStringConvertible {
return nil
}
}
self.value = description
self.rawValue = description
}

public var description: String {
value
rawValue
}
}
10 changes: 5 additions & 5 deletions Tests/NanoIDTests/NanoIDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class NanoIDTests: XCTestCase {
func testAlphabet() {
let id = NanoID()

for char in id.value {
for char in id.rawValue {
guard NanoID.alphabet.firstIndex(of: char) != nil else {
return XCTFail("Invalid character")
}
Expand All @@ -16,21 +16,21 @@ final class NanoIDTests: XCTestCase {
func testDefaultSize() {
let size = 21
let id = NanoID(size: size)
XCTAssertEqual(id.value.count, id.size)
XCTAssertEqual(id.rawValue.count, id.size)
XCTAssertEqual(size, id.size)
}

func testCustomSize() {
let size = 4
let id = NanoID(size: size)
XCTAssertEqual(id.value.count, id.size)
XCTAssertEqual(id.rawValue.count, id.size)
XCTAssertEqual(size, id.size)
}

func testValidAlphabet() {
let id = NanoID("abc")
XCTAssertNotNil(id)
XCTAssertEqual(id?.value, "abc")
XCTAssertEqual(id?.rawValue, "abc")
XCTAssertEqual(id?.size, 3)
XCTAssertEqual(id?.description, "abc")
}
Expand Down Expand Up @@ -58,7 +58,7 @@ final class NanoIDTests: XCTestCase {
let jsonData = jsonString.data(using: .utf8)!
let decoder = JSONDecoder()
let wrapper = try decoder.decode(Wrapper.self, from: jsonData)
XCTAssertEqual(wrapper.id.value, "abc")
XCTAssertEqual(wrapper.id.rawValue, "abc")
}

func testEncodable() throws {
Expand Down

0 comments on commit a7ec5dd

Please sign in to comment.