Skip to content

Commit d3f9a33

Browse files
committed
[PlaygroundLogger] Added support for logging CGFloat instances as their native type.
This represents an enhancement over the previous logger, which did not handle CGFloat instances specially at all. This addresses <rdar://problem/37421663>.
1 parent 7d33d3a commit d3f9a33

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

PlaygroundLogger/PlaygroundLogger.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
5E4AF1AF1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */; };
7777
5E5FE50B202D13C800E28C3C /* PGLConcurrentMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5FE50A202D13C800E28C3C /* PGLConcurrentMap.swift */; };
7878
5ECE8F911FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */; };
79+
5EE3867420352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EE3867320352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift */; };
7980
/* End PBXBuildFile section */
8081

8182
/* Begin PBXContainerItemProxy section */
@@ -161,6 +162,7 @@
161162
5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyEntrypoints.swift; sourceTree = "<group>"; };
162163
5E5FE50A202D13C800E28C3C /* PGLConcurrentMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PGLConcurrentMap.swift; sourceTree = "<group>"; };
163164
5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyPlaygroundLoggerTests.swift; sourceTree = "<group>"; };
165+
5EE3867320352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGFloat+CustomOpaqueLoggable.swift"; sourceTree = "<group>"; };
164166
/* End PBXFileReference section */
165167

166168
/* Begin PBXFrameworksBuildPhase section */
@@ -375,6 +377,7 @@
375377
5E27566D1FC51F7E00B69C83 /* CGGeometry+CustomOpaqueLoggable.swift */,
376378
5E27566F1FC51FCB00B69C83 /* CGColor+OpaquePlaygroundLoggable.swift */,
377379
5E2756711FC51FF400B69C83 /* CGImage+CustomOpaqueLoggable.swift */,
380+
5EE3867320352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift */,
378381
);
379382
path = CoreGraphics;
380383
sourceTree = "<group>";
@@ -544,6 +547,7 @@
544547
buildActionMask = 2147483647;
545548
files = (
546549
5E2756321FC48FD300B69C83 /* NSRange+KeyedArchiveOpaqueRepresentation.swift in Sources */,
550+
5EE3867420352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift in Sources */,
547551
5E27565A1FC4F35300B69C83 /* FloatingPoint+CustomOpaqueLoggable.swift in Sources */,
548552
5E2756241FC4886A00B69C83 /* String+TaggedOpaqueRepresentation.swift in Sources */,
549553
5E27563D1FC4D17F00B69C83 /* CGColor+KeyedArchiveOpaqueRepresentation.swift in Sources */,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--- CGFloat+CustomOpaqueLoggable.swift -------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import CoreGraphics
14+
15+
extension CGFloat: CustomOpaqueLoggable {
16+
var opaqueRepresentation: LogEntry.OpaqueRepresentation {
17+
return self.native
18+
}
19+
}

PlaygroundLogger/PlaygroundLoggerTests/LegacyPlaygroundLoggerTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,44 @@ class LegacyPlaygroundLoggerTests: XCTestCase {
575575
}
576576

577577
// testUInt64EightBytesEncoding(), testNSColorLogging(), and testStructLogging() are excluded, as in their current form they test implementation details of the legacy logger.
578+
579+
// MARK: - New Tests Using Legacy Infrastructure
580+
581+
// These are tests which did not exist in the previous test suite, but which use the legacy infrastructure to run.
582+
// They should be migrated to new test infrastructure once such a thing exists.
583+
584+
func testCGFloatLogging() {
585+
let cgFloat: CGFloat = 2.0
586+
let logdata = legacyLog(instance: cgFloat, name: "cgFloat", id: 0, startLine: 0, endLine: 0, startColumn: 0, endColumn: 0) as! NSData
587+
guard let decoded = legacyLogDecode(logdata), let iderepr = decoded.object as? PlaygroundDecodedObject_IDERepr else {
588+
XCTFail("Decoded object is not IDERepr")
589+
return
590+
}
591+
592+
XCTAssertEqual(iderepr.name, "cgFloat")
593+
XCTAssertEqual(iderepr.typeName, "CoreGraphics.CGFloat")
594+
XCTAssertEqual(iderepr.summary, "2.0")
595+
596+
if CGFloat.NativeType.self == Double.self {
597+
XCTAssertEqual(iderepr.tag, "DOBL")
598+
guard iderepr.payload is Double else {
599+
XCTFail("Expected a Double as payload but did not have one")
600+
return
601+
}
602+
XCTAssertEqual(iderepr.payload as! Double, 2.0 as Double)
603+
}
604+
else if CGFloat.NativeType.self == Float.self {
605+
XCTAssertEqual(iderepr.tag, "FLOT")
606+
guard iderepr.payload is Float else {
607+
XCTFail("Expected a Float as payload but did not have one")
608+
return
609+
}
610+
XCTAssertEqual(iderepr.payload as! Float, 2.0 as Float)
611+
}
612+
else {
613+
XCTFail("Unknown CGFloat.NativeType: \(CGFloat.NativeType.self)")
614+
}
615+
}
578616
}
579617

580618
// generic so can't be nested in the test case itself

0 commit comments

Comments
 (0)