Fix wrong VersionLock printing on Swift 5 (fixes #311)

This commit is contained in:
John Estropia
2019-04-05 08:29:14 +09:00
parent b2dba0d6fd
commit fe7e6e7b84
4 changed files with 69 additions and 7 deletions

View File

@@ -491,6 +491,9 @@
B59851491C90289D00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; };
B598514A1C90289E00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; };
B598514B1C90289F00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; };
B59A51832256C85E00CEF3C5 /* VersionLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A51822256C85E00CEF3C5 /* VersionLockTests.swift */; };
B59A51842256C85E00CEF3C5 /* VersionLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A51822256C85E00CEF3C5 /* VersionLockTests.swift */; };
B59A51852256C85E00CEF3C5 /* VersionLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A51822256C85E00CEF3C5 /* VersionLockTests.swift */; };
B59AFF411C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; };
B5A1DAC81F111BFA003CF369 /* KeyPath+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1DAC71F111BFA003CF369 /* KeyPath+Querying.swift */; };
B5A1DAC91F111BFA003CF369 /* KeyPath+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1DAC71F111BFA003CF369 /* KeyPath+Querying.swift */; };
@@ -858,6 +861,7 @@
B596BBAD1DD59FDB001DCDD9 /* ConvenienceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvenienceTests.swift; sourceTree = "<group>"; };
B596BBB51DD5BC67001DCDD9 /* FetchableSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableSource.swift; sourceTree = "<group>"; };
B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryableSource.swift; sourceTree = "<group>"; };
B59A51822256C85E00CEF3C5 /* VersionLockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionLockTests.swift; sourceTree = "<group>"; };
B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSPersistentStoreCoordinator+Setup.swift"; sourceTree = "<group>"; };
B5A1DAC71F111BFA003CF369 /* KeyPath+Querying.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyPath+Querying.swift"; sourceTree = "<group>"; };
B5A261201B64BFDB006EB6D3 /* MigrationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationType.swift; sourceTree = "<group>"; };
@@ -1110,6 +1114,7 @@
B5489F3C1CF5EEBC008B4978 /* TestEntities */,
B5489F451CF5F017008B4978 /* TransactionTests.swift */,
B525577F1D029D2500E51965 /* TweakTests.swift */,
B59A51822256C85E00CEF3C5 /* VersionLockTests.swift */,
B52557731D02791400E51965 /* WhereTests.swift */,
);
path = CoreStoreTests;
@@ -2043,6 +2048,7 @@
B5489F461CF5F017008B4978 /* TransactionTests.swift in Sources */,
B52557801D029D2500E51965 /* TweakTests.swift in Sources */,
B580857A1CDF808C004C2EEB /* SetupTests.swift in Sources */,
B59A51832256C85E00CEF3C5 /* VersionLockTests.swift in Sources */,
B5489F4C1CF5F743008B4978 /* BaseTestCase.swift in Sources */,
B5DBE2DF1C9939E100B5CEFA /* BridgingTests.m in Sources */,
B57D27BE1D0BBE8200539C58 /* BaseTestDataTestCase.swift in Sources */,
@@ -2237,6 +2243,7 @@
B52557711D02561A00E51965 /* SelectTests.swift in Sources */,
B5489F471CF5F017008B4978 /* TransactionTests.swift in Sources */,
B52557811D029D2500E51965 /* TweakTests.swift in Sources */,
B59A51842256C85E00CEF3C5 /* VersionLockTests.swift in Sources */,
B5489F4D1CF5F743008B4978 /* BaseTestCase.swift in Sources */,
82BA18DC1C4BBD9C00A0916E /* Model.xcdatamodeld in Sources */,
B57D27BF1D0BBE8200539C58 /* BaseTestDataTestCase.swift in Sources */,
@@ -2431,6 +2438,7 @@
B5489F481CF5F017008B4978 /* TransactionTests.swift in Sources */,
B52557821D029D2500E51965 /* TweakTests.swift in Sources */,
B5489F4E1CF5F743008B4978 /* BaseTestCase.swift in Sources */,
B59A51852256C85E00CEF3C5 /* VersionLockTests.swift in Sources */,
B5598BCC1BE2093D0092EFCE /* Model.xcdatamodeld in Sources */,
B5220E261D1308C2009BC71E /* ListObserverTests.swift in Sources */,
B57D27C01D0BBE8200539C58 /* BaseTestDataTestCase.swift in Sources */,

View File

@@ -0,0 +1,55 @@
//
// VersionLockTests.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import XCTest
@testable
import CoreStore
//MARK: - VersionLockTests
final class VersionLockTests: XCTestCase {
@objc
dynamic func test_ThatVersionLocksProduceCorrectHashes() {
let versionLock: VersionLock = [
"Animal": [0x1b59d511019695cf, 0xdeb97e86c5eff179, 0x1cfd80745646cb3, 0x4ff99416175b5b9a],
"Dog": [0xe3f0afeb109b283a, 0x29998d292938eb61, 0x6aab788333cfc2a3, 0x492ff1d295910ea7],
"Person": [0x2831cf046084d96d, 0xbe19b13ace54641, 0x635a082728b0f6f0, 0x3d4ef2dd4b74a87c]
]
XCTAssertEqual(
versionLock.description,
"""
[
"Animal": [0x1b59d511019695cf, 0xdeb97e86c5eff179, 0x1cfd80745646cb3, 0x4ff99416175b5b9a],
"Dog": [0xe3f0afeb109b283a, 0x29998d292938eb61, 0x6aab788333cfc2a3, 0x492ff1d295910ea7],
"Person": [0x2831cf046084d96d, 0xbe19b13ace54641, 0x635a082728b0f6f0, 0x3d4ef2dd4b74a87c]
]
"""
)
}
}

View File

@@ -922,11 +922,11 @@ extension VersionLock: CustomStringConvertible, CustomDebugStringConvertible, Co
for (index, keyValue) in self.hashesByEntityName.sorted(by: { $0.key < $1.key }).enumerated() {
let data = keyValue.value
let count = data.count
let bytes = data.withUnsafeBytes { (pointer) in
return (0 ..< (count / MemoryLayout<HashElement>.size))
.map({ "\("0x\(String(pointer[$0], radix: 16, uppercase: false))")" })
return pointer
.bindMemory(to: VersionLock.HashElement.self)
.map({ "\("0x\(String($0, radix: 16, uppercase: false))")" })
}
string.append("\(index == 0 ? "\n" : ",\n")\"\(keyValue.key)\": [\(bytes.joined(separator: ", "))]")
}

View File

@@ -153,11 +153,10 @@ extension DynamicSchema {
valueType = Data.self
if let defaultValue = (attribute.defaultValue as! Data.QueryableNativeType?).flatMap(Data.cs_fromQueryableNativeType) {
let count = defaultValue.count
let bytes = defaultValue.withUnsafeBytes { (pointer) in
return (0 ..< (count / MemoryLayout<UInt8>.size))
.map({ "\("0x\(String(pointer[$0], radix: 16, uppercase: false))")" })
return pointer
.bindMemory(to: UInt64.self)
.map({ "\("0x\(String($0, radix: 16, uppercase: false))")" })
}
defaultString = ", initial: Data(bytes: [\(bytes.joined(separator: ", "))])"
}