File tree Expand file tree Collapse file tree 2 files changed +54
-2
lines changed
Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,30 @@ class Test: XCTestCase
149149 }
150150 }
151151
152+ func testChild( )
153+ {
154+ let set = ColorSet ( )
155+ let child = ColorSet ( )
156+ let clear = NSColor . clear
157+ let red = NSColor . red
158+
159+ XCTAssertNil ( set [ " foo " ] )
160+
161+ set. add ( child: child )
162+
163+ XCTAssertNil ( set [ " foo " ] )
164+
165+ child. add ( color: red, forName: " foo " )
166+
167+ XCTAssertNotNil ( set [ " foo " ] )
168+ XCTAssertTrue ( set [ " foo " ] !. color === red )
169+
170+ set. add ( color: clear, forName: " foo " )
171+
172+ XCTAssertNotNil ( set [ " foo " ] )
173+ XCTAssertTrue ( set [ " foo " ] !. color === clear )
174+ }
175+
152176 func testCreate( )
153177 {
154178 var set = ColorSet ( )
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ import Cocoa
5555 return set ?? ColorSet ( )
5656 } ( )
5757
58- private var colors = [ String : ColorPair ] ( )
58+ private var colors = [ String : ColorPair ] ( )
59+ private var children = [ ColorSet ] ( )
5960
6061 @objc public var count : Int
6162 {
@@ -139,7 +140,34 @@ import Cocoa
139140 {
140141 return self . synchronized
141142 {
142- return self . colors [ name ]
143+ if let color = self . colors [ name ]
144+ {
145+ return color
146+ }
147+
148+ for child in self . children
149+ {
150+ if let color = child [ name ]
151+ {
152+ return color
153+ }
154+ }
155+
156+ return nil
157+ }
158+ }
159+
160+ @objc ( addChild: )
161+ public func add( child: ColorSet )
162+ {
163+ if child === self
164+ {
165+ return
166+ }
167+
168+ self . synchronized
169+ {
170+ self . children. append ( child )
143171 }
144172 }
145173
You can’t perform that action at this time.
0 commit comments