CommandLineToolkit
64 строки · 1.8 Кб
1/*
2* Copyright (c) Avito Tech LLC
3*/
4
5import Foundation
6import CLTLogging
7import CLTLoggingModels
8import XCTest
9
10final class NSLogLikeLogEntryTextFormatterTests: XCTestCase {
11func test___with_location_with_coordinates() {
12let formatter = NSLogLikeLogEntryTextFormatter(
13logLocation: true,
14logCoordinates: true
15)
16
17let entry = LogEntry(
18file: "file",
19line: 42,
20coordinates: [
21LogEntryCoordinate(name: "some"),
22LogEntryCoordinate(name: "coordinate", value: "value"),
23],
24message: "message",
25timestamp: Date(),
26verbosity: .always
27)
28let text = formatter.format(logEntry: entry)
29
30let expectedTimestamp = NSLogLikeLogEntryTextFormatter.logDateFormatter.string(from: entry.timestamp)
31
32XCTAssertEqual(
33text,
34"[ALWAYS] \(expectedTimestamp) file:42 some coordinate:value: message"
35)
36}
37
38func test___without_location_without_coordinates() {
39let formatter = NSLogLikeLogEntryTextFormatter(
40logLocation: false,
41logCoordinates: false
42)
43
44let entry = LogEntry(
45file: "file",
46line: 42,
47coordinates: [
48LogEntryCoordinate(name: "some"),
49LogEntryCoordinate(name: "coordinate", value: "value"),
50],
51message: "message",
52timestamp: Date(),
53verbosity: .always
54)
55let text = formatter.format(logEntry: entry)
56
57let expectedTimestamp = NSLogLikeLogEntryTextFormatter.logDateFormatter.string(from: entry.timestamp)
58
59XCTAssertEqual(
60text,
61"[ALWAYS] \(expectedTimestamp): message"
62)
63}
64}
65