Skip to content

Commit

Permalink
test files for the experimental stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed May 6, 2011
1 parent 25582fd commit 6e252c5
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 0 deletions.
64 changes: 64 additions & 0 deletions experimental/res/JSTalk.bridgesupport
@@ -0,0 +1,64 @@
<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='0.9'>

<!--
<struct name='JSTTestStruct' type='{JSTTestStruct=&quot;b&quot;c&quot;f&quot;f&quot;d&quot;d&quot;i8&quot;c&quot;ui8&quot;C&quot;i16&quot;s&quot;ui16&quot;S&quot;i32&quot;i&quot;ui32&quot;I&quot;i64&quot;q&quot;ui64&quot;Q&quot;next&quot;^{JSTTestStruct}}'/>
-->

<struct name='JSTTestStruct' type='{JSTTestStruct=&quot;b&quot;}'/>

<function name='objc_msgSend' variadic='true'>
<arg type='@'/>
<arg type=':'/>
<retval type='@'/>
</function>

<function name='JSTNSString'>
<arg type='@'/>
<retval type='@'/>
</function>

<class name='JSTTests'>

<method selector='testBoolValue'>
<retval declared_type='BOOL' type='B'/>
</method>

<method selector='testClassBoolValue' class_method='true'>
<retval declared_type='BOOL' type='B'/>
</method>

<method selector='testStringValue'>
<retval declared_type='NSString*' type='@'/>
</method>

<method selector='testClassStringValue' class_method='true'>
<retval declared_type='NSString*' type='@'/>
</method>

<method selector='testAppendString'>
<arg name='aString' declared_type='NSString*' type='@' index='0'/>
<retval declared_type='NSString*' type='@'/>
</method>

<method selector='testClassAppendString' class_method='true'>
<arg name='aString' declared_type='NSString*' type='@' index='0'/>
<retval declared_type='NSString*' type='@'/>
</method>

<method selector='classTestNSRect' class_method='true'>
<retval declared_type='NSRect' type64='{CGRect={CGPoint=dd}{CGSize=dd}}' type='{_NSRect={_NSPoint=ff}{_NSSize=ff}}'/>
</method>

<method selector='classTestStruct' class_method='true'>
<!-- <retval declared_type='JSTTestStruct' type64='{JSTTestStruct=cfdcCsSiIqQ^{JSTTestStruct}}' type='{JSTTestStruct=cfdcCsSiIqQ^{JSTTestStruct}}'/> -->
<retval declared_type='JSTTestStruct' type64='{JSTTestStruct=c}' type='{JSTTestStruct=c}'/> -->
</method>

</class>




</signatures>
9 changes: 9 additions & 0 deletions experimental/tests/jstsetup.jstalk
@@ -0,0 +1,9 @@
function jsassert(val, msg) {
if (!val) {
print("Assertion failure!");
print(msg);
//NSBeep();
}
}


46 changes: 46 additions & 0 deletions experimental/tests/testA.jstalk
@@ -0,0 +1,46 @@
[jstalk include:"jstsetup.jstalk"];


var zp = NSZeroPoint;
jsassert(zp, "Can't make a zero point");
jsassert(zp.x == 0, "Can't grab NSZeroPoint");

var name = NSUserName();
jsassert(name);


var d = [NSArray arrayWithObject:NSUserName()];
jsassert([d count] == 1);


var r = NSMakeRect(1, 2, 3, 4);
jsassert(r, "Can't make a rect");
jsassert(r.origin.x == 1, "Wrong value for x");
jsassert(r.origin.y == 2, "Wrong value for y");
jsassert(r.size.width == 3, "Wrong value for width");
jsassert(r.size.height == 4, "Wrong value for height");


var randomConst = NSBundleDidLoadNotification;
jsassert(randomConst, "Can't find NSBundleDidLoadNotification");

jsassert(NSMinYEdge == 1, "Can't find NSMinYEdge");
jsassert(CGRectMinYEdge == 1, "Can't find NSMinYEdge");

var p = NSMakePoint(0,0);

jsassert(p, "Can't make a point");
jsassert(p.x == 0, "Can't verify a point");

p.x = 1;
jsassert(p.x == 1, "Set a point");



/*

if (![private runtimeInfo]) {
[private setRuntimeInfo:[[JSTBridgeSupportLoader sharedController] runtimeInfoForSymbol:NSStringFromClass([self class])]];
}
*/

130 changes: 130 additions & 0 deletions experimental/tests/testB.jstalk
@@ -0,0 +1,130 @@
var s = [JSTTests classTestStruct];
jsassert(s.b, "s.b is wrong");

[jstalk include:"jstsetup.jstalk"];

var r = [JSTTests classTestNSRect];
jsassert(r.origin.x == 1, "r.origin.x");
jsassert(r.origin.y == 2, "r.origin.y");
jsassert(r.size.width == 3, "r.size.width");
jsassert(r.size.height == 4, "r.size.height");

NSLog("Woo!");

var r = NSMakeRange(1, 1);
r.location = 12;
r.length = 11;
jsassert(r.location == 12, "r.location is wrong");
jsassert(r.length == 11, "r.length is wrong");


var r = NSMakeRect(1, 2, 3, 4);

jsassert(r.origin.x == 1, "r.origin.x");
jsassert(r.origin.y == 2, "r.origin.y");
jsassert(r.size.width == 3, "r.size.width");
jsassert(r.size.height == 4, "r.size.height");

r.size.width = 10;
r.size.height = 20;

jsassert(r.size.width == 10, "r.size.width");
jsassert(r.size.height == 20, "r.size.height");

var s = NSMakeSize(1, 2);
jsassert(s.width == 1, "s.width is wrong");
jsassert(s.height == 2, "s.height is wrong");
s.width = 3;
s.height = 4;
jsassert(s.width == 3, "s.width is wrong");
jsassert(s.height == 4, "s.height is wrong");





var r2 = NSMakeRect(5, 6, 7, 8);
jsassert(r2.origin.x == 5, "r2.origin.x");
jsassert(r2.origin.y == 6, "r2.origin.y");
jsassert(r2.size.width == 7, "r2.size.width");
jsassert(r2.size.height == 8, "r2.size.height");


var ti = [[JSTTests alloc] init];

//print("Trying the long double");
//jsassert(55.5 == [ti nonBridgedInstanceMethodReturnAddAndReturnLongDouble:50],
// "nonBridgedInstanceMethodReturnAddAndReturnLongDouble: failed");
jsassert(34.5 == [ti nonBridgedInstanceMethodReturnAddAndReturnDouble:20],
"nonBridgedInstanceMethodReturnAddAndReturnDouble: failed");
jsassert(4.5 == [ti nonBridgedInstanceMethodReturnFloat], "nonBridgedInstanceMethodReturnFloat failed");
jsassert(14.5 == [ti nonBridgedInstanceMethodReturnDouble], "nonBridgedInstanceMethodReturnDouble failed");
jsassert(24.5 == [ti nonBridgedInstanceMethodReturnAddAndReturnFloat:20],
"nonBridgedInstanceMethodReturnAddAndReturnFloat: failed");


jsassert([ti testBoolValue], "[ti testBoolValue] failed");
jsassert([JSTTests testClassBoolValue], "[JSTTests testClassBoolValue] failed");

jsassert([ti testStringValue] == "String from testStringValue", "[ti testStringValue] failed");

jsassert([JSTTests nonBridgedClassMethodReturnString] == "String from nonBridgedClassMethodReturnString",
"[JSTTests nonBridgedClassMethodReturnString] failed");

jsassert([ti nonBridgedInstanceMethodReturnString] == "String from nonBridgedInstanceMethodReturnString",
"[ti nonBridgedInstanceMethodReturnString] failed");


var name = NSFullUserName();
jsassert(name, "NSFullUserName failed");
jsassert((name + "").toLowerCase() == [name lowercaseString], "Lowercase stuff failed");



jsassert(([JSTTests nonBridgedClassMethodReturnInt] == 34), "nonBridgedClassMethodReturnInt failed");
jsassert(([ti nonBridgedInstanceMethodReturnInt] == 36), "nonBridgedInstanceMethodReturnInt failed");
jsassert(([JSTTests nonBridgedClassMethodAddIntTo34:2] == 36), "nonBridgedClassMethodAddIntTo34 failed");
jsassert(([ti nonBridgedInstanceMethodAddIntTo34:4] == 38), "nonBridgedInstanceMethodAddIntTo34 failed");


var nilValue = nil;
jsassert(!nilValue, "nilValue is not nil");

var randomConst = NSBundleDidLoadNotification;
jsassert(randomConst == "NSBundleDidLoadNotification", "Can't find the NSBundleDidLoadNotification const");

var boolVal = NSZombieEnabled;
jsassert(!boolVal, "Why would NSZombieEnabled be enabled?");

jsassert(NSMinYEdge == 1, "Can't find NSMinYEdge");
jsassert(CGRectMinYEdge == 1, "Can't find CGRectMinYEdge");


var twelve = [NSNumber numberWithInt:12];
var fifteen = twelve + 3;
jsassert(fifteen == 15, "Can't add NSNumbers to js number!");

var scriptURL = [[jstalk env] objectForKey:"scriptURL"];
scriptURL = [scriptURL lastPathComponent];
jsassert(scriptURL == "B.jstalk", "lastPathComponent failed");

var a = [[jstalk env] objectForKey:"scriptURL"] + ""
var b = [[jstalk env] objectForKey:"scriptURL"];

jsassert(a == b, "scriptURL conversions failed");

a = [ti testStringValue] + ""
b = ti.testStringValue() + "";

jsassert(a == b, "JS style method A call failed");

var twelve = NSNumber.numberWithInt(12);
var fifteen = twelve + 3;
jsassert(fifteen == 15, "JS style method B call failed!");

var twelve = NSNumber.numberWithInt_(12);
var fifteen = twelve + 3;
//jsassert(fifteen == 15, "JS style method C call failed!");

NSLog("Hey! %@ %p", "What's shaking?", ti);

60 changes: 60 additions & 0 deletions experimental/tests/testForLoops.jstalk
@@ -0,0 +1,60 @@
[jstalk include:"jstsetup.jstalk"];


var d = [NSMutableDictionary dictionary];

[d setObject:'seeeee' forKey:'c'];
d['a'] = 'eh';
d['b'] = 'beee';
for (var key in d) {

var value = d[key];

if (key === 'a') {
jsassert(value == 'eh', "Got " + value + " for a");
}
if (key === 'b') {
jsassert(value == 'beee', "Got " + value + " for b");
}
if (key === 'c') {
jsassert(value == 'seeeee', "Got " + value + " for c");
}
}


var args = [NSMutableArray array];

[args addObject:"one"];
[args addObject:"two"];
[args addObject:"three"];


for (idx in args) {

var checker = function(value, s) {
if (idx == 0) {
jsassert(value == 'one', "Got " + value + " for 1 " + s);
}
if (idx == 1) {
jsassert(value == 'two', "Got " + value + " for 2 " + s);
}
if (idx == 2) {
jsassert(value == 'three', "Got " + value + " for 3 " + s);
}
}

checker([args objectAtIndex:idx], "objectAtIndex");
checker(args[idx], "direct whatever");

}

var gotException = false;

try {
var x = args[5];
}
catch(err) {
gotException = true;
}

jsassert(gotException, "Didn't get the exception when trying to grab an array index that was out of bounds");

0 comments on commit 6e252c5

Please sign in to comment.