mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-23 15:05:52 +00:00
Further capp_linting.
Reviewed by me.
This commit is contained in:
1 parent
dd560fb78c
commit
400bdb5103
19 files changed
+443
-445
No files matched your search
@@ -220,14 +220,14 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0,
|
||||
[_draggingUpdateTimer invalidate];
|
||||
_draggingUpdateTimer = nil;
|
||||
|
||||
var dragOperation = CPDragOperationCopy;
|
||||
var dragOperation = CPDragOperationCopy,
|
||||
// We have to convert base to bridge since the drag event comes from the source window, not the drag window.
|
||||
var draggingDestination = [aPlatformWindow _dragHitTest:aLocation pasteboard:[CPDragServerDraggingInfo draggingPasteboard]];
|
||||
draggingDestination = [aPlatformWindow _dragHitTest:aLocation pasteboard:[CPDragServerDraggingInfo draggingPasteboard]];
|
||||
|
||||
if (draggingDestination)
|
||||
_draggingLocation = [DRAGGING_WINDOW(draggingDestination) convertPlatformWindowToBase:aLocation];
|
||||
|
||||
if(draggingDestination !== _draggingDestination)
|
||||
if (draggingDestination !== _draggingDestination)
|
||||
{
|
||||
if ([_draggingDestination respondsToSelector:@selector(draggingExited:)])
|
||||
[_draggingDestination draggingExited:CPDragServerDraggingInfo];
|
||||
|
||||
+1
-1
@@ -557,7 +557,7 @@ var _CPEventPeriodicEventPeriod = 0,
|
||||
if (_modifierFlags & (CPCommandKeyMask | CPControlKeyMask))
|
||||
return YES;
|
||||
|
||||
for(var i=0; i<characterCount; i++)
|
||||
for (var i = 0; i < characterCount; i++)
|
||||
{
|
||||
switch(_characters.charAt(i))
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ var sharedObject = [CPObject new];
|
||||
- (CPAttributedString)stringForTesting
|
||||
{
|
||||
var string = [[CPAttributedString alloc] initWithString:"The quick brown fox jumped over the lazy dog."];
|
||||
|
||||
|
||||
string._rangeEntries = [];
|
||||
|
||||
|
||||
string._rangeEntries.push({
|
||||
range:CPMakeRange(0, 9),
|
||||
attributes:[CPDictionary dictionaryWithObjects:[1, "bar", sharedObject, 20] forKeys:["a", "b", "c", "d"]]
|
||||
@@ -27,7 +27,7 @@ var sharedObject = [CPObject new];
|
||||
range:CPMakeRange(32, 13),
|
||||
attributes:[CPDictionary dictionaryWithObjects:[37, "baz", 1, 20, 55, 43] forKeys:["a", "b", "c", "d", "e", "f"]]
|
||||
});
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ var sharedObject = [CPObject new];
|
||||
{
|
||||
var string = [[CPAttributedString alloc] initWithString:@"hi there"];
|
||||
|
||||
[self assertTrue:([string string] === @"hi there")
|
||||
[self assertTrue:([string string] === @"hi there")
|
||||
message:"testInitWithString: expected:" + @"hi there" + " actual:" + [string string]];
|
||||
}
|
||||
- (void)testInitWithAttributedString
|
||||
@@ -43,13 +43,13 @@ var sharedObject = [CPObject new];
|
||||
var string = [[CPAttributedString alloc] initWithString:@"hi there"],
|
||||
attributedString = [[CPAttributedString alloc] initWithAttributedString:string];
|
||||
|
||||
[self assertTrue:([string isEqualToAttributedString:attributedString])
|
||||
[self assertTrue:([string isEqualToAttributedString:attributedString])
|
||||
message:"testInitWithAttributedString: expected:" + string + " actual:" + attributedString];
|
||||
|
||||
|
||||
//TODO add a case where we init with a string that actually adds attributes
|
||||
string = [[CPAttributedString alloc] initWithAttributedString:[self stringForTesting]];
|
||||
|
||||
[self assertTrue:([string isEqualToAttributedString:[self stringForTesting]])
|
||||
[self assertTrue:([string isEqualToAttributedString:[self stringForTesting]])
|
||||
message:"testInitWithAttributedString: expected:" + [self stringForTesting] + " actual:" + string];
|
||||
}
|
||||
|
||||
@@ -57,15 +57,15 @@ var sharedObject = [CPObject new];
|
||||
{
|
||||
var string = [[CPAttributedString alloc] initWithString:@"hi there" attributes:[CPDictionary dictionary]];
|
||||
|
||||
[self assertTrue:([string string] === @"hi there")
|
||||
[self assertTrue:([string string] === @"hi there")
|
||||
message:"testIinitWithString_attributes: expected:" + @"hi there" + " actual:" + [string string]];
|
||||
|
||||
var string = [[CPAttributedString alloc] initWithString:@"hi there" attributes:[CPDictionary dictionaryWithObjects:[1, "bar"] forKeys:["number", "foo"]]];
|
||||
|
||||
[self assertTrue:([[string attributesAtIndex:0 effectiveRange:nil] objectForKey:@"number"] === 1)
|
||||
[self assertTrue:([[string attributesAtIndex:0 effectiveRange:nil] objectForKey:@"number"] === 1)
|
||||
message:"testIinitWithString_attributes: value for key 'number' expected:" + 1 + " actual:" + [[string attributesAtIndex:0 effectiveRange:nil] objectForKey:@"number"]];
|
||||
|
||||
[self assertTrue:([[string attributesAtIndex:0 effectiveRange:nil] objectForKey:@"foo"] === "bar")
|
||||
[self assertTrue:([[string attributesAtIndex:0 effectiveRange:nil] objectForKey:@"foo"] === "bar")
|
||||
message:"testIinitWithString_attributes: value for key 'foo' expected:" + "bar" + " actual:" + [[string attributesAtIndex:0 effectiveRange:nil] objectForKey:@"foo"]];
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ var sharedObject = [CPObject new];
|
||||
{
|
||||
var string = [[CPAttributedString alloc] initWithString:@"hi there"];
|
||||
|
||||
[self assertTrue:([string string] === string._string)
|
||||
[self assertTrue:([string string] === string._string)
|
||||
message:"testString: expected:" + @"hi there" + " actual:" + [string string]];
|
||||
}
|
||||
|
||||
@@ -82,25 +82,25 @@ var sharedObject = [CPObject new];
|
||||
{
|
||||
var string = [[CPAttributedString alloc] initWithString:@"hi there"];
|
||||
|
||||
[self assertTrue:([string length] === 8)
|
||||
[self assertTrue:([string length] === 8)
|
||||
message:"testLength: expected:" + 8 + " actual:" + [string length]];
|
||||
|
||||
[self assertTrue:([[self stringForTesting] length] === 45)
|
||||
[self assertTrue:([[self stringForTesting] length] === 45)
|
||||
message:"testLength: expected:" + 45 + " actual:" + [[self stringForTesting] length]];
|
||||
}
|
||||
|
||||
- (void)test_indexOfEntryWithIndex
|
||||
{
|
||||
var string = [self stringForTesting];
|
||||
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:0]===0 message:@"expecting index 0, was:"+[string _indexOfEntryWithIndex:0]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:10]===1 message:@"expecting index 1, was:"+[string _indexOfEntryWithIndex:10]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:30]===2 message:@"expecting index 2, was:"+[string _indexOfEntryWithIndex:30]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:35]===3 message:@"expecting index 3, was:"+[string _indexOfEntryWithIndex:35]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:8]===0 message:@"expecting index 0, was:"+[string _indexOfEntryWithIndex:8]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:9]===1 message:@"expecting index 1, was:"+[string _indexOfEntryWithIndex:9]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:20]===2 message:@"expecting index 2, was:"+[string _indexOfEntryWithIndex:20]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:32]===3 message:@"expecting index 3, was:"+[string _indexOfEntryWithIndex:32]];
|
||||
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:0] === 0 message:@"expecting index 0, was:" + [string _indexOfEntryWithIndex:0]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:10] === 1 message:@"expecting index 1, was:" + [string _indexOfEntryWithIndex:10]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:30] === 2 message:@"expecting index 2, was:" + [string _indexOfEntryWithIndex:30]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:35] === 3 message:@"expecting index 3, was:" + [string _indexOfEntryWithIndex:35]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:8] === 0 message:@"expecting index 0, was:" + [string _indexOfEntryWithIndex:8]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:9] === 1 message:@"expecting index 1, was:" + [string _indexOfEntryWithIndex:9]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:20] === 2 message:@"expecting index 2, was:" + [string _indexOfEntryWithIndex:20]];
|
||||
[self assertTrue:[string _indexOfEntryWithIndex:32] === 3 message:@"expecting index 3, was:" + [string _indexOfEntryWithIndex:32]];
|
||||
}
|
||||
|
||||
//Retrieving Attribute Information
|
||||
@@ -108,7 +108,7 @@ var sharedObject = [CPObject new];
|
||||
{
|
||||
var string = [self stringForTesting],
|
||||
expectedValues = {a:1, b:"bar", c:sharedObject, d:20};
|
||||
|
||||
|
||||
testAttributesAtIndexWithValues(string, 1, expectedValues, self);
|
||||
|
||||
expectedValues = {a:37, b:"baz", f:43}
|
||||
@@ -118,28 +118,28 @@ var sharedObject = [CPObject new];
|
||||
|
||||
//- (CPDictionary)attributesAtIndex:(unsigned)anIndex longestEffectiveRange:(CPRangePointer)aRange inRange:(CPRange)rangeLimit
|
||||
- (void)testAttributesAtIndexLongestEffectiveRangeInRange
|
||||
{
|
||||
{
|
||||
var string = [self stringForTesting];
|
||||
|
||||
string._rangeEntries[3].range.length = 10;
|
||||
string._rangeEntries.push({range:CPMakeRange(42, 3), attributes:[string._rangeEntries[3].attributes copy]});
|
||||
|
||||
|
||||
var range = CPMakeRange(0, 0),
|
||||
attributes = [string attributesAtIndex:35 longestEffectiveRange:range inRange:CPMakeRange(0, 43)];
|
||||
|
||||
[self assertTrue:CPMaxRange(range)==43 message:@"expecting attributes to be valuable at range 43, was: "+CPMaxRange(range)];
|
||||
[self assertTrue:range.location==32 message:@"expecting attributes to be valuable at range 32, was: "+range.location];
|
||||
|
||||
[self assertTrue:[attributes objectForKey:"a"]===37 message:@"expecting 'a' to be '1', was: "+[attributes objectForKey:"a"]];
|
||||
[self assertTrue:[attributes objectForKey:"b"]==="baz" message:@"expecting 'b' to be 'baz', was: "+[attributes objectForKey:"b"]];
|
||||
[self assertTrue:[attributes objectForKey:"f"]===43 message:@"expecting 'f' to be 43, was: "+[attributes objectForKey:"f"]];
|
||||
[self assertTrue:CPMaxRange(range) == 43 message:@"expecting attributes to be valuable at range 43, was: " + CPMaxRange(range)];
|
||||
[self assertTrue:range.location == 32 message:@"expecting attributes to be valuable at range 32, was: " + range.location];
|
||||
|
||||
[self assertTrue:[attributes objectForKey:"a"] === 37 message:@"expecting 'a' to be '1', was: " + [attributes objectForKey:"a"]];
|
||||
[self assertTrue:[attributes objectForKey:"b"] === "baz" message:@"expecting 'b' to be 'baz', was: " + [attributes objectForKey:"b"]];
|
||||
[self assertTrue:[attributes objectForKey:"f"] === 43 message:@"expecting 'f' to be 43, was: " + [attributes objectForKey:"f"]];
|
||||
}
|
||||
|
||||
//- (id)attribute:(CPString)attribute atIndex:(unsigned)index effectiveRange:(CPRangePointer)aRange
|
||||
- (void)testAttributeAtIndexEffectiveRange
|
||||
{
|
||||
var string = [self stringForTesting];
|
||||
|
||||
|
||||
testAttributeAtIndexWithValue(string, 1, "a", 1, self);
|
||||
testAttributeAtIndexWithValue(string, 20, "d", [CPNull null], self);
|
||||
}
|
||||
@@ -148,34 +148,34 @@ var sharedObject = [CPObject new];
|
||||
- (void)testAttributeAtIndexLongestEffectiveRangeInRange
|
||||
{
|
||||
var string = [self stringForTesting];
|
||||
|
||||
|
||||
var range = CPMakeRange(0, 0),
|
||||
attribute = [string attribute:"b" atIndex:35 longestEffectiveRange:range inRange:CPMakeRange(0, 43)];
|
||||
|
||||
[self assertTrue:CPMaxRange(range)==43 message:@"expecting attributes to be valuable at range 43, was: "+CPMaxRange(range)];
|
||||
[self assertTrue:range.location==9 message:@"expecting attributes to be valuable at range 9, was: "+range.location];
|
||||
|
||||
[self assertTrue:attribute==="baz" message:@"expecting 'b' to be 'baz', was: "+attribute];
|
||||
[self assertTrue:CPMaxRange(range) == 43 message:@"expecting attributes to be valuable at range 43, was: " + CPMaxRange(range)];
|
||||
[self assertTrue:range.location == 9 message:@"expecting attributes to be valuable at range 9, was: " + range.location];
|
||||
|
||||
[self assertTrue:attribute === "baz" message:@"expecting 'b' to be 'baz', was: " + attribute];
|
||||
}
|
||||
|
||||
//Comparing Attributed Strings
|
||||
- (void)testIsEqualToAttributedString
|
||||
{
|
||||
[self assertTrue:[[self stringForTesting] isEqualToAttributedString:[self stringForTesting]] message:"expected stringForTesting to equal itself, but it didn't"];
|
||||
|
||||
|
||||
[self assertFalse:[[self stringForTesting] isEqualToAttributedString:[[CPAttributedString alloc] initWithString:@"HELLO!"]] message:"Expected stringForTesting to not equal 'HELLO!', but it did"];
|
||||
}
|
||||
|
||||
- (void)testIsEqual
|
||||
{
|
||||
[self assertTrue:[[self stringForTesting] isEqual:[self stringForTesting]] message:"expected stringForTesting to equal itself, but it didn't"];
|
||||
|
||||
|
||||
[self assertFalse:[[self stringForTesting] isEqual:[[CPAttributedString alloc] initWithString:@"HELLO!"]] message:"Expected stringForTesting to not equal 'HELLO!', but it did"];
|
||||
|
||||
var a = [self stringForTesting];
|
||||
|
||||
|
||||
[self assertTrue:[a isEqual:a] message:"expected a to equal itself, but it didn't"];
|
||||
|
||||
|
||||
[self assertFalse:[a isEqual:@"HELLO!"] message:"Expected a to not equal 'HELLO!', but it did"];
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ var sharedObject = [CPObject new];
|
||||
|
||||
var c = [[self stringForTesting] attributedSubstringFromRange:CPMakeRange(0, 45)];
|
||||
[self assertTrue:[c isEqual:[self stringForTesting]] message:"expected c to equal itself, but it didn't"];
|
||||
|
||||
|
||||
var d = [[self stringForTesting] attributedSubstringFromRange:CPMakeRange(9, 11)],
|
||||
expectedValues = {a:2, b:"baz", c:sharedObject};
|
||||
|
||||
@@ -205,8 +205,8 @@ var sharedObject = [CPObject new];
|
||||
expectedValues = {a:2, b:"baz", c:"astring", d:[CPNull null]};
|
||||
|
||||
testAttributesAtIndexWithValues(e, 13, expectedValues, self);
|
||||
|
||||
[self assertTrue:CPEqualRanges(e._rangeEntries[0].range, CPMakeRange(0, 1)) message:"expected range to be {0, 1}, was "+CPStringFromRange(e._rangeEntries[0].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(e._rangeEntries[0].range, CPMakeRange(0, 1)) message:"expected range to be {0, 1}, was " + CPStringFromRange(e._rangeEntries[0].range)];
|
||||
}
|
||||
|
||||
//Changing Characters
|
||||
@@ -216,8 +216,8 @@ var sharedObject = [CPObject new];
|
||||
var string = [self stringForTesting];
|
||||
|
||||
[string replaceCharactersInRange:CPMakeRange(10, 5) withString:"firetruck red"];
|
||||
|
||||
[self assertTrue:[string string]==="The quick firetruck red fox jumped over the lazy dog." message:"replacing 'brown' with 'firetruck red' produced: "+[string string].substr(10, 5)];
|
||||
|
||||
[self assertTrue:[string string] === "The quick firetruck red fox jumped over the lazy dog." message:"replacing 'brown' with 'firetruck red' produced: " + [string string].substr(10, 5)];
|
||||
|
||||
testAttributesAtIndexWithValues(string, 21, {a:2, b:"baz", c:sharedObject}, self);
|
||||
testAttributesAtIndexWithValues(string, 40, {a:37, b:"baz", c:1, d:20, e:55, f:43}, self);
|
||||
@@ -230,8 +230,8 @@ var sharedObject = [CPObject new];
|
||||
var string = [self stringForTesting];
|
||||
|
||||
[string deleteCharactersInRange:CPMakeRange(10, 5)];
|
||||
|
||||
[self assertTrue:[string string]==="The quick fox jumped over the lazy dog." message:"replacing 'brown' with '' produced: "+[string string]];
|
||||
|
||||
[self assertTrue:[string string] === "The quick fox jumped over the lazy dog." message:"replacing 'brown' with '' produced: " + [string string]];
|
||||
|
||||
testAttributesAtIndexWithValues(string, 10, {a:2, b:"baz", c:sharedObject}, self);
|
||||
testAttributesAtIndexWithValues(string, 27, {a:37, b:"baz", c:1, d:20, e:55, f:43}, self);
|
||||
@@ -239,10 +239,10 @@ var sharedObject = [CPObject new];
|
||||
|
||||
[string deleteCharactersInRange:CPMakeRange(0, [string length])];
|
||||
|
||||
[self assertTrue:[string isEqual:[[CPAttributedString alloc] initWithString:""]] message:"emptry string was not equal: "+[string string]];
|
||||
[self assertTrue:[string isEqual:[[CPAttributedString alloc] initWithString:""]] message:"emptry string was not equal: " + [string string]];
|
||||
|
||||
var string = [self stringForTesting];
|
||||
|
||||
|
||||
//this deletes an exact rangeEntry
|
||||
[string deleteCharactersInRange:CPMakeRange(9, 11)];
|
||||
|
||||
@@ -253,60 +253,59 @@ var sharedObject = [CPObject new];
|
||||
//- (void)_indexOfRangeEntryForIndex:(unsigned)characterIndex splitOnMaxIndex:(BOOL)split
|
||||
- (void)testIndexOfRangeEntryForIndexSplitOnMaxIndex
|
||||
{
|
||||
var string = [self stringForTesting];
|
||||
|
||||
var index = [string _indexOfRangeEntryForIndex:4 splitOnMaxIndex:YES];
|
||||
var string = [self stringForTesting],
|
||||
index = [string _indexOfRangeEntryForIndex:4 splitOnMaxIndex:YES];
|
||||
|
||||
[self assertTrue:index==1 message:"index of character 4 should have been 1, was: "+index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 4)) message:"range 0 should be {0, 4}; was "+CPStringFromRange(string._rangeEntries[0].range)];
|
||||
[self assertTrue:index == 1 message:"index of character 4 should have been 1, was: " + index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 4)) message:"range 0 should be {0, 4}; was " + CPStringFromRange(string._rangeEntries[0].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(4, 5)) message:"range 1 should be {4, 5}; was " + CPStringFromRange(string._rangeEntries[1].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(4, 5)) message:"range 1 should be {4, 5}; was "+CPStringFromRange(string._rangeEntries[1].range)];
|
||||
|
||||
[self assertTrue:[string isEqual:[self stringForTesting]] message:"should be equal to template attributed string but wasn't"];
|
||||
|
||||
string = [self stringForTesting];
|
||||
|
||||
index = [string _indexOfRangeEntryForIndex:8 splitOnMaxIndex:YES];
|
||||
|
||||
[self assertTrue:index==1 message:"index of character 8 should have been 1, was: "+index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 8)) message:"range 0 should be {0, 8}; was "+CPStringFromRange(string._rangeEntries[0].range)];
|
||||
string = [self stringForTesting];
|
||||
|
||||
index = [string _indexOfRangeEntryForIndex:8 splitOnMaxIndex:YES];
|
||||
|
||||
[self assertTrue:index == 1 message:"index of character 8 should have been 1, was: " + index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 8)) message:"range 0 should be {0, 8}; was " + CPStringFromRange(string._rangeEntries[0].range)];
|
||||
|
||||
index = [string _indexOfRangeEntryForIndex:9 splitOnMaxIndex:YES];
|
||||
|
||||
[self assertTrue:index==2 message:"index of character 9 should have been 2, was: "+index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 8)) message:"range 0 should be {0, 8}; was "+CPStringFromRange(string._rangeEntries[0].range)];
|
||||
[self assertTrue:index == 2 message:"index of character 9 should have been 2, was: " + index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(8, 1)) message:"range 1 should be {8, 1}; was "+CPStringFromRange(string._rangeEntries[1].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 8)) message:"range 0 should be {0, 8}; was " + CPStringFromRange(string._rangeEntries[0].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[2].range, CPMakeRange(9, 11)) message:"range 2 should be {9, 11}; was "+CPStringFromRange(string._rangeEntries[2].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(8, 1)) message:"range 1 should be {8, 1}; was " + CPStringFromRange(string._rangeEntries[1].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[2].range, CPMakeRange(9, 11)) message:"range 2 should be {9, 11}; was " + CPStringFromRange(string._rangeEntries[2].range)];
|
||||
|
||||
string = [self stringForTesting];
|
||||
|
||||
|
||||
index = [string _indexOfRangeEntryForIndex:44 splitOnMaxIndex:YES];
|
||||
|
||||
[self assertTrue:index==4 message:"index of character 44 should have been 4, was: "+index];
|
||||
[self assertTrue:index == 4 message:"index of character 44 should have been 4, was: " + index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[index].range, CPMakeRange(44, 1)) message:"range 3 should be {44, 1}; was "+CPStringFromRange(string._rangeEntries[index].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[index].range, CPMakeRange(44, 1)) message:"range 3 should be {44, 1}; was " + CPStringFromRange(string._rangeEntries[index].range)];
|
||||
|
||||
index = [string _indexOfRangeEntryForIndex:43 splitOnMaxIndex:YES];
|
||||
|
||||
[self assertTrue:index==4 message:"index of character 43 should have been 4, was: "+index];
|
||||
[self assertTrue:index == 4 message:"index of character 43 should have been 4, was: " + index];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[index-1].range, CPMakeRange(32, 11)) message:"range 3 should be {32, 11}; was "+CPStringFromRange(string._rangeEntries[index-1].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[index - 1].range, CPMakeRange(32, 11)) message:"range 3 should be {32, 11}; was " + CPStringFromRange(string._rangeEntries[index - 1].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[index].range, CPMakeRange(43, 1)) message:"range 4 should be {43, 1}; was "+CPStringFromRange(string._rangeEntries[index].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[index].range, CPMakeRange(43, 1)) message:"range 4 should be {43, 1}; was " + CPStringFromRange(string._rangeEntries[index].range)];
|
||||
}
|
||||
|
||||
//- (void)_coalesceRangeEntriesFromIndex:(unsigned)start toIndex:(unsigned)end
|
||||
- (void)testCoalesceRangeEntriesFromIndexToIndex
|
||||
{
|
||||
var templateString = [[CPAttributedString alloc] initWithString:"The quick brown fox jumped over the lazy dog."];
|
||||
|
||||
|
||||
templateString._rangeEntries = [];
|
||||
|
||||
|
||||
templateString._rangeEntries.push({
|
||||
range:CPMakeRange(0, 4),
|
||||
attributes:[CPDictionary dictionaryWithObjects:[1, "bar", sharedObject, 20] forKeys:["a", "b", "c", "d"]]
|
||||
@@ -339,30 +338,30 @@ var sharedObject = [CPObject new];
|
||||
range:CPMakeRange(43, 2),
|
||||
attributes:[CPDictionary dictionaryWithObjects:[37, "baz", 1, 20, 55, 43] forKeys:["a", "b", "c", "d", "e", "f"]]
|
||||
});
|
||||
|
||||
var string = [[CPAttributedString alloc] initWithAttributedString:templateString];
|
||||
|
||||
[string _coalesceRangeEntriesFromIndex:0 toIndex:string._rangeEntries.length-1];
|
||||
|
||||
[self assertTrue:[string isEqual:templateString] message:"string should equal template string but does not."];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 9)) message:"range 0 should be {0, 9}; was "+CPStringFromRange(string._rangeEntries[0].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(9, 11)) message:"range 1 should be {9, 11}; was "+CPStringFromRange(string._rangeEntries[1].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[2].range, CPMakeRange(20, 12)) message:"range 2 should be {20, 12}; was "+CPStringFromRange(string._rangeEntries[2].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[3].range, CPMakeRange(32, 13)) message:"range 3 should be {32, 13}; was "+CPStringFromRange(string._rangeEntries[3].range)];
|
||||
|
||||
var string = [[CPAttributedString alloc] initWithAttributedString:templateString];
|
||||
|
||||
|
||||
[string _coalesceRangeEntriesFromIndex:0 toIndex:string._rangeEntries.length - 1];
|
||||
|
||||
[self assertTrue:[string isEqual:templateString] message:"string should equal template string but does not."];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 9)) message:"range 0 should be {0, 9}; was " + CPStringFromRange(string._rangeEntries[0].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(9, 11)) message:"range 1 should be {9, 11}; was " + CPStringFromRange(string._rangeEntries[1].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[2].range, CPMakeRange(20, 12)) message:"range 2 should be {20, 12}; was " + CPStringFromRange(string._rangeEntries[2].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[3].range, CPMakeRange(32, 13)) message:"range 3 should be {32, 13}; was " + CPStringFromRange(string._rangeEntries[3].range)];
|
||||
|
||||
var string = [[CPAttributedString alloc] initWithAttributedString:templateString];
|
||||
|
||||
[string _coalesceRangeEntriesFromIndex:4 toIndex:7];
|
||||
|
||||
[self assertTrue:[string isEqual:templateString] message:"string should equal template string but does not."];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 4)) message:"range 0 should be {0, 4}; was "+CPStringFromRange(string._rangeEntries[0].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(4, 5)) message:"range 1 should be {4, 5}; was "+CPStringFromRange(string._rangeEntries[1].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[2].range, CPMakeRange(9, 10)) message:"range 2 should be {9, 10}; was "+CPStringFromRange(string._rangeEntries[2].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[3].range, CPMakeRange(19, 1)) message:"range 3 should be {19, 1}; was "+CPStringFromRange(string._rangeEntries[3].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[4].range, CPMakeRange(20, 12)) message:"range 4 should be {20, 12}; was "+CPStringFromRange(string._rangeEntries[4].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[5].range, CPMakeRange(32, 13)) message:"range 5 should be {32, 13}; was "+CPStringFromRange(string._rangeEntries[5].range)];
|
||||
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[0].range, CPMakeRange(0, 4)) message:"range 0 should be {0, 4}; was " + CPStringFromRange(string._rangeEntries[0].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[1].range, CPMakeRange(4, 5)) message:"range 1 should be {4, 5}; was " + CPStringFromRange(string._rangeEntries[1].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[2].range, CPMakeRange(9, 10)) message:"range 2 should be {9, 10}; was " + CPStringFromRange(string._rangeEntries[2].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[3].range, CPMakeRange(19, 1)) message:"range 3 should be {19, 1}; was " + CPStringFromRange(string._rangeEntries[3].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[4].range, CPMakeRange(20, 12)) message:"range 4 should be {20, 12}; was " + CPStringFromRange(string._rangeEntries[4].range)];
|
||||
[self assertTrue:CPEqualRanges(string._rangeEntries[5].range, CPMakeRange(32, 13)) message:"range 5 should be {32, 13}; was " + CPStringFromRange(string._rangeEntries[5].range)];
|
||||
}
|
||||
|
||||
//Changing Attributes
|
||||
@@ -382,30 +381,32 @@ var sharedObject = [CPObject new];
|
||||
testAttributesAtIndexWithValues(string, 10, {a:1, b:2, c:3, d:4, e:5}, self);
|
||||
|
||||
var range = CPMakeRange(0, 0);
|
||||
|
||||
|
||||
[string setAttributes:[CPDictionary dictionaryWithObject:"FOO" forKey:"BAR"] range:CPMakeRange(15, 20)];
|
||||
|
||||
var value = [string attribute:"BAR" atIndex:16 longestEffectiveRange:range inRange:CPMakeRange(0, 45)];
|
||||
|
||||
[self assertTrue:value==="FOO" message:"expected value to be 'FOO', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(15, 20)) message:"expected key to be valid across {15, 20}, was: "+CPStringFromRange(range)];
|
||||
|
||||
|
||||
[self assertTrue:value === "FOO" message:"expected value to be 'FOO', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(15, 20)) message:"expected key to be valid across {15, 20}, was: " + CPStringFromRange(range)];
|
||||
|
||||
var index = range.location;
|
||||
while(index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil]=="FOO" message:"incorrect value for key BAR"];
|
||||
|
||||
while (index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil] == "FOO" message:"incorrect value for key BAR"];
|
||||
|
||||
string = [self stringForTesting];
|
||||
|
||||
|
||||
[string addAttributes:[CPDictionary dictionaryWithObject:"FOO" forKey:"BAR"] range:CPMakeRange(0, 45)];
|
||||
|
||||
var value = [string attribute:"BAR" atIndex:16 longestEffectiveRange:range inRange:CPMakeRange(0, 45)];
|
||||
|
||||
[self assertTrue:value==="FOO" message:"expected value to be 'FOO', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(0, 45)) message:"expected key to be valid across {0, 45}, was: "+CPStringFromRange(range)];
|
||||
|
||||
|
||||
[self assertTrue:value === "FOO" message:"expected value to be 'FOO', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(0, 45)) message:"expected key to be valid across {0, 45}, was: " + CPStringFromRange(range)];
|
||||
|
||||
var index = range.location;
|
||||
while(index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil]=="FOO" message:"incorrect value for key BAR"];
|
||||
|
||||
while (index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil] == "FOO" message:"incorrect value for key BAR"];
|
||||
}
|
||||
|
||||
//- (void)addAttributes:(CPDictionary)aDictionary range:(CPRange)aRange
|
||||
@@ -417,32 +418,34 @@ var sharedObject = [CPObject new];
|
||||
[string addAttributes:[CPDictionary dictionaryWithObject:"FOO" forKey:"BAR"] range:CPMakeRange(15, 20)];
|
||||
|
||||
var value = [string attribute:"BAR" atIndex:16 longestEffectiveRange:range inRange:CPMakeRange(0, 45)];
|
||||
|
||||
[self assertTrue:value==="FOO" message:"expected value to be 'FOO', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(15, 20)) message:"expected key to be valid across {15, 20}, was: "+CPStringFromRange(range)];
|
||||
|
||||
|
||||
[self assertTrue:value === "FOO" message:"expected value to be 'FOO', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(15, 20)) message:"expected key to be valid across {15, 20}, was: " + CPStringFromRange(range)];
|
||||
|
||||
var index = range.location;
|
||||
while(index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil]=="FOO" message:"incorrect value for key BAR"];
|
||||
|
||||
|
||||
while (index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil] == "FOO" message:"incorrect value for key BAR"];
|
||||
|
||||
string = [self stringForTesting];
|
||||
|
||||
[string addAttributes:[CPDictionary dictionaryWithObjects:[1, 2, 3, 4, 5] forKeys:["a", "b", "c", "d", "e"]] range:CPMakeRange(0, [string length])];
|
||||
|
||||
testAttributesAtIndexWithValues(string, 10, {a:1, b:2, c:3, d:4, e:5}, self);
|
||||
|
||||
|
||||
string = [self stringForTesting];
|
||||
|
||||
[string addAttributes:[CPDictionary dictionaryWithObject:"FOO" forKey:"BAR"] range:CPMakeRange(0, 45)];
|
||||
|
||||
var value = [string attribute:"BAR" atIndex:16 longestEffectiveRange:range inRange:CPMakeRange(0, 45)];
|
||||
|
||||
[self assertTrue:value==="FOO" message:"expected value to be 'FOO', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(0, 45)) message:"expected key to be valid across {0, 45}, was: "+CPStringFromRange(range)];
|
||||
|
||||
|
||||
[self assertTrue:value === "FOO" message:"expected value to be 'FOO', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(0, 45)) message:"expected key to be valid across {0, 45}, was: " + CPStringFromRange(range)];
|
||||
|
||||
var index = range.location;
|
||||
while(index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil]=="FOO" message:"incorrect value for key BAR"];
|
||||
|
||||
while (index < CPMaxRange(range))
|
||||
[self assertTrue:[string attribute:"BAR" atIndex:index++ effectiveRange:nil] == "FOO" message:"incorrect value for key BAR"];
|
||||
}
|
||||
|
||||
//- (void)addAttribute:(CPString)anAttribute value:(id)aValue range:(CPRange)aRange
|
||||
@@ -479,14 +482,14 @@ var sharedObject = [CPObject new];
|
||||
|
||||
[string appendAttributedString:addOn];
|
||||
[string appendAttributedString:addOn];
|
||||
|
||||
[self assertTrue:[string string]==="The quick brown fox jumped over the lazy dog.dogdog" message:"wrong string after appending"];
|
||||
|
||||
[self assertTrue:[string string] === "The quick brown fox jumped over the lazy dog.dogdog" message:"wrong string after appending"];
|
||||
|
||||
var range = CPMakeRange(0, 0),
|
||||
value = [string attribute:"c" atIndex:47 longestEffectiveRange:range inRange:CPMakeRange(0, [string length])];
|
||||
|
||||
[self assertTrue:value===1 message:"expected value to be '1', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(32, 13+3+3)) message:"expected key to be valid across {32, 19}, was: "+CPStringFromRange(range)];
|
||||
|
||||
[self assertTrue:value === 1 message:"expected value to be '1', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(32, 13 + 3 + 3)) message:"expected key to be valid across {32, 19}, was: " + CPStringFromRange(range)];
|
||||
}
|
||||
|
||||
//- insertAttributedString:(CPAttributedString)aString atIndex:(CPString)anIndex
|
||||
@@ -502,11 +505,11 @@ var sharedObject = [CPObject new];
|
||||
string = [self stringForTesting];
|
||||
|
||||
addOn = [[self stringForTesting] attributedSubstringFromRange:CPMakeRange(41, 3)];
|
||||
|
||||
|
||||
[string insertAttributedString:addOn atIndex:9];
|
||||
|
||||
|
||||
testAttributesAtIndexWithValues(string, 9, {a:37, b:"baz", c:1, d:20, e:55, f:43}, self);
|
||||
|
||||
|
||||
addOn = [[self stringForTesting] attributedSubstringFromRange:CPMakeRange(41, 3)];
|
||||
|
||||
[string insertAttributedString:addOn atIndex:8];
|
||||
@@ -515,14 +518,14 @@ var sharedObject = [CPObject new];
|
||||
|
||||
var range = CPMakeRange(0, 0),
|
||||
value = [string attribute:"a" atIndex:9 longestEffectiveRange:range inRange:CPMakeRange(0, 45)];
|
||||
|
||||
[self assertTrue:value===37 message:"expected value to be '37', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(8, 3)) message:"expected key to be valid across {8, 3}, was: "+CPStringFromRange(range)];
|
||||
|
||||
[self assertTrue:value === 37 message:"expected value to be '37', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(8, 3)) message:"expected key to be valid across {8, 3}, was: " + CPStringFromRange(range)];
|
||||
|
||||
value = [string attribute:"a" atIndex:11 longestEffectiveRange:range inRange:CPMakeRange(0, 45)];
|
||||
|
||||
[self assertTrue:value===1 message:"expected value to be '37', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(11, 1)) message:"expected key to be valid across {11, 1}, was: "+CPStringFromRange(range)];
|
||||
|
||||
[self assertTrue:value === 1 message:"expected value to be '37', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(11, 1)) message:"expected key to be valid across {11, 1}, was: " + CPStringFromRange(range)];
|
||||
}
|
||||
|
||||
//- (void)replaceCharactersInRange:(CPRange)aRange withAttributedString:(CPAttributedString)aString
|
||||
@@ -532,14 +535,14 @@ var sharedObject = [CPObject new];
|
||||
addOn = [string attributedSubstringFromRange:CPMakeRange(41, 3)];
|
||||
|
||||
[string replaceCharactersInRange:CPMakeRange(41, 3) withAttributedString:addOn];
|
||||
|
||||
[self assertTrue:[string string]===[[self stringForTesting] string] message:"wrong string after replacing."];
|
||||
|
||||
[self assertTrue:[string string] === [[self stringForTesting] string] message:"wrong string after replacing."];
|
||||
|
||||
var range = CPMakeRange(0, 0),
|
||||
value = [string attribute:"c" atIndex:42 longestEffectiveRange:range inRange:CPMakeRange(0, [string length])];
|
||||
|
||||
[self assertTrue:value===1 message:"expected value to be '1', was: "+value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(32, 13)) message:"expected key to be valid across {32, 13}, was: "+CPStringFromRange(range)];
|
||||
|
||||
[self assertTrue:value === 1 message:"expected value to be '1', was: " + value];
|
||||
[self assertTrue:CPEqualRanges(range, CPMakeRange(32, 13)) message:"expected key to be valid across {32, 13}, was: " + CPStringFromRange(range)];
|
||||
}
|
||||
|
||||
//- (void)setAttributedString:(CPAttributedString)aString
|
||||
@@ -547,8 +550,8 @@ var sharedObject = [CPObject new];
|
||||
{
|
||||
var string = [[CPAttributedString alloc] initWithString:"HELLO THERE"];
|
||||
[string setAttributedString:[self stringForTesting]];
|
||||
|
||||
[self assertTrue:[[self stringForTesting] isEqual:string] message:"setAttributedString should have made strings equal, but they were not"];
|
||||
|
||||
[self assertTrue:[[self stringForTesting] isEqual:string] message:"setAttributedString should have made strings equal, but they were not"];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -563,16 +566,17 @@ function testAttributesAtIndexWithValues(aString, anIndex, values, aSelf)
|
||||
var range = CPMakeRange(0, 0),
|
||||
attributes = [aString attributesAtIndex:anIndex effectiveRange:range];
|
||||
|
||||
for(key in values)
|
||||
[aSelf assertTrue:isEqualAllowingUndefinedCast([attributes objectForKey:key], values[key]) message: "expecting '"+key+"' to be '"+values[key]+"', was '"+[attributes objectForKey:key]];
|
||||
for (key in values)
|
||||
[aSelf assertTrue:isEqualAllowingUndefinedCast([attributes objectForKey:key], values[key]) message: "expecting '" + key + "' to be '" + values[key] + "', was '" + [attributes objectForKey:key]];
|
||||
|
||||
var index = range.location;
|
||||
while(index < CPMaxRange(range))
|
||||
|
||||
while (index < CPMaxRange(range))
|
||||
{
|
||||
attributes = [aString attributesAtIndex:index++ effectiveRange:nil];
|
||||
|
||||
for(key in values)
|
||||
[aSelf assertTrue:isEqualAllowingUndefinedCast([attributes objectForKey:key], values[key]) message: "expecting '"+key+"' in loop to be '"+values[key]+"', was '"+[attributes objectForKey:key]];
|
||||
|
||||
for (key in values)
|
||||
[aSelf assertTrue:isEqualAllowingUndefinedCast([attributes objectForKey:key], values[key]) message: "expecting '" + key + "' in loop to be '" + values[key] + "', was '" + [attributes objectForKey:key]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,18 +585,19 @@ function testAttributeAtIndexWithValue(aString, anIndex, aKey, aValue, aSelf)
|
||||
var range = CPMakeRange(0, 0),
|
||||
attribute = [aString attribute:aKey atIndex:anIndex effectiveRange:range];
|
||||
|
||||
[aSelf assertTrue: isEqualAllowingUndefinedCast(attribute, aValue) message: "expecting '"+aKey+"' to be '"+aValue+"', was '"+attribute];
|
||||
[aSelf assertTrue: isEqualAllowingUndefinedCast(attribute, aValue) message: "expecting '" + aKey + "' to be '" + aValue + "', was '" + attribute];
|
||||
|
||||
var index = range.location;
|
||||
while(index < CPMaxRange(range))
|
||||
|
||||
while (index < CPMaxRange(range))
|
||||
{
|
||||
attribute = [aString attribute:aKey atIndex:index++ effectiveRange:nil];
|
||||
|
||||
[aSelf assertTrue: isEqualAllowingUndefinedCast(attribute, aValue) message: "expecting '"+aKey+"' to be '"+aValue+"', was '"+attribute];
|
||||
|
||||
[aSelf assertTrue: isEqualAllowingUndefinedCast(attribute, aValue) message: "expecting '" + aKey + "' to be '" + aValue + "', was '" + attribute];
|
||||
}
|
||||
}
|
||||
|
||||
function printRangeEntry(entry)
|
||||
{
|
||||
print("range: "+CPStringFromRange(entry.range)+" "+[entry.attributes description]);
|
||||
print("range: " + CPStringFromRange(entry.range) + " " + [entry.attributes description]);
|
||||
}
|
||||
@@ -8,52 +8,52 @@
|
||||
- (void)testCountForObject
|
||||
{
|
||||
var set = [CPCountedSet setWithArray:[1, 2, 3]];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:[CPNull null]] === 0 message:"Expected count of 0, got: "+[set countForObject:[CPNull null]]];
|
||||
[self assertTrue:[set countForObject:3] === 1 message:"Expected count of 1, got: "+[set countForObject:0]];
|
||||
|
||||
|
||||
[set addObject:1];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:1] === 2 message:"Expected count of 2, got: "+[set countForObject:1]];
|
||||
|
||||
|
||||
[set addObject:2];
|
||||
[set addObject:2];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:2] === 3 message:"Expected count of 3, got: "+[set countForObject:2]];
|
||||
}
|
||||
|
||||
- (void)testAddObject
|
||||
{
|
||||
var set = [CPCountedSet new];
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 0 message:"Expected count of 0, got: "+[set countForObject:"foo"]];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 0 message:"Expected count of 0, got: "+[set countForObject:"foo"]];
|
||||
|
||||
[set addObject:"foo"];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 1 message:"Expected count of 1, got: "+[set countForObject:"foo"]];
|
||||
|
||||
[set addObject:"foo"];
|
||||
[set addObject:"foo"];
|
||||
[set addObject:"foo"];
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 4 message:"Expected count of 4, got: "+[set countForObject:"foo"]];
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 4 message:"Expected count of 4, got: "+[set countForObject:"foo"]];
|
||||
}
|
||||
|
||||
- (void)testRemoveObject
|
||||
{
|
||||
var set = [CPCountedSet new];
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 0 message:"Expected count of 0, got: "+[set countForObject:"foo"]];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 0 message:"Expected count of 0, got: "+[set countForObject:"foo"]];
|
||||
|
||||
[set addObject:"foo"];
|
||||
[set addObject:"foo"];
|
||||
[set addObject:"foo"];
|
||||
[set addObject:"foo"];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 4 message:"Expected count of 4, got: "+[set countForObject:"foo"]];
|
||||
|
||||
|
||||
[set removeObject:"foo"];
|
||||
|
||||
|
||||
[self assertTrue:[set countForObject:"foo"] === 3 message:"Expected count of 3, got: "+[set countForObject:"foo"]];
|
||||
|
||||
[set removeObject:"foo"];
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
@import <Foundation/CPFunctionOperation.j>
|
||||
|
||||
@implementation SomeObject : CPObject
|
||||
@implementation SomeObject : CPObject
|
||||
{
|
||||
CPString result @accessors;
|
||||
}
|
||||
|
||||
- (CPString)setAString:(CPString)someString
|
||||
- (CPString)setAString:(CPString)someString
|
||||
{
|
||||
result = someString;
|
||||
return @"Done";
|
||||
@@ -18,16 +18,15 @@
|
||||
- (void)testRunInvocation
|
||||
{
|
||||
so = [[SomeObject alloc] init];
|
||||
|
||||
|
||||
var someVar = nil;
|
||||
|
||||
|
||||
funcOp = [CPFunctionOperation functionOperationWithFunction:function() {[so setAString:@"Hello World"]}];
|
||||
[funcOp addExecutionFunction:function() {someVar = 'Soylent Green';}];
|
||||
[funcOp start];
|
||||
|
||||
|
||||
[self assert:@"Hello World" equals:[so result]];
|
||||
[self assert:@"Soylent Green" equals:someVar];
|
||||
[self assert:@"Soylent Green" equals:someVar];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@end
|
||||
@@ -23,7 +23,7 @@ function descriptionWithoutEntity(aString)
|
||||
|
||||
// Test no indexes
|
||||
[self assert:descriptionWithoutEntity(indexSet) equals:@"(no indexes)"];
|
||||
|
||||
|
||||
// Test adding initial range
|
||||
[indexSet addIndexesInRange:CPMakeRange(30,10)];
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
@import <Foundation/CPInvocationOperation.j>
|
||||
|
||||
@implementation SomeObject : CPObject
|
||||
@implementation SomeObject : CPObject
|
||||
{
|
||||
CPString result @accessors;
|
||||
}
|
||||
|
||||
- (CPString)setAString:(CPString)someString
|
||||
- (CPString)setAString:(CPString)someString
|
||||
{
|
||||
result = someString;
|
||||
return @"Done";
|
||||
@@ -19,12 +19,11 @@
|
||||
{
|
||||
var so = [[SomeObject alloc] init],
|
||||
io = [[CPInvocationOperation alloc] initWithTarget:so selector:@selector(setAString:) object:@"Hello World"];
|
||||
|
||||
|
||||
[io start];
|
||||
|
||||
|
||||
[self assert:@"Hello World" equals:[so result]];
|
||||
[self assert:@"Done" equals:[io result]];
|
||||
[self assert:@"Done" equals:[io result]];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@end
|
||||
@@ -7,7 +7,7 @@
|
||||
BOOL _sawPriorObservation;
|
||||
BOOL _sawObservation;
|
||||
BOOL _sawDependentObservation;
|
||||
|
||||
|
||||
id bob;
|
||||
id obj;
|
||||
id cs101;
|
||||
@@ -24,11 +24,11 @@
|
||||
- (void)testAddObserver
|
||||
{
|
||||
bob = [[PersonTester alloc] init];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"name" options:nil context:"testAddObserver"];
|
||||
|
||||
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"name"] == @"set_bob" message: "valueForKey:'name' should be 'set_bob', was: "+[bob valueForKey:@"name"]];
|
||||
[self assertTrue: bob.name == @"set_bob" message: "bob.name should be 'set_bob', was: "+bob.name];
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
@@ -37,11 +37,11 @@
|
||||
- (void)testUnobservedKey
|
||||
{
|
||||
bob = [[PersonTester alloc] init];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"name" options:nil context:"testUnobservedKey"];
|
||||
|
||||
|
||||
[bob setValue:@"555" forKey:@"phoneNumber"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"phoneNumber"] == @"555" message: "'phoneNumber' should be '555', was: "+[bob valueForKey:@"phoneNumber"]];
|
||||
[self assertFalse: _sawObservation message:"Should not have recieved an observation"];
|
||||
}
|
||||
@@ -49,12 +49,12 @@
|
||||
- (void)testAddTwoObservers
|
||||
{
|
||||
bob = [[PersonTester alloc] init];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"name" options:nil context:"testAddTwoObservers"];
|
||||
[bob addObserver:[CPObject new] forKeyPath:@"name" options:nil context:"testAddTwoObservers"];
|
||||
|
||||
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"name"] == @"set_bob" message: "valueForKey:'name' should be bob, was: "+[bob valueForKey:@"name"]];
|
||||
[self assertTrue: bob.name == @"set_bob" message: "bob.name should be 'bob', was: "+bob.name];
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
@@ -63,11 +63,11 @@
|
||||
- (void)testDirectIVarObservation
|
||||
{
|
||||
var bob = [[PersonTester alloc] init];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"phoneNumber" options:nil context:"testDirectIVarObservation"];
|
||||
|
||||
|
||||
[bob setValue:@"555" forKey:@"phoneNumber"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"phoneNumber"] == @"555" message: "valueForKey:'phoneNumber' should be '555', was: "+[bob valueForKey:@"phoneNumber"]];
|
||||
[self assertTrue: bob.phoneNumber == @"555" message: "bob.phoneNumber should be '555', was: "+bob.phoneNumber];
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
@@ -76,14 +76,14 @@
|
||||
- (void)testRemoveObserver
|
||||
{
|
||||
bob = [[PersonTester alloc] init];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"name" options:nil context:"testRemoveObserver"];
|
||||
[bob addObserver:[CPString new] forKeyPath:@"name" options:nil context:"testRemoveObserver"];
|
||||
|
||||
|
||||
[bob removeObserver:self forKeyPath:@"name"];
|
||||
|
||||
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"name"] == @"set_bob" message: "valueForKey:'name' should be bob, was: "+[bob valueForKey:@"name"]];
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@
|
||||
{
|
||||
bob = [[PersonTester alloc] init];
|
||||
obj = [CPString new];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"name" options:nil context:"testRemoveOtherObserver"];
|
||||
[bob addObserver:obj forKeyPath:@"name" options:nil context:"testRemoveOtherObserver"];
|
||||
|
||||
|
||||
[bob removeObserver:obj forKeyPath:@"name"];
|
||||
|
||||
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"name"] == @"set_bob" message: "valueForKey:'name' should be bob, was: "+[bob valueForKey:@"name"]];
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
}
|
||||
@@ -108,16 +108,16 @@
|
||||
bob = [[PersonTester alloc] init];
|
||||
obj = [CPArray new];
|
||||
obj2 = [CPString new];
|
||||
|
||||
|
||||
[bob addObserver:obj forKeyPath:@"name" options:nil context:"testRemoveAllObservers"];
|
||||
[bob addObserver:obj2 forKeyPath:@"name" options:nil context:"testRemoveAllObservers"];
|
||||
|
||||
|
||||
[bob removeObserver:obj forKeyPath:@"name"];
|
||||
[bob removeObserver:obj2 forKeyPath:@"name"];
|
||||
[bob removeObserver:nil forKeyPath:nil];
|
||||
|
||||
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
|
||||
|
||||
[self assertTrue: [bob valueForKey:@"name"] == @"set_bob" message: "valueForKey:'name' should be bob, was: "+[bob valueForKey:@"name"]];
|
||||
|
||||
}
|
||||
@@ -125,7 +125,7 @@
|
||||
- (void)testDictionary
|
||||
{
|
||||
var dict = [[CPDictionary alloc] init];
|
||||
|
||||
|
||||
[dict setObject:@"Bob Jones" forKey:@"dictionaryKey"];
|
||||
|
||||
[dict addObserver:self
|
||||
@@ -141,9 +141,9 @@
|
||||
- (void)testPriorObservationOption
|
||||
{
|
||||
_sawPriorObservation = NO;
|
||||
|
||||
|
||||
bob = [[PersonTester alloc] init];
|
||||
|
||||
|
||||
[bob addObserver:self forKeyPath:@"name" options:CPKeyValueObservingOptionPrior context:"testPriorObservationOption"];
|
||||
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
@@ -170,10 +170,10 @@
|
||||
- (void)testDependentKeyObservation
|
||||
{
|
||||
_sawDependentObservation = NO;
|
||||
|
||||
|
||||
bob = [[PersonTester alloc] init];
|
||||
|
||||
bob.name = "paul";
|
||||
|
||||
bob.name = "paul";
|
||||
|
||||
[bob addObserver:self forKeyPath:@"bobName" options:0 context:"testDependentKeyObservation"];
|
||||
[bob addObserver:self forKeyPath:@"twiceRemoved" options:0 context:"testDependentKeyObservation2"];
|
||||
@@ -181,7 +181,7 @@
|
||||
[bob setValue:@"bob" forKey:@"name"];
|
||||
|
||||
[self assertTrue:_sawDependentObservation message:"asked for bobName but did not recieve corresponding notification"];
|
||||
[self assertTrue: [bob valueForKey:@"bobName"] === @"BOB! set_bob" message: "should have been BOB! set_bob, was "+[bob valueForKey:@"bobName"]];
|
||||
[self assertTrue: [bob valueForKey:@"bobName"] === @"BOB! set_bob" message: "should have been BOB! set_bob, was "+[bob valueForKey:@"bobName"]];
|
||||
}
|
||||
|
||||
- (void)testMultipartKey
|
||||
@@ -190,11 +190,11 @@
|
||||
bob = [PersonTester new];
|
||||
|
||||
[cs101 setTeacher:bob];
|
||||
|
||||
|
||||
[cs101 addObserver:self forKeyPath:@"teacher.name" options:0 context:"testMultipartKey"];
|
||||
|
||||
|
||||
[bob setName:@"bob"];
|
||||
|
||||
|
||||
[self assertTrue:[cs101 valueForKeyPath:@"teacher.name"] == "set_bob" message:"teacher.name should be: set_bob, was: "+[cs101 valueForKeyPath:@"teacher.name"]];
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
}
|
||||
@@ -238,7 +238,7 @@
|
||||
[focus setValue:"2000" forKey:"year"];
|
||||
|
||||
[cs101 addObserver:self forKeyPath:@"teacher.car.year" options:0 context:"testThreePartKeyPart2"];
|
||||
|
||||
|
||||
[bob setValue:focus forKey:"car"];
|
||||
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
@@ -250,13 +250,13 @@
|
||||
bob = [PersonTester new];
|
||||
|
||||
[cs101 setTeacher:bob];
|
||||
|
||||
|
||||
[cs101 addObserver:self forKeyPath:@"teacher.name" options:0 context:"testRemoveMultipartKey"];
|
||||
|
||||
|
||||
[cs101 removeObserver:self forKeyPath:@"teacher.name"];
|
||||
|
||||
|
||||
[bob setName:@"bob"];
|
||||
|
||||
|
||||
[self assertFalse: _sawObservation message:"Should not have recieved an observation"];
|
||||
}
|
||||
|
||||
@@ -281,51 +281,51 @@
|
||||
- (void)testCrazyKeyPathChanges
|
||||
{
|
||||
var a = [A new];
|
||||
|
||||
|
||||
[a setValue:[B new] forKeyPath:"b"];
|
||||
[a setValue:[C new] forKeyPath:"b.c"];
|
||||
[a setValue:[D new] forKeyPath:"b.c.d"];
|
||||
[a setValue:[E new] forKeyPath:"b.c.d.e"];
|
||||
[a setValue:[F new] forKeyPath:"b.c.d.e.f"];
|
||||
|
||||
|
||||
[a addObserver:self forKeyPath:"b.c.d.e.f" options:0 context:"testCrazyKeyPathChanges"];
|
||||
|
||||
|
||||
[a setValue:[D new] forKeyPath:"b.c.d"];
|
||||
|
||||
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
}
|
||||
|
||||
- (void)testCrazyKeyPathChanges2
|
||||
{
|
||||
var a = [A new];
|
||||
|
||||
|
||||
[a setValue:[B new] forKeyPath:"b"];
|
||||
[a setValue:[C new] forKeyPath:"b.c"];
|
||||
[a setValue:[D new] forKeyPath:"b.c.d"];
|
||||
[a setValue:[E new] forKeyPath:"b.c.d.e"];
|
||||
[a setValue:[F new] forKeyPath:"b.c.d.e.f"];
|
||||
|
||||
|
||||
[a addObserver:self forKeyPath:"b.c.d.e.f" options:0 context:"testCrazyKeyPathChanges2"];
|
||||
|
||||
|
||||
[a setValue:nil forKeyPath:"b.c"];
|
||||
|
||||
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
}
|
||||
|
||||
- (void)testCrazyKeyPathChanges3
|
||||
{
|
||||
var a = [A new];
|
||||
|
||||
|
||||
[a setValue:[B new] forKeyPath:"b"];
|
||||
[a setValue:[C new] forKeyPath:"b.c"];
|
||||
[a setValue:[D new] forKeyPath:"b.c.d"];
|
||||
[a setValue:[E new] forKeyPath:"b.c.d.e"];
|
||||
[a setValue:[F new] forKeyPath:"b.c.d.e.f"];
|
||||
|
||||
|
||||
[a addObserver:self forKeyPath:"b.c.d.e.f" options:0 context:"testCrazyKeyPathChanges3"];
|
||||
|
||||
|
||||
[a setValue:7 forKeyPath:"b.c.d.e.f"];
|
||||
|
||||
|
||||
[self assertTrue: _sawObservation message:"Never recieved an observation"];
|
||||
}
|
||||
|
||||
@@ -386,9 +386,9 @@
|
||||
{
|
||||
var one = [1, 1, 1, 1, 1, 1, 1, 1],
|
||||
two = [1, 2, 3, 4, 8, 0];
|
||||
|
||||
|
||||
[self assert:[one valueForKey:"@count"] equals:8];
|
||||
[self assert:[one valueForKeyPath:"@sum.intValue"] equals:8];
|
||||
[self assert:[one valueForKeyPath:"@sum.intValue"] equals:8];
|
||||
[self assert:[two valueForKeyPath:"@avg.intValue"] equals:3];
|
||||
[self assert:[two valueForKeyPath:"@max.intValue"] equals:8];
|
||||
[self assert:[two valueForKeyPath:"@min.intValue"] equals:0];
|
||||
@@ -407,8 +407,8 @@
|
||||
|
||||
var startTime = new Date();
|
||||
|
||||
for(var i=0; i<1000; i++)
|
||||
[bob setValue:i+"bob" forKey:"name"];
|
||||
for (var i = 0; i < 1000; i++)
|
||||
[bob setValue:i + "bob" forKey:"name"];
|
||||
|
||||
var total = new Date() - startTime;
|
||||
|
||||
@@ -416,8 +416,8 @@
|
||||
|
||||
startTime = new Date();
|
||||
|
||||
for(var i=0; i<1000; i++)
|
||||
[bob setValue: i+"bob" forKey:"name"];
|
||||
for (var i = 0; i < 1000; i++)
|
||||
[bob setValue: i + "bob" forKey:"name"];
|
||||
|
||||
var secondTotal = new Date() - startTime;
|
||||
|
||||
@@ -449,19 +449,19 @@
|
||||
{
|
||||
case "testDependentKeysPaths": ++observationCount;
|
||||
break;
|
||||
case "testAddObserver":
|
||||
case "testAddObserver":
|
||||
[self assertTrue: newValue == "set_bob" message: "newValue should be: set_bob was: "+newValue];
|
||||
[self assertTrue: oldValue == [CPNull null] message: "oldValue should be CPNull was: "+oldValue];
|
||||
[self assertTrue: anObject == bob message: "anObject should be: "+[bob description]+", was: "+[anObject description]];
|
||||
break;
|
||||
case "testUnobservedKey":
|
||||
case "testUnobservedKey":
|
||||
[self assertFalse: YES message: "not observing this key, should never get here"];
|
||||
break;
|
||||
case "testAddTwoObservers":
|
||||
case "testAddTwoObservers":
|
||||
[self assertTrue: newValue == "set_bob" message: "newValue should be: set_bob was: "+newValue];
|
||||
[self assertTrue: oldValue == [CPNull null] message: "oldValue should be CPNull was: "+oldValue];
|
||||
break;
|
||||
|
||||
|
||||
case "testDirectIVarObservation":
|
||||
[self assertTrue: newValue == "555" message: "newValue should be: 555 was: "+newValue];
|
||||
[self assertTrue: oldValue == [CPNull null] message: "oldValue should be CPNull was: "+oldValue];
|
||||
@@ -479,10 +479,10 @@
|
||||
case "testRemoveAllObservers":
|
||||
[self assertTrue: NO message: "all observers were removed, but notification was still received"];
|
||||
break;
|
||||
|
||||
|
||||
case "testPriorObservationOption":
|
||||
var prior = [changes objectForKey:CPKeyValueChangeNotificationIsPriorKey];
|
||||
|
||||
|
||||
if (!_sawPriorObservation)
|
||||
{
|
||||
[self assertTrue:prior message:"Have not been sent the prior notification, but it should have been sent"];
|
||||
@@ -496,7 +496,7 @@
|
||||
[self assertTrue: newValue == "set_bob" message: "newValue should be: set_bob was: "+newValue];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "testInitialObservationOption":
|
||||
if (!_sawInitialObservation)
|
||||
{
|
||||
@@ -508,13 +508,13 @@
|
||||
[self assertFalse:YES message:"Should never have received this notification"];
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "testMultipartKey":
|
||||
[self assertTrue: aKeyPath == "teacher.name" message:"Keypath should be: teacher.name, was: "+aKeyPath];
|
||||
[self assertTrue: newValue == "set_bob" message:"New value should be: set_bob, was: "+newValue];
|
||||
[self assertTrue: anObject == cs101 message: "anObject should be: "+[cs101 description]+", was: "+[anObject description]];
|
||||
break;
|
||||
|
||||
|
||||
case "testRemoveMultipartKey":
|
||||
[self assertFalse:YES message:"Should never have received this notification"];
|
||||
break;
|
||||
@@ -534,7 +534,7 @@
|
||||
[self assertTrue: newValue.year == "2000" message:"New value should be a car with year: 2000, was: "+[newValue description]];
|
||||
[self assertTrue: anObject == cs101 message: "anObject should be: "+[cs101 description]+", was: "+[anObject description]];
|
||||
break;
|
||||
|
||||
|
||||
case "testCrazyKeyPathChanges":
|
||||
[self assertTrue: [anObject class] == A message:"Should be observing an A class, was: "+[anObject class]];
|
||||
[self assertTrue: [newValue class] == D message:"Changed class was a D class, got: "+[newValue class]];
|
||||
@@ -552,7 +552,7 @@
|
||||
[self assertTrue: newValue == 7 message:"Expected 7, got: "+newValue];
|
||||
[self assertTrue: aKeyPath == "b.c.d.e.f" message:"Expected keyPath b.c.d.e.f, got: "+aKeyPath];
|
||||
break;
|
||||
|
||||
|
||||
case "testDependentKeyObservation":
|
||||
|
||||
[self assertTrue:aKeyPath === "bobName"
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
globalResults = [];
|
||||
|
||||
@implementation TestOperation : CPOperation
|
||||
@implementation TestOperation : CPOperation
|
||||
{
|
||||
CPString name @accessors;
|
||||
CPString value @accessors;
|
||||
}
|
||||
|
||||
- (void)main
|
||||
- (void)main
|
||||
{
|
||||
[self setName:@"test"];
|
||||
globalResults.push([self value]);
|
||||
@@ -16,17 +16,16 @@ globalResults = [];
|
||||
|
||||
@end
|
||||
|
||||
@implementation TestObserver : CPObject
|
||||
@implementation TestObserver : CPObject
|
||||
{
|
||||
CPArray changedKeyPaths @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
if (self = [super init])
|
||||
changedKeyPaths = [[CPArray alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -43,30 +42,30 @@ globalResults = [];
|
||||
|
||||
@implementation CPOperationQueueTest : OJTestCase
|
||||
|
||||
- (void)testAddOperation
|
||||
- (void)testAddOperation
|
||||
{
|
||||
var oq = [[CPOperationQueue alloc] init],
|
||||
to = [[TestOperation alloc] init];
|
||||
|
||||
|
||||
[self assert:0 equals:[oq operationCount]];
|
||||
[oq addOperation:to];
|
||||
|
||||
|
||||
[self assert:1 equals:[oq operationCount]];
|
||||
}
|
||||
|
||||
- (void)testAddOperationsWithWaitUntilFinished
|
||||
- (void)testAddOperationsWithWaitUntilFinished
|
||||
{
|
||||
var oq = [[CPOperationQueue alloc] init],
|
||||
to1 = [[TestOperation alloc] init],
|
||||
to2 = [[TestOperation alloc] init],
|
||||
to3 = [[TestOperation alloc] init];
|
||||
|
||||
|
||||
[to3 addDependency:to1];
|
||||
[to3 addDependency:to2];
|
||||
|
||||
|
||||
[self assert:0 equals:[oq operationCount]];
|
||||
[oq addOperations:[to1, to2, to3] waitUntilFinished:YES];
|
||||
|
||||
|
||||
//make sure they all ran and are finished...
|
||||
[self assertTrue:[to1 isFinished]];
|
||||
[self assertTrue:[to2 isFinished]];
|
||||
@@ -74,11 +73,11 @@ globalResults = [];
|
||||
[self assert:@"test" equals:[to1 name]];
|
||||
[self assert:@"test" equals:[to2 name]];
|
||||
[self assert:@"test" equals:[to3 name]];
|
||||
|
||||
|
||||
[self assert:3 equals:[oq operationCount]];
|
||||
}
|
||||
|
||||
- (void)testRunOperationsInCorrectOrder
|
||||
- (void)testRunOperationsInCorrectOrder
|
||||
{
|
||||
var oq = [[CPOperationQueue alloc] init],
|
||||
to1 = [[TestOperation alloc] init];
|
||||
@@ -97,12 +96,12 @@ globalResults = [];
|
||||
[to5 setValue:@"high"];
|
||||
var to6 = [[TestOperation alloc] init];
|
||||
[to6 setValue:@"also normal"];
|
||||
|
||||
|
||||
globalResults = [];
|
||||
[oq addOperations:[to3, to4, to5, to6] waitUntilFinished:NO];
|
||||
|
||||
|
||||
[oq waitUntilAllOperationsAreFinished];
|
||||
|
||||
|
||||
[self assertTrue:[to3 isFinished]];
|
||||
[self assertTrue:[to4 isFinished]];
|
||||
[self assertTrue:[to5 isFinished]];
|
||||
@@ -111,7 +110,7 @@ globalResults = [];
|
||||
[self assert:@"normal" equals:globalResults[1]];
|
||||
[self assert:@"also normal" equals:globalResults[2]];
|
||||
[self assert:@"low" equals:globalResults[3]];
|
||||
|
||||
|
||||
globalResults = [];
|
||||
[oq addOperation:to1];
|
||||
[oq addOperation:to2];
|
||||
@@ -120,31 +119,31 @@ globalResults = [];
|
||||
[self assert:@"very low" equals:globalResults[1]];
|
||||
}
|
||||
|
||||
- (void)testAddOperationWithFunction
|
||||
- (void)testAddOperationWithFunction
|
||||
{
|
||||
var oq = [[CPOperationQueue alloc] init];
|
||||
globalResults = [];
|
||||
|
||||
|
||||
[oq addOperationWithFunction:function() {globalResults.push("Soylent");}];
|
||||
[oq waitUntilAllOperationsAreFinished];
|
||||
[self assert:@"Soylent" equals:globalResults[0]];
|
||||
}
|
||||
|
||||
- (void)testKVO
|
||||
{
|
||||
- (void)testKVO
|
||||
{
|
||||
var oq = [[CPOperationQueue alloc] init],
|
||||
obs = [[TestObserver alloc] init];
|
||||
|
||||
|
||||
[oq addObserver:obs
|
||||
forKeyPath:@"operations"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
|
||||
[oq addObserver:obs
|
||||
forKeyPath:@"operationCount"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
context:NULL];
|
||||
|
||||
[oq addObserver:obs
|
||||
forKeyPath:@"suspended"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
@@ -153,18 +152,17 @@ globalResults = [];
|
||||
[oq addObserver:obs
|
||||
forKeyPath:@"name"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
|
||||
context:NULL];
|
||||
|
||||
[oq addOperationWithFunction:function() {globalResults.push("Soylent");}];
|
||||
[self assert:@"operations" equals:[[obs changedKeyPaths] objectAtIndex:0]];
|
||||
[self assert:@"operationCount" equals:[[obs changedKeyPaths] objectAtIndex:1]];
|
||||
|
||||
|
||||
[oq setSuspended:YES];
|
||||
[self assert:@"suspended" equals:[[obs changedKeyPaths] objectAtIndex:2]];
|
||||
[oq setSuspended:NO];
|
||||
[self assert:@"suspended" equals:[[obs changedKeyPaths] objectAtIndex:3]];
|
||||
|
||||
|
||||
[oq setName:@"Soylent"];
|
||||
[self assert:@"name" equals:[[obs changedKeyPaths] objectAtIndex:4]];
|
||||
}
|
||||
|
||||
@@ -6,21 +6,21 @@
|
||||
CPString value @accessors;
|
||||
}
|
||||
|
||||
- (void)main
|
||||
- (void)main
|
||||
{
|
||||
[self setName:@"test"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TestObserver : CPObject
|
||||
@implementation TestObserver : CPObject
|
||||
{
|
||||
CPArray changedKeyPaths @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init])
|
||||
if (self = [super init])
|
||||
{
|
||||
changedKeyPaths = [[CPArray alloc] init];
|
||||
}
|
||||
@@ -44,7 +44,7 @@
|
||||
{
|
||||
var co = [[CPOperation alloc] init],
|
||||
co_dep = [[CPOperation alloc] init];
|
||||
|
||||
|
||||
[co addDependency:co_dep];
|
||||
[self assert:1 equals:[[co dependencies] count]];
|
||||
}
|
||||
@@ -54,26 +54,26 @@
|
||||
var co = [[CPOperation alloc] init],
|
||||
co_dep1 = [[CPOperation alloc] init],
|
||||
co_dep2 = [[CPOperation alloc] init];
|
||||
|
||||
|
||||
[co addDependency:co_dep1];
|
||||
[co addDependency:co_dep2];
|
||||
|
||||
|
||||
[self assert:2 equals:[[co dependencies] count]];
|
||||
|
||||
|
||||
[co removeDependency:co_dep2];
|
||||
[self assert:1 equals:[[co dependencies] count]];
|
||||
|
||||
|
||||
[co removeDependency:co_dep2];
|
||||
[self assert:1 equals:[[co dependencies] count]];
|
||||
|
||||
|
||||
[co removeDependency:co_dep1];
|
||||
[self assert:0 equals:[[co dependencies] count]];
|
||||
}
|
||||
|
||||
- (void)testCorrectValuesOnInit
|
||||
- (void)testCorrectValuesOnInit
|
||||
{
|
||||
var co = [[CPOperation alloc] init];
|
||||
|
||||
|
||||
[self assertTrue:[co isReady]];
|
||||
[self assertFalse:[co isCancelled]];
|
||||
[self assertFalse:[co isConcurrent]];
|
||||
@@ -82,57 +82,56 @@
|
||||
[self assert:CPOperationQueuePriorityNormal equals:[co queuePriority]];
|
||||
}
|
||||
|
||||
- (void)testIsReadyWithDependencies
|
||||
- (void)testIsReadyWithDependencies
|
||||
{
|
||||
var co = [[CPOperation alloc] init],
|
||||
co_dep1 = [[CPOperation alloc] init],
|
||||
co_dep2 = [[CPOperation alloc] init];
|
||||
|
||||
|
||||
[self assertTrue:[co isReady]];
|
||||
|
||||
|
||||
[co addDependency:co_dep1];
|
||||
[co addDependency:co_dep2];
|
||||
|
||||
|
||||
[self assertFalse:[co isReady]];
|
||||
|
||||
|
||||
[co_dep1 start];
|
||||
|
||||
|
||||
[self assertFalse:[co isReady]];
|
||||
|
||||
|
||||
[co_dep2 start];
|
||||
|
||||
|
||||
[self assertTrue:[co isReady]];
|
||||
}
|
||||
|
||||
- (void)testCompletionFunction
|
||||
- (void)testCompletionFunction
|
||||
{
|
||||
var to = [[TestOperation alloc] init];
|
||||
|
||||
|
||||
[to setCompletionFunction:function() {[to setValue:@"something"];}];
|
||||
[to start];
|
||||
|
||||
|
||||
[self assert:@"something" equals:[to value]];
|
||||
}
|
||||
|
||||
// KVO Tests
|
||||
|
||||
- (void)testKVO
|
||||
- (void)testKVO
|
||||
{
|
||||
var to = [[TestOperation alloc] init],
|
||||
to2 = [[TestOperation alloc] init],
|
||||
obs = [[TestObserver alloc] init];
|
||||
|
||||
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"isCancelled"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"isExecuting"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
context:NULL];
|
||||
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"isFinished"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
@@ -141,12 +140,12 @@
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"isReady"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
context:NULL];
|
||||
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"dependencies"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
context:NULL];
|
||||
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"queuePriority"
|
||||
@@ -156,9 +155,8 @@
|
||||
[to addObserver:obs
|
||||
forKeyPath:@"completionFunction"
|
||||
options:(CPKeyValueObservingOptionNew)
|
||||
context:NULL];
|
||||
|
||||
|
||||
context:NULL];
|
||||
|
||||
[to addDependency:to2];
|
||||
[self assert:@"dependencies" equals:[[obs changedKeyPaths] objectAtIndex:0]];
|
||||
[self assert:@"isReady" equals:[[obs changedKeyPaths] objectAtIndex:1]];
|
||||
@@ -166,20 +164,20 @@
|
||||
[self assert:@"isReady" equals:[[obs changedKeyPaths] objectAtIndex:2]];
|
||||
[to removeDependency:to2];
|
||||
[self assert:@"dependencies" equals:[[obs changedKeyPaths] objectAtIndex:3]];
|
||||
[to setQueuePriority:CPOperationQueuePriorityHigh];
|
||||
[to setQueuePriority:CPOperationQueuePriorityHigh];
|
||||
[self assert:@"queuePriority" equals:[[obs changedKeyPaths] objectAtIndex:4]];
|
||||
[to setCompletionFunction:function() {}];
|
||||
[self assert:@"completionFunction" equals:[[obs changedKeyPaths] objectAtIndex:5]];
|
||||
|
||||
[to setCompletionFunction:function() {}];
|
||||
[self assert:@"completionFunction" equals:[[obs changedKeyPaths] objectAtIndex:5]];
|
||||
|
||||
// this should set executing = yes, executing = no, finished = yes.
|
||||
[to start];
|
||||
[self assert:@"isExecuting" equals:[[obs changedKeyPaths] objectAtIndex:6]];
|
||||
[self assert:@"isExecuting" equals:[[obs changedKeyPaths] objectAtIndex:7]];
|
||||
[self assert:@"isExecuting" equals:[[obs changedKeyPaths] objectAtIndex:7]];
|
||||
[self assert:@"isFinished" equals:[[obs changedKeyPaths] objectAtIndex:8]];
|
||||
|
||||
|
||||
[to cancel];
|
||||
|
||||
|
||||
[self assert:@"isCancelled" equals:[[obs changedKeyPaths] objectAtIndex:9]];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
@@ -239,7 +239,7 @@
|
||||
var testStrings = [
|
||||
["tmp/scratch", ["tmp", "scratch"]],
|
||||
["/tmp/scratch", ["/", "tmp", "scratch"]]
|
||||
]
|
||||
];
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if(self)
|
||||
if (self)
|
||||
_a = "Bob";
|
||||
|
||||
return self;
|
||||
|
||||
@@ -98,48 +98,48 @@ CPLogRegister(CPLogConsole);
|
||||
|
||||
- (void)createBindings
|
||||
{
|
||||
// bind array controller to self's itemsArray
|
||||
// bind array controller to self's itemsArray
|
||||
[arrayController bind:@"contentArray" toObject:self
|
||||
withKeyPath:@"itemsArray" options:nil];
|
||||
withKeyPath:@"itemsArray" options:nil];
|
||||
|
||||
// bind the total field -- no options on this one
|
||||
// Currently broken, crashes the app as it tries to pull valueForKey @sum at some point.
|
||||
//[totalCountField bind:CPValueBinding toObject:arrayController
|
||||
// withKeyPath:@"arrangedObjects.@sum.price" options:nil];
|
||||
//[totalCountField bind:CPValueBinding toObject:arrayController
|
||||
// withKeyPath:@"arrangedObjects.@sum.price" options:nil];
|
||||
|
||||
var bindingOptions = [CPDictionary dictionary];
|
||||
var bindingOptions = [CPDictionary dictionary];
|
||||
|
||||
// binding options for "name"
|
||||
//[bindingOptions setObject:@"No Name" forKey:@"NSNullPlaceholder"];
|
||||
// binding options for "name"
|
||||
//[bindingOptions setObject:@"No Name" forKey:@"NSNullPlaceholder"];
|
||||
|
||||
// binding for selected "name" field
|
||||
// binding for selected "name" field
|
||||
//[selectedNameField bind: @"value" toObject: arrayController
|
||||
// withKeyPath:@"selection.name" options:bindingOptions];
|
||||
// withKeyPath:@"selection.name" options:bindingOptions];
|
||||
|
||||
// binding for "name" column
|
||||
// binding for "name" column
|
||||
var tableColumn = [tableView tableColumnWithIdentifier:@"name"];
|
||||
|
||||
[tableColumn bind:@"value" toObject: arrayController
|
||||
withKeyPath:@"arrangedObjects.name" options:bindingOptions];
|
||||
[tableColumn bind:@"value" toObject: arrayController
|
||||
withKeyPath:@"arrangedObjects.name" options:bindingOptions];
|
||||
|
||||
|
||||
// binding options for "price"
|
||||
// no need for placeholder as overridden by formatters
|
||||
//[bindingOptions removeObjectForKey:@"NSNullPlaceholder"];
|
||||
// no need for placeholder as overridden by formatters
|
||||
//[bindingOptions removeObjectForKey:@"NSNullPlaceholder"];
|
||||
|
||||
//[bindingOptions setObject:YES
|
||||
// forKey:CPValidatesImmediatelyBindingOption];
|
||||
//[bindingOptions setObject:YES
|
||||
// forKey:CPValidatesImmediatelyBindingOption];
|
||||
|
||||
// binding for selected "price" field
|
||||
//[selectedPriceField bind: @"value" toObject: arrayController
|
||||
// withKeyPath:@"selection.price" options:bindingOptions];
|
||||
// binding for selected "price" field
|
||||
//[selectedPriceField bind: @"value" toObject: arrayController
|
||||
// withKeyPath:@"selection.price" options:bindingOptions];
|
||||
|
||||
|
||||
// binding for "price" column
|
||||
// binding for "price" column
|
||||
tableColumn = [tableView tableColumnWithIdentifier:@"price"];
|
||||
|
||||
[tableColumn bind:@"value" toObject: arrayController
|
||||
withKeyPath:@"arrangedObjects.price" options:bindingOptions];
|
||||
withKeyPath:@"arrangedObjects.price" options:bindingOptions];
|
||||
|
||||
tableColumn = [tableView tableColumnWithIdentifier:@"all right"];
|
||||
|
||||
|
||||
@@ -20,45 +20,44 @@
|
||||
{
|
||||
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
|
||||
[theWindow orderFront:self];
|
||||
|
||||
|
||||
scrollViewXCount = 0;
|
||||
scrollViewYCount = 0;
|
||||
|
||||
|
||||
// Vanilla scrollview
|
||||
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,900,675)];
|
||||
[imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"photo.jpg"]]];
|
||||
|
||||
|
||||
var scrollView = [self makeScrollview];
|
||||
[scrollView setDocumentView:imageView];
|
||||
[[theWindow contentView] addSubview:scrollView];
|
||||
|
||||
|
||||
|
||||
// Scrollview with a CPTextField in it
|
||||
var textField = [CPTextField textFieldWithStringValue:@"Try to select this" placeholder:@"" width:120];
|
||||
|
||||
[textField setFrameOrigin:CGPointMake(20,20)];
|
||||
[textField setSelectable:YES];
|
||||
|
||||
|
||||
var scrollView = [self makeScrollview];
|
||||
|
||||
|
||||
[[scrollView documentView] addSubview:textField];
|
||||
[[theWindow contentView] addSubview:scrollView];
|
||||
|
||||
|
||||
|
||||
// In another window
|
||||
var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(120,400,400,300) styleMask:CPTitledWindowMask];
|
||||
[aWindow setTitle:@"Scrollview in a ScrollView in a Window."]
|
||||
[aWindow orderFront:nil];
|
||||
|
||||
|
||||
// Scrollview with another scrollview in it
|
||||
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,900,675)];
|
||||
[imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"photo.jpg"]]];
|
||||
|
||||
|
||||
var innerScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 20, 150, 150)];
|
||||
[innerScrollView setDocumentView:imageView];
|
||||
|
||||
var scrollView = [self makeScrollview];
|
||||
[scrollView setFrameOrigin:CGPointMake(20,20)]
|
||||
|
||||
|
||||
[[scrollView documentView] addSubview:innerScrollView];
|
||||
[[aWindow contentView] addSubview:scrollView];
|
||||
}
|
||||
@@ -67,15 +66,15 @@
|
||||
{
|
||||
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake((scrollViewXCount * 320) + 120, (scrollViewYCount * 220) + 100, 300, 200)];
|
||||
[scrollView setDocumentView:[[CPView alloc] initWithFrame:CGRectMake(0,0,1000,1000)]];
|
||||
|
||||
|
||||
scrollViewXCount += 1;
|
||||
|
||||
|
||||
if (scrollViewXCount === 3)
|
||||
{
|
||||
scrollViewXCount = 0;
|
||||
scrollViewYCount += 1;
|
||||
}
|
||||
|
||||
|
||||
return scrollView;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Created by __Me__ on __Date__.
|
||||
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
CPLogRegister(CPLogConsole);
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
@@ -14,8 +14,8 @@ CPLogRegister(CPLogConsole);
|
||||
{
|
||||
CPSlider slider;
|
||||
CPTextField textField;
|
||||
|
||||
Track track @accessors;
|
||||
|
||||
Track track @accessors;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
@@ -37,17 +37,17 @@ CPLogRegister(CPLogConsole);
|
||||
[contentView addSubview:textField];
|
||||
|
||||
var textFrame = [textField frame];
|
||||
|
||||
|
||||
slider = [[CPSlider alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFrame), CGRectGetMaxY(textFrame)+10, CGRectGetWidth(textFrame), 12)];
|
||||
|
||||
[slider setContinuous:YES];
|
||||
|
||||
|
||||
[contentView addSubview:slider];
|
||||
|
||||
|
||||
var button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFrame)+25, CGRectGetMaxY(textFrame)+40, 100, 18)];
|
||||
|
||||
|
||||
[button setTitle:@"mute"];
|
||||
|
||||
|
||||
[button setTarget:self];
|
||||
[button setAction:@selector(muteTrack:)];
|
||||
|
||||
@@ -59,19 +59,19 @@ CPLogRegister(CPLogConsole);
|
||||
|
||||
|
||||
//SET UP AN OBJECT CONTROLLER
|
||||
|
||||
var controller = [[CPObjectController alloc] init];
|
||||
|
||||
var controller = [[CPObjectController alloc] init];
|
||||
[controller bind:@"contentObject" toObject:self withKeyPath:@"track" options:nil];
|
||||
|
||||
[textField bind:CPValueBinding toObject:controller withKeyPath:@"selection.volume" options:nil];
|
||||
[slider bind:CPValueBinding toObject:controller withKeyPath:@"selection.volume" options:nil];
|
||||
|
||||
[textField bind:CPValueBinding toObject:controller withKeyPath:@"selection.volume" options:nil];
|
||||
[slider bind:CPValueBinding toObject:controller withKeyPath:@"selection.volume" options:nil];
|
||||
|
||||
[theWindow orderFront:self];
|
||||
}
|
||||
|
||||
- (IBAction)muteTrack:(id)sender
|
||||
{
|
||||
[track setVolume:0.0];
|
||||
[track setVolume:0.0];
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ CPLogRegister(CPLogConsole);
|
||||
|
||||
@implementation Track : CPObject
|
||||
{
|
||||
float volume @accessors;
|
||||
CPString title @accessors;
|
||||
float volume @accessors;
|
||||
CPString title @accessors;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -27,13 +27,13 @@ CPLogRegister(CPLogConsole);
|
||||
{
|
||||
// This is called when the cib is done loading.
|
||||
// You can implement this method on any object instantiated from a Cib.
|
||||
// It's a useful hook for setting up current UI values, and other things.
|
||||
|
||||
// It's a useful hook for setting up current UI values, and other things.
|
||||
|
||||
// In this case, we want the window from Cib to become our full browser window
|
||||
[theWindow setFullPlatformWindow:YES];
|
||||
|
||||
|
||||
[theWindow setBackgroundColor:[CPColor colorWithHexString:@"f3f4f5"]];
|
||||
|
||||
|
||||
[theBorderTypePopup selectItemWithTag:[theScrollView borderType]];
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ CPLogRegister(CPLogConsole);
|
||||
{
|
||||
var type = [[sender selectedItem] tag];
|
||||
console.log('type=%d', type);
|
||||
|
||||
|
||||
[theScrollView setBorderType:type];
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
CPTableView table;
|
||||
CPTableColumn columnA;
|
||||
CPTableColumn columnB;
|
||||
CPTableColumn columnC;
|
||||
CPTableColumn columnD;
|
||||
|
||||
CPTableView table;
|
||||
CPTableColumn columnA;
|
||||
CPTableColumn columnB;
|
||||
CPTableColumn columnC;
|
||||
CPTableColumn columnD;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
@@ -92,16 +91,16 @@ var randomColors = {};
|
||||
- (void)drawRow:(CPInteger)aRow clipRect:(CGRect)clipRect
|
||||
{
|
||||
var viewRect = [self frameOfDataViewAtColumn:[self columnWithIdentifier:@"A"] row:aRow],
|
||||
badgeWidth = CGRectGetWidth(viewRect)/5,
|
||||
badgeWidth = CGRectGetWidth(viewRect) / 5,
|
||||
badgePath = [CPBezierPath bezierPath];
|
||||
|
||||
var badgeFrame = CGRectMake(CGRectGetMaxX(viewRect) - badgeWidth - ROW_RIGHT_MARGIN,
|
||||
CGRectGetMidY(viewRect) - BADGE_HEIGHT / 2.0,
|
||||
badgeWidth,
|
||||
BADGE_HEIGHT);
|
||||
|
||||
[badgePath appendBezierPathWithRoundedRect:badgeFrame xRadius:(BADGE_HEIGHT/2.0) yRadius:(BADGE_HEIGHT/2.0)];
|
||||
[[TableViewDrawRow colorForRow:aRow] setFill];
|
||||
|
||||
var badgeFrame = CGRectMake(CGRectGetMaxX(viewRect) - badgeWidth - ROW_RIGHT_MARGIN,
|
||||
CGRectGetMidY(viewRect) - BADGE_HEIGHT / 2.0,
|
||||
badgeWidth,
|
||||
BADGE_HEIGHT);
|
||||
|
||||
[badgePath appendBezierPathWithRoundedRect:badgeFrame xRadius:(BADGE_HEIGHT / 2.0) yRadius:(BADGE_HEIGHT / 2.0)];
|
||||
[[TableViewDrawRow colorForRow:aRow] setFill];
|
||||
[badgePath fill];
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
{
|
||||
var groups = [];
|
||||
|
||||
for(var i = 0; i < 100; i += 5)
|
||||
for (var i = 0; i < 100; i += 5)
|
||||
groups.push(i);
|
||||
|
||||
return [groups containsObject:aRow];
|
||||
|
||||
@@ -45,7 +45,7 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
[tableView setSelectionHighlightColor:[CPColor redColor]];
|
||||
[tableView setDataSource:self];
|
||||
|
||||
var iconView = [[CPImageView alloc] initWithFrame:CGRectMake(16,16,0,0)];
|
||||
var iconView = [[CPImageView alloc] initWithFrame:CGRectMake(16, 16, 0, 0)];
|
||||
[iconView setImageScaling:CPScaleNone];
|
||||
var iconColumn = [[CPTableColumn alloc] initWithIdentifier:"icons"];
|
||||
[iconColumn setWidth:32.0];
|
||||
@@ -122,9 +122,9 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
[button setAction:@selector(addColumn:)];
|
||||
[contentView addSubview:button];
|
||||
|
||||
var sourceListActiveGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [255.0/255.0, 153.0/255.0, 209.0/255.0,1.0, 33.0/255.0, 94.0/255.0, 208.0/255.0,1.0], [0,1], 2),
|
||||
sourceListActiveTopLineColor = [CPColor colorWithCalibratedRed:(255.0/255.0) green:(123.0/255.0) blue:(218.0/255.0) alpha:1.0],
|
||||
sourceListActiveBottomLineColor = [CPColor colorWithCalibratedRed:(255.0/255.0) green:(92.0/255.0) blue:(207.0/255.0) alpha:1.0];
|
||||
var sourceListActiveGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [255.0 / 255.0, 153.0 / 255.0, 209.0 / 255.0, 1.0, 33.0 / 255.0, 94.0 / 255.0, 208.0 / 255.0, 1.0], [0, 1], 2),
|
||||
sourceListActiveTopLineColor = [CPColor colorWithCalibratedRed:(255.0 / 255.0) green:(123.0 / 255.0) blue:(218.0 / 255.0) alpha:1.0],
|
||||
sourceListActiveBottomLineColor = [CPColor colorWithCalibratedRed:(255.0 / 255.0) green:(92.0 / 255.0) blue:(207.0 / 255.0) alpha:1.0];
|
||||
[tableView setSelectionGradientColors:[CPDictionary dictionaryWithObjects:[sourceListActiveGradient, sourceListActiveTopLineColor, sourceListActiveBottomLineColor] forKeys:[CPSourceListGradient, CPSourceListTopLineColor, CPSourceListBottomLineColor]]];
|
||||
}
|
||||
|
||||
@@ -296,18 +296,18 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
var newDescriptors = [aTableView sortDescriptors];
|
||||
|
||||
[(aTableView === tableView) ? dataSet1:dataSet2 sortUsingDescriptors:newDescriptors];
|
||||
[aTableView reloadData];
|
||||
[aTableView reloadData];
|
||||
}
|
||||
|
||||
|
||||
- (void)tableViewSelectionIsChanging:(CPNotification)aNotification
|
||||
{
|
||||
//CPLog.debug(@"changing! %@", [aNotification description]);
|
||||
//CPLog.debug(@"changing! %@", [aNotification description]);
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(CPNotification)aNotification
|
||||
{
|
||||
//CPLog.debug(@"did change! %@", [aNotification description]);
|
||||
//CPLog.debug(@"did change! %@", [aNotification description]);
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(CPTableView)aTableView shouldSelectRow:(int)rowIndex
|
||||
@@ -318,8 +318,8 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
|
||||
- (BOOL)selectionShouldChangeInTableView:(CPTableView)aTableView
|
||||
{
|
||||
//CPLog.debug(@"selectionShouldChangeInTableView");
|
||||
return YES;
|
||||
//CPLog.debug(@"selectionShouldChangeInTableView");
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(id)notification
|
||||
@@ -362,7 +362,7 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
var newDescriptors = [aTableView sortDescriptors];
|
||||
|
||||
[(aTableView === tableView) ? dataSet1:dataSet2 sortUsingDescriptors:newDescriptors];
|
||||
[aTableView reloadData];
|
||||
[aTableView reloadData];
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(CPTableView)aTableView writeRowsWithIndexes:(CPIndexSet)rowIndexes toPasteboard:(CPPasteboard)pboard
|
||||
@@ -414,7 +414,7 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
destinationDataSet = dataSets[1 - index],
|
||||
sourceDataSet = dataSets[index];
|
||||
|
||||
if (operation | CPDragOperationMove)
|
||||
if (operation & CPDragOperationMove)
|
||||
{
|
||||
if (sourceTableUID == [aTableView UID])
|
||||
{
|
||||
@@ -454,33 +454,34 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
@end
|
||||
|
||||
@implementation CPArray (MoveIndexes)
|
||||
|
||||
- (void)moveIndexes:(CPIndexSet)indexes toIndex:(int)insertIndex
|
||||
{
|
||||
var aboveCount = 0,
|
||||
object,
|
||||
removeIndex;
|
||||
|
||||
var index = [indexes lastIndex];
|
||||
|
||||
|
||||
var index = [indexes lastIndex];
|
||||
|
||||
while (index != CPNotFound)
|
||||
{
|
||||
if (index >= insertIndex)
|
||||
{
|
||||
removeIndex = index + aboveCount;
|
||||
aboveCount ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
removeIndex = index;
|
||||
insertIndex --;
|
||||
}
|
||||
|
||||
object = [self objectAtIndex:removeIndex];
|
||||
[self removeObjectAtIndex:removeIndex];
|
||||
[self insertObject:object atIndex:insertIndex];
|
||||
|
||||
index = [indexes indexLessThanIndex:index];
|
||||
}
|
||||
{
|
||||
if (index >= insertIndex)
|
||||
{
|
||||
removeIndex = index + aboveCount;
|
||||
aboveCount ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
removeIndex = index;
|
||||
insertIndex --;
|
||||
}
|
||||
|
||||
object = [self objectAtIndex:removeIndex];
|
||||
[self removeObjectAtIndex:removeIndex];
|
||||
[self insertObject:object atIndex:insertIndex];
|
||||
|
||||
index = [indexes indexLessThanIndex:index];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user