mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-06 18:57:12 +00:00
Merge branch 'master' into tolmasky
Conflicts: AppKit/CPControl.j AppKit/CPTextField.j
This commit is contained in:
@@ -111,6 +111,7 @@
|
||||
_tileWidth = -1.0;
|
||||
|
||||
_selectionIndexes = [CPIndexSet indexSet];
|
||||
_isSelectable = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -258,7 +259,7 @@
|
||||
*/
|
||||
- (void)setSelectionIndexes:(CPIndexSet)anIndexSet
|
||||
{
|
||||
if (_selectionIndexes == anIndexSet)
|
||||
if (_selectionIndexes == anIndexSet || !_isSelectable)
|
||||
return;
|
||||
|
||||
var index = CPNotFound;
|
||||
|
||||
@@ -523,6 +523,8 @@ var hexCharacters = "0123456789ABCDEF";
|
||||
*/
|
||||
function hexToRGB(hex)
|
||||
{
|
||||
if ( hex.length == 3 )
|
||||
hex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
|
||||
if(hex.length != 6)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -103,6 +103,8 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
|
||||
JSObject _ephemeralSubviewsForNames;
|
||||
CPSet _ephereralSubviews;
|
||||
|
||||
CPString _toolTip;
|
||||
|
||||
// FIXME: Who uses this?
|
||||
BOOL _isBezeled;
|
||||
@@ -183,6 +185,33 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
return previousMask;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the tooltip for the receiver.
|
||||
@param aToolTip the tooltip
|
||||
*/
|
||||
/*
|
||||
-(void)setToolTip:(CPString)aToolTip
|
||||
{
|
||||
if (_toolTip == aToolTip)
|
||||
return;
|
||||
|
||||
_toolTip = aToolTip;
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
_DOMElement.title = aToolTip;
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
/*!
|
||||
Returns the receiver's tooltip
|
||||
*/
|
||||
/*
|
||||
-(CPString)toolTip
|
||||
{
|
||||
return _toolTip;
|
||||
}
|
||||
*/
|
||||
|
||||
/*!
|
||||
Returns whether the control can continuously send its action messages.
|
||||
*/
|
||||
|
||||
@@ -450,7 +450,7 @@ CPPopUpButtonStatePullsDown = 1 << 12;
|
||||
*/
|
||||
- (int)indexOfItemWithRepresentedObject:(id)anObject
|
||||
{
|
||||
return [_menu indexOfItemWithRepresentedObejct:anObject];
|
||||
return [_menu indexOfItemWithRepresentedObject:anObject];
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -780,4 +780,4 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
|
||||
[aCoder encodeObject:_placeholderString forKey:CPTextFieldPlaceholderStringKey];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
@@ -95,7 +95,7 @@ var CAMediaNamedTimingFunctions = nil;
|
||||
else
|
||||
{
|
||||
reference[0] = 1.0;
|
||||
reference[0] = 1.0;
|
||||
reference[1] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+40
-19
@@ -57,7 +57,16 @@
|
||||
|
||||
SEL _replaceSEL;
|
||||
Function _replace;
|
||||
|
||||
SEL _insertManySEL;
|
||||
Function _insertMany;
|
||||
|
||||
SEL _removeManySEL;
|
||||
Function _removeMany;
|
||||
|
||||
SEL _replaceManySEL;
|
||||
Function _replaceMany;
|
||||
|
||||
SEL _objectAtIndexSEL;
|
||||
Function _objectAtIndex;
|
||||
|
||||
@@ -95,32 +104,44 @@
|
||||
var capitalizedKey = _key.charAt(0).toUpperCase() + _key.substring(1);
|
||||
|
||||
_insertSEL = sel_getName(@"insertObject:in"+capitalizedKey+"AtIndex:");
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_insert = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_insertSEL])
|
||||
_insert = [_proxyObject methodForSelector:_insertSEL];
|
||||
|
||||
_removeSEL = sel_getName(@"removeObjectFrom"+capitalizedKey+"AtIndex:");
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_remove = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_removeSEL])
|
||||
_remove = [_proxyObject methodForSelector:_removeSEL];
|
||||
|
||||
_replaceSEL = sel_getName(@"replaceObjectFrom"+capitalizedKey+"AtIndex:withObject:");
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_replace = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_replaceSEL])
|
||||
_replace = [_proxyObject methodForSelector:_replaceSEL];
|
||||
|
||||
_insertManySEL = sel_getName(@"insertObjects:in"+capitalizedKey+"AtIndexes:");
|
||||
if ([_proxyObject respondsToSelector:_insertManySEL])
|
||||
_insert = [_proxyObject methodForSelector:_insertManySEL];
|
||||
|
||||
_removeManySEL = sel_getName(@"removeObjectsFrom"+capitalizedKey+"AtIndexes:");
|
||||
if ([_proxyObject respondsToSelector:_removeManySEL])
|
||||
_remove = [_proxyObject methodForSelector:_removeManySEL];
|
||||
|
||||
_replaceManySEL = sel_getName(@"replaceObjectsFrom"+capitalizedKey+"AtIndexes:withObjects:");
|
||||
if ([_proxyObject respondsToSelector:_replaceManySEL])
|
||||
_replace = [_proxyObject methodForSelector:_replaceManySEL];
|
||||
|
||||
_objectAtIndexSEL = sel_getName(@"objectIn"+capitalizedKey+"AtIndex:");
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_objectAtIndex = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_objectAtIndexSEL])
|
||||
_objectAtIndex = [_proxyObject methodForSelector:_objectAtIndexSEL];
|
||||
|
||||
_countSEL = sel_getName(@"countOf"+capitalizedKey);
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_count = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_countSEL])
|
||||
_count = [_proxyObject methodForSelector:_countSEL];
|
||||
|
||||
_accessSEL = sel_getName(_key);
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_access = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_accessSEL])
|
||||
_access = [_proxyObject methodForSelector:_accessSEL];
|
||||
|
||||
_setSEL = sel_getName(@"set"+capitalizedKey+":");
|
||||
if ([_proxyObject respondsToSelector:selector])
|
||||
_set = [_proxyObject methodForSelector:selector];
|
||||
if ([_proxyObject respondsToSelector:_setSEL])
|
||||
_set = [_proxyObject methodForSelector:_setSEL];
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -176,7 +197,7 @@
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target addObject:anObject];
|
||||
[_self _setRepresentedObject:target];
|
||||
[self _setRepresentedObject:target];
|
||||
}
|
||||
|
||||
- (void)insertObject:(id)anObject atIndex:(unsigned)anIndex
|
||||
@@ -187,7 +208,7 @@
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target insertObject:anObject atIndex:anIndex];
|
||||
[_self _setRepresentedObject:target];
|
||||
[self _setRepresentedObject:target];
|
||||
}
|
||||
|
||||
- (void)removeLastObject
|
||||
@@ -198,7 +219,7 @@
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target removeLastObject];
|
||||
[_self _setRepresentedObject:target];
|
||||
[self _setRepresentedObject:target];
|
||||
}
|
||||
|
||||
- (void)removeObjectAtIndex:(unsigned)anIndex
|
||||
@@ -209,7 +230,7 @@
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target removeObjectAtIndex:anIndex];
|
||||
[_self _setRepresentedObject:target];
|
||||
[self _setRepresentedObject:target];
|
||||
}
|
||||
|
||||
- (void)replaceObjectAtIndex:(unsigned)anIndex withObject:(id)anObject
|
||||
@@ -220,7 +241,7 @@
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target replaceObjectAtIndex:anIndex withObject:anObject];
|
||||
[_self _setRepresentedObject:target];
|
||||
[self _setRepresentedObject:target];
|
||||
}
|
||||
|
||||
- (CPArray)objectsAtIndexes:(CPIndexSet)indexes
|
||||
|
||||
@@ -674,7 +674,7 @@
|
||||
*/
|
||||
- (CPArray)arrayByAddingObject:(id)anObject
|
||||
{
|
||||
if (!anObject)
|
||||
if (anObject === nil || anObject === undefined)
|
||||
[CPException raise:CPInvalidArgumentException
|
||||
reason:"arrayByAddingObject: object can't be nil"];
|
||||
|
||||
|
||||
+20
-2
@@ -39,10 +39,17 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
+ (id)dateWithTimeIntervalSinceNow:(CPTimeInterval)seconds
|
||||
{
|
||||
return [[CPDate alloc] initWithTimeIntervalSinceNow:seconds];
|
||||
}
|
||||
|
||||
+ (id)dateWithTimeIntervalSince1970:(CPTimeInterval)seconds
|
||||
{
|
||||
return [[CPDate alloc] initWithTimeIntervalSince1970:seconds];
|
||||
}
|
||||
|
||||
+ (id)dateWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
|
||||
{
|
||||
return [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:seconds];
|
||||
@@ -63,23 +70,31 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
self = new Date((new Date()).getTime() + seconds * 1000);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds
|
||||
{
|
||||
self = new Date(seconds * 1000);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
|
||||
{
|
||||
self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(CPDate)refDate
|
||||
{
|
||||
self = new Date(refDate.getTime() + seconds * 1000);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithString:(CPString)description
|
||||
{
|
||||
self = new Date(description); // FIXME: not same format as NSString
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (CPTimeInterval)timeIntervalSinceDate:(CPDate)anotherDate
|
||||
{
|
||||
return (self.getTime() - anotherDate.getTime()) / 1000.0;
|
||||
@@ -89,14 +104,17 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
{
|
||||
return [self timeIntervalSinceDate:[CPDate date]];
|
||||
}
|
||||
|
||||
- (CPTimeInterval)timeIntervalSince1970
|
||||
{
|
||||
return self.getTime() / 1000.0;
|
||||
}
|
||||
|
||||
- (CPTimeInterval)timeIntervalSinceReferenceDate
|
||||
{
|
||||
return (self.getTime() - CPDateReferenceDate.getTime()) / 1000.0;
|
||||
}
|
||||
|
||||
+ (CPTimeInterval)timeIntervalSinceReferenceDate
|
||||
{
|
||||
return [[CPDate date] timeIntervalSinceReferenceDate];
|
||||
@@ -129,4 +147,4 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
|
||||
@end
|
||||
|
||||
Date.prototype.isa = CPDate;
|
||||
Date.prototype.isa = CPDate;
|
||||
|
||||
@@ -268,7 +268,7 @@
|
||||
if (lhsObject === rhsObject)
|
||||
continue;
|
||||
|
||||
if ([lhsObject respondsToSelector:@selector(isEqual:)] && [lhsObject isEqual:rhsObject])
|
||||
if (lhsObject.isa && rhsObject.isa && [lhsObject respondsToSelector:@selector(isEqual:)] && [lhsObject isEqual:rhsObject])
|
||||
continue;
|
||||
|
||||
return NO;
|
||||
|
||||
@@ -146,6 +146,10 @@ if (input == nil)
|
||||
|
||||
@end
|
||||
|
||||
var CPExceptionNameKey = "CPExceptionNameKey",
|
||||
CPExceptionReasonKey = "CPExceptionReasonKey",
|
||||
CPExceptionUserInfoKey = "CPExceptionUserInfoKey";
|
||||
|
||||
@implementation CPException (CPCoding)
|
||||
|
||||
/*!
|
||||
@@ -161,7 +165,7 @@ if (input == nil)
|
||||
{
|
||||
name = [aCoder decodeObjectForKey:CPExceptionNameKey];
|
||||
reason = [aCoder decodeObjectForKey:CPExceptionReasonKey];
|
||||
userInfo = [aCoer decodeObjectForKey:CPExceptionUserInfoKey];
|
||||
userInfo = [aCoder decodeObjectForKey:CPExceptionUserInfoKey];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
@@ -41,7 +41,7 @@ var CPNotificationDefaultCenter = nil;
|
||||
/*!
|
||||
Returns the application's notification center
|
||||
*/
|
||||
+ (CPNotifcationCenter)defaultCenter
|
||||
+ (CPNotificationCenter)defaultCenter
|
||||
{
|
||||
if (!CPNotificationDefaultCenter)
|
||||
CPNotificationDefaultCenter = [[CPNotificationCenter alloc] init];
|
||||
|
||||
+37
-4
@@ -23,8 +23,41 @@
|
||||
/*!
|
||||
@class CPObject
|
||||
|
||||
CPObject is the root class for most Cappuccino classes. Your custom classes
|
||||
should almost always subclass CPObject or one of its children.
|
||||
CPObject is the root class for most Cappuccino classes. Like in Objective-C,
|
||||
you have to declare parent class explicitly in Objective-J, so your custom
|
||||
classes should almost always subclass CPObject or one of its children.
|
||||
|
||||
CPObject provides facilities for class allocation and initialization,
|
||||
querying runtime about parent classes and available selectors, using KVC
|
||||
(key-value coding).
|
||||
|
||||
When you subclass CPObject, most of the time you override one selector - init.
|
||||
It is called for default initialization of custom object. You must call
|
||||
parent class init in your overriden code:
|
||||
<pre>- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
... provide default initialization code for your object ...
|
||||
}
|
||||
return self;
|
||||
}</pre>
|
||||
|
||||
One more useful thing to override is description(). This selector
|
||||
is used to provide developer-readable information about object. description
|
||||
selector is often used with CPLog debugging:
|
||||
<pre>- (CPString)description
|
||||
{
|
||||
return [CPString stringWithFormat:@"<SomeClass %d>", someValue];
|
||||
}</pre>
|
||||
To get description value you can use %@ specifier everywhere where format
|
||||
specifiers are allowed:
|
||||
<pre>var inst = [[SomeClass alloc] initWithSomeValue:10];
|
||||
CPLog(@"Got some class: %@", inst);</pre>
|
||||
would output:
|
||||
<pre>Got some class: <SomeClass 10></pre>
|
||||
|
||||
@todo document KVC usage.
|
||||
*/
|
||||
@implementation CPObject
|
||||
{
|
||||
@@ -177,7 +210,7 @@
|
||||
*/
|
||||
+ (BOOL)instancesRespondToSelector:(SEL)aSelector
|
||||
{
|
||||
return class_getInstanceMethod(self, aSelector);
|
||||
return !!class_getInstanceMethod(self, aSelector);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -187,7 +220,7 @@
|
||||
*/
|
||||
- (BOOL)respondsToSelector:(SEL)aSelector
|
||||
{
|
||||
return class_getInstanceMethod(isa, aSelector) != NULL;
|
||||
return !!class_getInstanceMethod(isa, aSelector);
|
||||
}
|
||||
|
||||
// Obtaining method information
|
||||
|
||||
+13
-5
@@ -91,7 +91,7 @@ var CPStringHashes = new objj_dictionary();
|
||||
*/
|
||||
+ (id)stringWithHash:(unsigned)aHash
|
||||
{
|
||||
var hashString = String(aHash);
|
||||
var hashString = parseInt(aHash, 10).toString(16);
|
||||
return "000000".substring(0, MAX(6-hashString.length, 0)) + hashString;
|
||||
}
|
||||
|
||||
@@ -222,13 +222,16 @@ var CPStringHashes = new objj_dictionary();
|
||||
return substr(0, aLength);
|
||||
|
||||
var string = self,
|
||||
substring = aString.substr(anIndex),
|
||||
substring = aString.substring(anIndex),
|
||||
difference = aLength - length;
|
||||
|
||||
while ((difference -= substring.length) > 0)
|
||||
while ((difference -= substring.length) >= 0)
|
||||
string += substring;
|
||||
|
||||
if (difference) string += substring.substr(difference + substring.length);
|
||||
if (-difference < substring.length)
|
||||
string += substring.substring(0, -difference);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
//Dividing Strings
|
||||
@@ -584,7 +587,12 @@ var CPStringHashes = new objj_dictionary();
|
||||
*/
|
||||
- (CPArray)pathComponents
|
||||
{
|
||||
return split('/');
|
||||
var result = split('/');
|
||||
if (result[0] === "")
|
||||
result[0] = "/";
|
||||
if (result[result.length - 1] === "")
|
||||
result.pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -55,3 +55,19 @@
|
||||
@import "CPURLResponse.j"
|
||||
@import "CPUserSessionManager.j"
|
||||
@import "CPValue.j"
|
||||
|
||||
/*! @mainpage
|
||||
Cappuccino is distributed under the @ref license "GNU LGPL".
|
||||
|
||||
@htmlonly <pre>@endhtmlonly
|
||||
@htmlinclude README
|
||||
@htmlonly </pre>@endhtmlonly
|
||||
|
||||
@page license License
|
||||
@htmlonly <pre>@endhtmlonly
|
||||
@htmlinclude LICENSE
|
||||
@htmlonly </pre>@endhtmlonly
|
||||
|
||||
@defgroup appkit AppKit
|
||||
@defgroup foundation Foundation
|
||||
*/
|
||||
|
||||
@@ -100,4 +100,4 @@ function main()
|
||||
}
|
||||
}
|
||||
|
||||
main.apply(main, arguments);
|
||||
main.apply(main, args);
|
||||
|
||||
@@ -2,6 +2,14 @@ import <Foundation/CPDate.j>
|
||||
|
||||
@implementation CPDateTest : OJTestCase
|
||||
|
||||
- (void)testSince1970
|
||||
{
|
||||
/* These two dates should be equal to Fri Feb 13 2009 15:31:30 GMT-0800 */
|
||||
unixDate = [CPDate dateWithTimeIntervalSince1970: 1234567890];
|
||||
cocoaDate = [CPDate dateWithTimeIntervalSinceReferenceDate: 253582290];
|
||||
[self assertTrue:[unixDate isEqualToDate: cocoaDate]];
|
||||
}
|
||||
|
||||
- (void)testDate
|
||||
{
|
||||
var before = new Date();
|
||||
@@ -17,4 +25,4 @@ import <Foundation/CPDate.j>
|
||||
[self assert:middle equals:[middle laterDate:past] message:"laterDate incorrect"];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
@@ -16,14 +16,112 @@ import <Foundation/CPString.j>
|
||||
}
|
||||
- (void)testStringByAppendingFormat
|
||||
{
|
||||
var format = @"%d X %d = %d";
|
||||
var expectedString = "2 X 3 = 6";
|
||||
var dummyString = @"";
|
||||
var actualString = [dummyString stringByAppendingFormat:format ,2 ,3 ,6];
|
||||
var format = @"%d X %d = %d",
|
||||
expectedString = "2 X 3 = 6",
|
||||
dummyString = @"",
|
||||
actualString = [dummyString stringByAppendingFormat:format, 2, 3, 6];
|
||||
|
||||
[self assertTrue:(expectedString === actualString)
|
||||
message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
|
||||
|
||||
}
|
||||
|
||||
- (void)testStringWithString
|
||||
{
|
||||
var original = [[CPString alloc] initWithString:"str"],
|
||||
copy = [CPString stringWithString:original];
|
||||
|
||||
[self assertTrue:(original == copy) message:"Contents should be equal"];
|
||||
}
|
||||
|
||||
- (void)testInitWithString
|
||||
{
|
||||
var str = [[CPString alloc] initWithString:"str"];
|
||||
[self assert:"str" equals:str];
|
||||
}
|
||||
|
||||
- (void) testInitWithFormat
|
||||
{
|
||||
// this could be really big
|
||||
var str = [[CPString alloc] initWithFormat:"%s", "str"];
|
||||
[self assert:"str" equals:str];
|
||||
|
||||
str = [[CPString alloc] initWithFormat:"%d", 42];
|
||||
[self assert:"42" equals:str];
|
||||
|
||||
str = [[CPString alloc] initWithFormat:"%f", 42.2];
|
||||
[self assert:"42.2" equals:str];
|
||||
}
|
||||
|
||||
- (void)testStringWithFormat
|
||||
{
|
||||
// this could be equally big
|
||||
var str = [CPString stringWithFormat:"%s", "str"];
|
||||
[self assert:"str" equals:str];
|
||||
|
||||
str = [CPString stringWithFormat:"%d", 42];
|
||||
[self assert:"42" equals:str];
|
||||
|
||||
str = [CPString stringWithFormat:"%f", 42.2];
|
||||
[self assert:"42.2" equals:str];
|
||||
}
|
||||
|
||||
- (void)testLength
|
||||
{
|
||||
[self assert:0 equals:["" length]];
|
||||
[self assert:1 equals:["a" length]];
|
||||
[self assert:5 equals:["abcde" length]];
|
||||
[self assert:3 equals:["日本語" length]];
|
||||
}
|
||||
|
||||
- (void)testCharacterAtIndex
|
||||
{
|
||||
[self assert:"a" equals:["abcd" characterAtIndex:0]];
|
||||
[self assert:"b" equals:["abcd" characterAtIndex:1]];
|
||||
[self assert:"d" equals:["abcd" characterAtIndex:3]];
|
||||
[self assert:"語" equals:["日本語" characterAtIndex:2]];
|
||||
}
|
||||
|
||||
- (void)testStringByAppendingSting
|
||||
{
|
||||
[self assert:"onetwo" equals:["one" stringByAppendingString:"two"]];
|
||||
}
|
||||
|
||||
|
||||
- (void)testStringByPaddingToLength
|
||||
{
|
||||
[self assert:"onebcd"
|
||||
equals:["one" stringByPaddingToLength:6
|
||||
withString:"abcdefg"
|
||||
startingAtIndex:1]];
|
||||
}
|
||||
|
||||
- (void)testComponentsSeparatedByString
|
||||
{
|
||||
[self assert:["arash", "francisco", "ross", "tom"]
|
||||
equals:["arash.francisco.ross.tom" componentsSeparatedByString:"."]];
|
||||
}
|
||||
|
||||
- (void)testSubstringFromIndex
|
||||
{
|
||||
[self assert:"abcd" equals:["abcd" substringFromIndex:0]];
|
||||
[self assert:"bcd" equals:["abcd" substringFromIndex:1]];
|
||||
[self assert:"" equals:["abcd" substringFromIndex:4]];
|
||||
}
|
||||
|
||||
- (void)testSubstringWithRange
|
||||
{
|
||||
[self assert:"bcd" equals:["abcde" substringWithRange:CPMakeRange(1,3)]];
|
||||
[self assert:"abcde" equals:["abcde" substringWithRange:CPMakeRange(0,5)]];
|
||||
[self assert:"" equals:["abcde" substringWithRange:CPMakeRange(1,0)]];
|
||||
}
|
||||
|
||||
- (void)testSubstringToIndex
|
||||
{
|
||||
[self assert:"abcd" equals:["abcd" substringToIndex:4]];
|
||||
[self assert:"abc" equals:["abcd" substringToIndex:3]];
|
||||
[self assert:"" equals:["abcd" substringToIndex:0]];
|
||||
}
|
||||
|
||||
- (void)testBoolValue
|
||||
{
|
||||
var testStrings = [
|
||||
@@ -59,6 +157,27 @@ import <Foundation/CPString.j>
|
||||
[self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
|
||||
}
|
||||
|
||||
- (void)testUppercaseString
|
||||
{
|
||||
var str = "This is a test";
|
||||
[self assert:[str uppercaseString] equals:"THIS IS A TEST"];
|
||||
}
|
||||
|
||||
- (void)testLowercaseString
|
||||
{
|
||||
var str = "This Is A TEST";
|
||||
[self assert:"this is a test" equals:[str lowercaseString]];
|
||||
}
|
||||
|
||||
- (void)testStringWithHash
|
||||
{
|
||||
[self assert:"000000" equals:[CPString stringWithHash:0]];
|
||||
[self assert:"000001" equals:[CPString stringWithHash:1]];
|
||||
[self assert:"00000a" equals:[CPString stringWithHash:10]];
|
||||
[self assert:"000010" equals:[CPString stringWithHash:16]];
|
||||
[self assert:"ffffff" equals:[CPString stringWithHash:16777215]];
|
||||
}
|
||||
|
||||
- (void)testStringByDeletingLastPathComponent
|
||||
{
|
||||
var testStrings = [
|
||||
@@ -80,4 +199,31 @@ import <Foundation/CPString.j>
|
||||
[self assert:[testStrings[i][0] stringByDeletingLastPathComponent] equals:testStrings[i][1]];
|
||||
}
|
||||
|
||||
- (void)testPathComponents
|
||||
{
|
||||
var testStrings = [
|
||||
["tmp/scratch", ["tmp", "scratch"]],
|
||||
["/tmp/scratch", ["/", "tmp", "scratch"]]
|
||||
]
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++) {
|
||||
var result = [testStrings[i][0] pathComponents];
|
||||
[self assertTrue:[result isEqualToArray:testStrings[i][1]] message:"Expected [" + testStrings[i][1] + "] was [" + result + "]"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testLastPathComponent
|
||||
{
|
||||
var testStrings = [
|
||||
["/tmp/scratch.tiff", "scratch.tiff"],
|
||||
["/tmp/scratch", "scratch"],
|
||||
["/tmp/", "tmp"],
|
||||
["scratch", "scratch"],
|
||||
["/", "/"]
|
||||
];
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++)
|
||||
[self assert:testStrings[i][1] equals:[testStrings[i][0] lastPathComponent]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -137,7 +137,8 @@ EXCLUDE = AppKit/Cib \
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS = _*
|
||||
EXCLUDE_SYMBOLS = _*
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATH = ./README \
|
||||
./LICENSE
|
||||
EXAMPLE_PATTERNS = *
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
|
||||
Binary file not shown.
@@ -85,7 +85,7 @@ function traverseDependencies(context, file)
|
||||
{
|
||||
if (context.dependencies[token])
|
||||
{
|
||||
var files = context.dependencies[token]
|
||||
var files = context.dependencies[token];
|
||||
for (var j = 0; j < files.length; j++)
|
||||
{
|
||||
// don't record references to self
|
||||
@@ -232,7 +232,7 @@ function findGlobalDefines(context, scope, rootPath, evaledFragments)
|
||||
|
||||
if (evaledFragments)
|
||||
{
|
||||
evaledFragments.push(aFragment);
|
||||
evaledFragments.push(aFragment);
|
||||
}
|
||||
|
||||
var result = fragment_evaluate_code_original(aFragment);
|
||||
|
||||
+28
-17
@@ -11,7 +11,8 @@ var usageMessage =
|
||||
--frameworks path The relative path (from root_directory) to the frameworks directory (default: 'Frameworks')\n\
|
||||
--png Run pngcrush on all PNGs (pngcrush must be installed!)\n\
|
||||
--flatten Flatten all code into a single Application.js file and attempt add script tag to index.html (useful for Adobe AIR and CDN deployment)\n\
|
||||
--nostrip Don't strip any files";
|
||||
--nostrip Don't strip any files\n\
|
||||
--v Verbose";
|
||||
|
||||
function main()
|
||||
{
|
||||
@@ -22,7 +23,7 @@ function main()
|
||||
optimizePNG = false,
|
||||
flatten = false,
|
||||
noStrip = false,
|
||||
verbose = true;
|
||||
verbose = false;
|
||||
|
||||
var usageError = false;
|
||||
while (args.length && !usageError)
|
||||
@@ -51,6 +52,9 @@ function main()
|
||||
case "--nostrip":
|
||||
noStrip = true;
|
||||
break;
|
||||
case "--v":
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
if (rootDirectory == null)
|
||||
rootDirectory = arg.replace(/\/$/, "");
|
||||
@@ -125,6 +129,11 @@ function main()
|
||||
// coalesce the results
|
||||
var dependencies = coalesceGlobalDefines(globals);
|
||||
|
||||
// Log
|
||||
CPLog.trace("Global defines:");
|
||||
for (var i in dependencies)
|
||||
CPLog.trace(" " + i + " => " + dependencies[i]);
|
||||
|
||||
// phase 2: walk the dependency tree (both imports and references) to determine exactly which files need to be included
|
||||
CPLog.error("PHASE 2: Walk dependency tree...");
|
||||
|
||||
@@ -143,7 +152,7 @@ function main()
|
||||
return;
|
||||
}
|
||||
|
||||
CPLog.info("Analyzing dependencies...");
|
||||
CPLog.warn("Analyzing dependencies...");
|
||||
|
||||
var context = {
|
||||
scope : scope,
|
||||
@@ -172,21 +181,21 @@ function main()
|
||||
}
|
||||
else
|
||||
{
|
||||
CPLog.warn("Excluded: " + path);
|
||||
CPLog.info("Excluded: " + path);
|
||||
}
|
||||
total++;
|
||||
}
|
||||
CPLog.info("Total required files: " + count + " out of " + total);
|
||||
CPLog.warn("Total required files: " + count + " out of " + total);
|
||||
|
||||
// FIXME: sprite images
|
||||
for (var i in context.bundleImages)
|
||||
{
|
||||
var images = context.bundleImages[i];
|
||||
|
||||
//CPLog.info("Bundle images for " + i);
|
||||
//for (var j in images)
|
||||
// CPLog.debug(j + " = " + images[j]);
|
||||
}
|
||||
//for (var i in context.bundleImages)
|
||||
//{
|
||||
// var images = context.bundleImages[i];
|
||||
//
|
||||
// CPLog.debug("Bundle images for " + i);
|
||||
// for (var j in images)
|
||||
// CPLog.trace(j + " = " + images[j]);
|
||||
//}
|
||||
}
|
||||
|
||||
var outputFiles = {};
|
||||
@@ -236,7 +245,7 @@ function main()
|
||||
}
|
||||
else
|
||||
{
|
||||
CPLog.warn("Stripping " + evaledFragments[i].file.path);
|
||||
CPLog.info("Stripping " + evaledFragments[i].file.path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +281,7 @@ function main()
|
||||
directory = dirname(path);
|
||||
|
||||
if (file.path != path)
|
||||
CPLog.warn("Sanity check (file path): " + file.path + " vs. " + path);
|
||||
CPLog.warn("Sanity check failed (file path): " + file.path + " vs. " + path);
|
||||
|
||||
if (file.bundle)
|
||||
{
|
||||
@@ -282,7 +291,7 @@ function main()
|
||||
bundles[file.bundle.path] = file.bundle;
|
||||
|
||||
if (bundleDirectory != directory)
|
||||
CPLog.warn("Sanity check (directory path): " + directory + " vs. " + bundleDirectory);
|
||||
CPLog.warn("Sanity check failed (directory path): " + directory + " vs. " + bundleDirectory);
|
||||
|
||||
// if it's in a .sj
|
||||
var dict = file.bundle.info,
|
||||
@@ -337,7 +346,7 @@ function main()
|
||||
}
|
||||
}
|
||||
else
|
||||
CPLog.warn("Ignoring import fragment " + file.fragments[i].info + " in " + path);
|
||||
CPLog.info("Ignoring import fragment " + file.fragments[i].info + " in " + path);
|
||||
}
|
||||
else
|
||||
CPLog.error("Unknown fragment type");
|
||||
@@ -362,6 +371,8 @@ function main()
|
||||
dict = bundles[path].info,
|
||||
replacedFiles = [dict objectForKey:"CPBundleReplacedFiles"];
|
||||
|
||||
CPLog.info("Modifying .sj: " + path);
|
||||
|
||||
if (replacedFiles)
|
||||
{
|
||||
var newReplacedFiles = [];
|
||||
|
||||
Reference in New Issue
Block a user