Skip to content

Commit

Permalink
add tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kostiakoval committed Nov 21, 2015
1 parent 39ba203 commit 7bde2a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
10 changes: 6 additions & 4 deletions Source/SpeedLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)."
Expand All @@ -68,6 +69,7 @@ private extension SpeedLog {
}
}

/// String syntax sugar extension
extension String {
var ns: NSString {
return self as NSString
Expand Down
34 changes: 25 additions & 9 deletions Tests/SpeedLogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}


0 comments on commit 7bde2a1

Please sign in to comment.