From 7bde2a16df3715a8deb12dfd4dd578c6a07cf43b Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 21 Nov 2015 15:52:41 +0100 Subject: [PATCH] add tests and documentation --- Source/SpeedLog.swift | 10 ++++++---- Tests/SpeedLogTests.swift | 34 +++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index ed7bcbd..47c0114 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -10,6 +10,7 @@ import Foundation typealias SLog = SpeedLog +///LogMode type. Specify what details should be included to the log public struct LogMode : OptionSetType { private var value: UInt = 0 @@ -31,9 +32,10 @@ public struct LogMode : OptionSetType { public static var AllOptions: LogMode { return [FileName, FuncName, Line] } } +///SpeedLog Type public struct SpeedLog { - - public static var mode: LogMode = LogMode.None + /// Log Mode + public static var mode: LogMode = .None public static func print(items: Any..., separator: String = " ", terminator: String = "\n", _ file: String = __FILE__, _ function: String = __FUNCTION__, _ line: Int = __LINE__) { #if ENABLE_LOG @@ -44,11 +46,10 @@ public struct SpeedLog { } } -private extension SpeedLog { +extension SpeedLog { static func printStringForMode(file: String, function: String, line: Int) -> String { var result: String = "" - //print("\(filename).\(function)[\(line)]: \(object)") if mode.contains(.FileName) { let filename = file.lastPathComponent.stringByDeletingPathExtension result = "\(filename)." @@ -68,6 +69,7 @@ private extension SpeedLog { } } +/// String syntax sugar extension extension String { var ns: NSString { return self as NSString diff --git a/Tests/SpeedLogTests.swift b/Tests/SpeedLogTests.swift index 2e8595a..3248980 100644 --- a/Tests/SpeedLogTests.swift +++ b/Tests/SpeedLogTests.swift @@ -11,19 +11,35 @@ import XCTest class SpeedLogTests: XCTestCase { - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. + func testEmptyPrefix() { + let prefix = logForMode(.None) + XCTAssertEqual(prefix, "") } - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() + func testFilePrefix() { + let prefix = logForMode(.FileName) + XCTAssertEqual(prefix, "File.: ") + //FIXME: remove "." from string } - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. + func testFuncPrefix() { + let prefix = logForMode(.FuncName) + XCTAssertEqual(prefix, "FuncA: ") } + func testLinePrefix() { + let prefix = logForMode(.Line) + XCTAssertEqual(prefix, "[\(10)]: ") + } } + +// MARK: - Helpers +extension SpeedLogTests { + + func logForMode(mode: LogMode) -> String { + SpeedLog.mode = mode + return SpeedLog.printStringForMode("File", function: "FuncA", line: 10) + } +} + +