Files
cappuccino/Tests/Objective-J/Preprocessor/BehaviorTests/MethodTest.j
T
Alexander Ljungberg 5ec9cf7faf Fixed: "in" could not be a parameter in a message.
With the new compiler, messages such as `[a in:b]` could not be sent, the "in:" parameter throwing an unexpected token error. This was true both if "in" was the first argument or any of the subsequent parameters (such as in `[a something:X in:Y]`).
2013-01-21 02:11:51 +00:00

84 lines
1.4 KiB
Plaintext

@import <Foundation/Foundation.j>
@import <OJUnit/OJTestCase.j>
@implementation MathClass : CPObject
{
}
- (CPNumber)five
{
return 5;
}
- (CPNumber)sqrt:(CPNumber)operand
{
return SQRT(operand);
}
- (CPNumber)multiply:(CPNumber)firstOperand with:(CPNumber)secondOperand
{
return firstOperand * secondOperand;
}
- (CPNumber)multiply:(CPNumber)operand, ...
{
var product;
for (var i = 2, ii = arguments.length; i < ii; ++i)
product = product ? product * arguments[i] : arguments[i];
return product;
}
- (id)in:(int)aNumber void:(int)anotherNumber
{
return aNumber - anotherNumber;
}
- (id)void:(int)aNumber in:(int)anotherNumber
{
return anotherNumber - aNumber;
}
@end
@implementation MethodTest : OJTestCase
{
MathClass testClass;
}
- (void)setUp
{
testClass = [[MathClass alloc] init];
}
- (void)testNoParameters
{
[self assert:5 equals:[testClass five]];
}
- (void)testOneParameter
{
[self assert:2 equals:[testClass sqrt:4]];
}
- (void)testTwoParameters
{
[self assert:6 equals:[testClass multiply:2 with:3]];
}
- (void)testVarArgs
{
[self assert:30 equals:[testClass multiply:2, 3, 5]];
[self assert:2310 equals:[testClass multiply:2, 3, 5, 7, 11]];
}
- (void)testKeywordsInSelector
{
[self assert:6 equals:[testClass in:10 void:4]];
[self assert:-6 equals:[testClass void:10 in:4]];
}
@end