forked from CodeEditApp/CodeEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTests_Extensions.swift
More file actions
136 lines (98 loc) · 3.63 KB
/
UnitTests_Extensions.swift
File metadata and controls
136 lines (98 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// UnitTests.swift
// CodeEditModules/CodeEditUtilsTests
//
// Created by Lukas Pistrol on 01.05.22.
//
import Foundation
import SwiftUI
import XCTest
@testable import CodeEdit
final class CodeEditUtilsExtensionsUnitTests: XCTestCase {
// MARK: - COLOR + HEX
func testColorConversionFromHEXString() throws {
let colorString = "#123456"
let color = Color(hex: colorString)
XCTAssertEqual(colorString, color.hexString)
}
func testNSColorConversionFromHEXString() throws {
let colorString = "#123456"
let color = NSColor(hex: colorString)
XCTAssertEqual(colorString, color.hexString)
}
func testColorConversionFromHEXInt() throws {
let colorInt = 0x123456
let color = Color(hex: colorInt)
XCTAssertEqual(colorInt, color.hex)
}
func testNSColorConversionFromHEXInt() throws {
let colorInt = 0x123456
let color = NSColor(hex: colorInt)
XCTAssertEqual(colorInt, color.hex)
}
func testColorConversionAlphaValue() throws {
let alpha = 0.25
let color = Color(hex: "#123456", alpha: alpha)
XCTAssertEqual(alpha, color.alphaComponent)
}
func testNSColorConversionAlphaValue() throws {
let alpha = 0.25
let color = NSColor(hex: "#123456", alpha: alpha)
XCTAssertEqual(alpha, color.alphaComponent)
}
// MARK: - DATE + FORMATTED
func testRelativeDateStringMinutes() throws {
let date = Date.now.addingTimeInterval(-61)
let string = date.relativeStringToNow(locale: Locale(identifier: "en_US"))
XCTAssertEqual("1 min. ago", string)
}
func testRelativeDateStringHours() throws {
let date = Date.now.addingTimeInterval(-3_601)
let string = date.relativeStringToNow(locale: Locale(identifier: "en_US"))
XCTAssertEqual("1 hr. ago", string)
}
func testRelativeDateStringDays() throws {
let date = Date.now.addingTimeInterval(-86_400)
let string = date.relativeStringToNow(locale: Locale(identifier: "en_US"))
XCTAssertEqual("yesterday", string)
}
// MARK: - STRING + MD5
func testMD5GenerationCaseSensitive() throws {
let testString = "CodeEdit"
let md5 = testString.md5(caseSensitive: true)
let result = "8ba8c8fd0442f7bae4d441e2a3fda706"
XCTAssertEqual(result, md5)
}
func testMD5Generation() throws {
let testString = "CodeEdit"
let md5 = testString.md5(caseSensitive: false)
let result = "4cdf122ff382a2d929eddc1a63473ec1"
XCTAssertEqual(result, md5)
}
// MARK: - STRING + SHA256
func testSHA256GenerationCaseSensitive() throws {
let testString = "CodeEdit"
let md5 = testString.sha256(caseSensitive: true)
let result = "52125689c088f1783e53c48db78a4fe7b3fa10b12d8fba205fcf054e5ef3789a"
XCTAssertEqual(result, md5)
}
func test256Generation() throws {
let testString = "CodeEdit"
let md5 = testString.sha256(caseSensitive: false)
let result = "7c3f327eab3860fc823a99623b348afbf1d7aebaec5d21289fbaeab0f6340e4a"
XCTAssertEqual(result, md5)
}
// MARK: - STRING + REMOVING OCCURRENCIES
func testRemovingNewLines() throws {
let string = "Hello, \nWorld!"
let withoutNewLines = string.removingNewLines()
let result = "Hello, World!"
XCTAssertEqual(result, withoutNewLines)
}
func testRemovingSpaces() throws {
let string = "Hello, World!"
let withoutSpaces = string.removingSpaces()
let result = "Hello,World!"
XCTAssertEqual(result, withoutSpaces)
}
}