Skip to content

Commit 43b71cd

Browse files
committed
Unit tests
1 parent 62b111a commit 43b71cd

File tree

3 files changed

+109
-3
lines changed

3 files changed

+109
-3
lines changed

ColorSet.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
05DB415323846DCB0026C565 /* DictionaryRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05DB415223846DCB0026C565 /* DictionaryRepresentable.swift */; };
5252
05DB415723847CE80026C565 /* SaveAsOptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05DB415623847CE80026C565 /* SaveAsOptionsViewController.swift */; };
5353
05DB415A23847CF80026C565 /* ColorSet.SaveAsOptionsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 05DB415823847CF80026C565 /* ColorSet.SaveAsOptionsViewController.xib */; };
54+
05DB415C23854B2B0026C565 /* Colors-XML.colorset in Resources */ = {isa = PBXBuildFile; fileRef = 05DB415B23854B2B0026C565 /* Colors-XML.colorset */; };
5455
/* End PBXBuildFile section */
5556

5657
/* Begin PBXContainerItemProxy section */
@@ -177,6 +178,7 @@
177178
05DB415223846DCB0026C565 /* DictionaryRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DictionaryRepresentable.swift; sourceTree = "<group>"; };
178179
05DB415623847CE80026C565 /* SaveAsOptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveAsOptionsViewController.swift; sourceTree = "<group>"; };
179180
05DB415923847CF80026C565 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ColorSet.SaveAsOptionsViewController.xib; sourceTree = "<group>"; };
181+
05DB415B23854B2B0026C565 /* Colors-XML.colorset */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "Colors-XML.colorset"; sourceTree = "<group>"; };
180182
/* End PBXFileReference section */
181183

182184
/* Begin PBXFrameworksBuildPhase section */
@@ -428,6 +430,7 @@
428430
isa = PBXGroup;
429431
children = (
430432
057DC45722B14CC300BA6727 /* Colors.colorset */,
433+
05DB415B23854B2B0026C565 /* Colors-XML.colorset */,
431434
057DC44D22B1492200BA6727 /* Test.swift */,
432435
057DC44F22B1492200BA6727 /* Info.plist */,
433436
);
@@ -597,6 +600,7 @@
597600
isa = PBXResourcesBuildPhase;
598601
buildActionMask = 2147483647;
599602
files = (
603+
05DB415C23854B2B0026C565 /* Colors-XML.colorset in Resources */,
600604
057DC45822B14CC300BA6727 /* Colors.colorset in Resources */,
601605
);
602606
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>colors</key>
6+
<dict>
7+
<key>NoVariant</key>
8+
<dict>
9+
<key>color</key>
10+
<dict>
11+
<key>a</key>
12+
<real>0.5</real>
13+
<key>h</key>
14+
<real>0.58333333333333337</real>
15+
<key>l</key>
16+
<real>0.39215686274509803</real>
17+
<key>s</key>
18+
<real>0.50000000000000011</real>
19+
</dict>
20+
<key>lightnesses</key>
21+
<array/>
22+
</dict>
23+
<key>Variant</key>
24+
<dict>
25+
<key>color</key>
26+
<dict>
27+
<key>a</key>
28+
<real>0.75</real>
29+
<key>h</key>
30+
<real>0.083333333333333329</real>
31+
<key>l</key>
32+
<real>0.78431372549019607</real>
33+
<key>s</key>
34+
<real>0.90909090909090917</real>
35+
</dict>
36+
<key>lightnesses</key>
37+
<array/>
38+
<key>variant</key>
39+
<dict>
40+
<key>a</key>
41+
<real>0.25</real>
42+
<key>h</key>
43+
<real>0.75</real>
44+
<key>l</key>
45+
<real>0.78431372549019607</real>
46+
<key>s</key>
47+
<real>0.90909090909090917</real>
48+
</dict>
49+
</dict>
50+
</dict>
51+
<key>magic</key>
52+
<integer>4850179227268629844</integer>
53+
<key>major</key>
54+
<integer>1</integer>
55+
<key>minor</key>
56+
<integer>2</integer>
57+
</dict>
58+
</plist>

ColorSetKit-Test/Test.swift

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Test: XCTestCase
3434
self.bundle = Bundle( for: type( of: self ) )
3535
}
3636

37-
func testInitWithURL()
37+
func testInitWithURLBinary()
3838
{
3939
guard let url = self.bundle?.url( forResource: "Colors", withExtension: "colorset" ) else
4040
{
@@ -47,7 +47,20 @@ class Test: XCTestCase
4747
}
4848
}
4949

50-
func testInitWithPath()
50+
func testInitWithURLXML()
51+
{
52+
guard let url = self.bundle?.url( forResource: "Colors-XML", withExtension: "colorset" ) else
53+
{
54+
XCTFail( "Cannot get URL of colorset file" ); return
55+
}
56+
57+
guard let _ = ColorSet( url: url ) else
58+
{
59+
XCTFail( "Cannot create colorset file" ); return
60+
}
61+
}
62+
63+
func testInitWithPathBinary()
5164
{
5265
guard let path = self.bundle?.path( forResource: "Colors", ofType: "colorset" ) else
5366
{
@@ -60,7 +73,20 @@ class Test: XCTestCase
6073
}
6174
}
6275

63-
func testInitWithData()
76+
func testInitWithPathXML()
77+
{
78+
guard let path = self.bundle?.path( forResource: "Colors-XML", ofType: "colorset" ) else
79+
{
80+
XCTFail( "Cannot get URL of colorset file" ); return
81+
}
82+
83+
guard let _ = ColorSet( path: path ) else
84+
{
85+
XCTFail( "Cannot create colorset file" ); return
86+
}
87+
}
88+
89+
func testInitWithDataBinary()
6490
{
6591
guard let path = self.bundle?.path( forResource: "Colors", ofType: "colorset" ) else
6692
{
@@ -78,6 +104,24 @@ class Test: XCTestCase
78104
}
79105
}
80106

107+
func testInitWithDataXML()
108+
{
109+
guard let path = self.bundle?.path( forResource: "Colors-XML", ofType: "colorset" ) else
110+
{
111+
XCTFail( "Cannot get URL of colorset file" ); return
112+
}
113+
114+
guard let data = FileManager.default.contents( atPath: path ) else
115+
{
116+
XCTFail( "Cannot read contents of colorset file" ); return
117+
}
118+
119+
guard let _ = ColorSet( data: data ) else
120+
{
121+
XCTFail( "Cannot create colorset file" ); return
122+
}
123+
}
124+
81125
func testShared()
82126
{
83127
XCTAssertEqual( ColorSet.shared.colors.count, 2 )

0 commit comments

Comments
 (0)