Source

Silver / Tests / SVFunctionTests.m

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
//
//  SVFunctionTests.m
//  SV
//
//  Created by Michael Tindal on 7/29/10.
//  Copyright (c) 2010 Michael Tindal. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as 
// published by the Free Software Foundation; either version 3 of 
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#import "SVFunctionTests.h"
#import "SVParserContext.h"
#import "SVVariable.h"
#import "SVVariableAssignment.h"
#import "SVBinaryOperator.h"
#import "SVUnaryOperator.h"
#import "SVBlock.h"
#import "SVFunction.h"
#import "SVControlOperations.h"
#import "SVObjcExtensions.h"
#import "NSMutableDictionary+SVExtensions.h"
#import <OCLog/OCLog.h>
#import <objc/runtime.h>

#define P(n) id n = [[context parse] evaluateNode]
#define PC(s) SVParserContext* context = [SVParserContext parserWithString:s]

extern int SVDebug;
@interface SVNativeFunctionHelper : NSObject

-(NSNumber*) addX:(NSNumber*)x y:(NSNumber*)y;

-(id) logMessage:(id)fmt args:(id)args;

@end

@interface NSArray (SVStuff)

-(NSArray*) select:(SVFunction*)f;

-(NSArray*) map:(SVFunction*)f;

@end

@implementation SVNativeFunctionHelper

-(NSNumber*) addX:(NSNumber *)x y:(NSNumber *)y {
    NSNumber* z = [NSNumber numberWithFloat:([x floatValue] + [y floatValue])];
    return z;
}

-(id)logMessage:(id)fmt args:(id)args {
	NSString* format = fmt;
	NSMutableArray* realargs;
	if(args) {
		if(![args isKindOfClass:[NSArray class]])
			realargs = [NSMutableArray arrayWithObject:args];
		else {
			realargs = [NSMutableArray arrayWithArray:args];
		}
		for(NSUInteger i = 0; i < [realargs count]; i++) {
			id node = [realargs objectAtIndex:i];
            if(!node)
				node = [NSNull null];
			[realargs replaceObjectAtIndex:i withObject:node];
		}
		NSScanner* scanner = [NSScanner scannerWithString:format];
		[scanner setCharactersToBeSkipped:[NSCharacterSet illegalCharacterSet]];
		NSMutableString* message = [NSMutableString string];
		NSString* stemp = nil;
		NSUInteger j = 0;
		while(j < [realargs count] && ![scanner isAtEnd]) {
			[scanner scanUpToString:@"%@" intoString:&stemp];
			if(![scanner isAtEnd]) {
				[scanner scanString:@"%@" intoString:NULL];
				id arg = [realargs objectAtIndex:j++];
                if(stemp) {
					[message appendFormat:@"%@%@",stemp,arg];
				} else {
					[message appendFormat:@"%@",arg];
				}
			} else if(stemp) {
				[message appendString:stemp];
			}
		}
		if(![scanner isAtEnd]) 
			[message appendString:[format substringFromIndex:[scanner scanLocation]]];
		OCLog(@"silver",debug,message);
        return message;
	} else {
		OCLog(@"silver",debug,format);
        return format;
	}
}

-(id)sv_conformsToProtocol:(id)obj :(id)name {
    return BL([obj conformsToProtocol:NSProtocolFromString(name)]);
}
@end

@implementation SVFunctionTests

- (void)setUp {
    [super setUp];
    
    [SVFunction nativeFunctionWithName:@"nadd" target:[SVNativeFunctionHelper class] selector:@selector(addX:y:)];
    [SVFunction nativeFunctionWithName:@"log" target:[SVNativeFunctionHelper class] selector:@selector(logMessage:args:)];
    SVParserContext* context = [SVParserContext parserWithString:@"require('ext');require('bridge');"];
    [[context parse] evaluateNode];
}

- (void)tearDown {
    // Tear-down code here.
    
    [super tearDown];
}

-(void) testFunctionSimple {
    PC(@"def testfunc(num) { x = 10; return x + num; }; testfunc(7);");
    P(var);
    assertThat(var,is(equalTo(N(17))));
}


-(void) testFunctionDefaultValue {
    PC(@"def testfunc(num=15) { x = 10; return x + num; }; testfunc();");
    P(var);
    assertThat(var,is(equalTo(N(25))));
}


-(void) testFunctionSimpleMultipleArguments {
    PC(@"def testfunc(num,y) { x = 10; (x + num)*y; }; testfunc(17,2);");
    P(var);
    assertThat(var,is(equalTo(N(54))));
}

-(void) testFunctionSimpleMultipleArgumentVarArg {
    PC(@"def testfunc(num,*y) { for(x in y) { num += x; }; return num; }; testfunc(10,5,10,15,20,25);");
    P(var);
    assertThat(var,is(equalTo(N(85))));
}

-(void) testFunctionEmptyArgumentList {
    PC(@"def testfunc() { return 10+5; }; testfunc();");
    P(var);
    assertThat(var,is(equalTo(N(15))));
}

-(void) testFunctionDefinitionDefaultNormalVararg {
    PC(@"def testfunc(x=27,y,*z) { n = x + y; for(a in z) { n -= a; }; return n; }; testfunc(y:10,1,2,3);");
    P(var);
    assertThat(var,is(equalTo(N(31))));
}

-(void) testFunctionDefaultKeywordVararg {
    PC(@"def testfunc(a=10,*c) { for(b in c) { a += b; }; return a; }; testfunc(c:10,15,20);");
    P(var);
    assertThat(var,is(equalTo(N(55))));
}

-(void) testFunctionKeywordOverflow {
    SVParserContext* context = [SVParserContext parserWithString:@"def testfunc(a='a',b) { return NSString.stringWithFormat('%@ %@',a,b); }; testfunc(b:'b','c');"];
    P(var);
    assertThat(var,is(equalTo(@"a b")));
}

-(void) testFunctionKeywordOverwrite {
    SVParserContext* context = [SVParserContext parserWithString:@"def testfunc(a='a',b) { return NSString.stringWithFormat('%@ %@',a,b); }; testfunc('a','b',b:'d');"];
    P(var);
    assertThat(var,is(equalTo(@"a d")));
}

-(void) testFunctionReturnValue {
    PC(@"def testfunc(x,y) { return x/y; }; z=18; n=3; testfunc(z,n);");
    P(var);
    assertThat(var,is(equalTo(N(6))));
}

-(void) testFunctionKeywordSimple {
    PC(@"def testfunc(a,b) { return a - b; }; testfunc(b:5,a:10);");
    P(var);
    assertThat(var,is(equalTo(N(5))));
}

-(void) testFunctionKeywordOffset {
    PC(@"def testfunc(a=10,b,c) { x = (a*b)+c; return x; }; testfunc(b:10,25);");
    P(var);
    assertThat(var,is(equalTo(N(125))));
}

-(void) testAnonFuncCall {    
    PC(@"->(num) { num*17;}(3);");
    P(var);
    assertThat(var,is(equalTo(N(51))));
}

-(void) testFunctionReturnInMiddle {
    PC(@"def testfunc(a,b) { return a * b; a/b; }; testfunc(10,5);");
    P(var);
    assertThat(var,is(equalTo(N(50))));
}

-(void) testFunctionEcapsulation {
    PC(@"def testfunc(num) {return num**2; };");
    [[context parse] evaluateNode];
    
    SVParserContext* first = [SVParserContext parserWithString:@"testfunc(7);"];
    SVParserContext* second = [SVParserContext parserWithString:@"testfunc(5);"];
    
    SVFunction* fc = [first parse];
    SVFunction* sc = [second parse];

    id var0 = [fc evaluateNode];
    id var1 = [sc evaluateNode];
    assertThat(var0,is(equalTo(N(49))));
    assertThat(var1,is(equalTo(N(25))));
}

-(void) testNativeFunction {
    PC(@"nadd(3,7);");
    
    P(var);
    assertThat(var,is(equalTo(N(10))));
}

-(void) testNestedFunction {
    SVParserContext* context0 = [SVParserContext parserWithString:@"def nest(n) { def nesthelper(y) { return n * y; }; return nesthelper(10); };"];
    [[context0 parse] evaluateNode];
    
    SVParserContext* l0 = [SVParserContext parserWithString:@"nest(10);"];
    SVParserContext* l1 = [SVParserContext parserWithString:@"nesthelper(10);"];
    
    id v0 = [[l0 parse] evaluateNode];
    
    assertThat(v0,is(equalTo(N(100))));
    STAssertThrowsSpecificNamed([[l1 parse] evaluateNode], NSException, @"SVUnknownFunctionException", nil);
}

-(void) testStringEval {
    assertThat([@"#{10+5}" evaluateNode],is(equalTo(@"15")));
}

-(void) testStringEval2 {
    PC(@"$wld = 'world';");
    [[context parse] evaluateNode];
    
    assertThat([@"Hello #{wld}!" evaluateNode],is(equalTo(@"Hello world!")));
}

+(int) selectorThatExpectsABlock:(int (^)(int,int))block {
    return block(5,10);
}

-(void) testBridgedFunc {
    PC(@"SVFunctionTests.selectorThatExpectsABlock(@block(->(x,y) { return x*y; },'iii'));");
    
    P(var);
    assertThat(var,is(equalTo(N(50))));
}

-(void) testBridgedFunc2 {
    PC(@"def func(x,y) { return x+y; };  SVFunctionTests.selectorThatExpectsABlock(@block(func,'iii'));");
    
    P(var);
    assertThat(var,is(equalTo(N(15))));
}

-(void) testNestedArrayReturn {
    NSArray* sa1 = [NSArray arrayWithObjects:N(1),N(2),nil];
    NSArray* sa2 = [NSArray arrayWithObjects:N(3),N(4),nil];
    NSArray* sa3 = [NSArray arrayWithObjects:N(5),N(6),nil];
    NSArray* expect = [NSArray arrayWithObjects:sa1,sa2,sa3,nil];
    PC(@"def func(a) { return a; }; func([[1,2],[3,4],[5,6]]);");
    
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testYieldNoArgs {
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    PC(@"def times(a) { b = 0; while(b < a) { yield; b+=1; }; }; z = []; x = 1; times(3) { z << (x+=1); }; z;");
    
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testYieldOneArg {
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    PC(@"def each(a) { for(o in a) { yield o; }; }; z = []; each([1,2,3]) { |x| z << x + 1; }; z;");
    
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testExplicitFunction {
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    PC(@"def each(a,&f) { for(o in a) { f(o); }; }; z = []; each([1,2,3]) { |x| z << x + 1; }; z;");
    
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testExplicitFunction2 {
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    PC(@"def each(a,&f) { for(o in a) { f(o); }; }; z = []; def f(x) { z << x + 1; }; each([1,2,3],f); z;");
    
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testSelectInObjc {
    NSArray* expect = [NSArray arrayWithObjects:N(2), N(3), nil];
    PC(@"def test(x) { return x > 1; };");
    
    P(func);
    NSArray* test = [NSArray arrayWithObjects:N(1),N(2),N(3),nil];
    NSArray* result = [test select:func];
    assertThat(result,is(equalTo(expect)));
}

-(void) testSelectInObjc2 {
    NSArray* expect = [NSArray arrayWithObjects:N(2), N(3), nil];
    NSArray* test = [NSArray arrayWithObjects:N(1),N(2),N(3),nil];
    NSArray* result = [test select:^id(int x) { return N(x > 1); }];
    assertThat(result,is(equalTo(expect)));
}

-(void) testSelectInObjc3 {
    NSArray* test = [NSArray arrayWithObjects:@"Hello",@"Hi",@"Bye",@"Last",@"Help",@"How",@"Cat",nil];
    NSArray* expect = [NSArray arrayWithObjects:@"Hello",@"Hi",@"Help",@"How",nil];
    NSArray* result = [test select:^id(NSString* s) { return N([s characterAtIndex:0] == 'H'); }];
    assertThat(result,is(equalTo(expect)));
}

-(void) testObjCBlock {
    PC(@"def func(block) { return block(10); }; func(x);");
    NSMutableDictionary* _context = [NSMutableDictionary dictionary];
    [_context createSymbolTable];
    SVSymbolTable* symtable = [_context symbolTable];
    SVSymbol* x = [symtable symbolWithName:@"x"];
    x.value = ^id(int y) { return N(y + 20); };
    id result = [[context parse] evaluateWithContext:_context];
    assertThat(result,is(equalTo(N(30))));
}

-(void) testMapNoYieldDoesNotCrash {
    PC(@"a = [1,2,3]; a.map; a;");
    NSArray* expect = [NSArray arrayWithObjects:N(1),N(2),N(3),nil];
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testMapEmptyYieldFunc {
    PC(@"a = [1,2,3]; a.map { nil; }; a;");
    NSArray* expect = [NSArray arrayWithObjects:N(1),N(2),N(3),nil];
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testMapTooManyYieldArgs {
    PC(@"a = [1,2,3]; a.map { |x,y| return x + 2; }; a;");
    NSArray* expect = [NSArray arrayWithObjects:N(1),N(2),N(3),nil];
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testMapFunctionAsArgument {
    PC(@"a = [1, 2, 3]; b = []; a.map(->(x) { b << x + 1; }); b;");
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testMapObjC {
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    NSMutableArray* result = [NSMutableArray array];
    [[NSArray arrayWithObjects:N(1),N(2),N(3),nil] map:^void(int x) { [result addObject:N(x+1)]; }];
    assertThat(result,is(equalTo(expect)));
}

-(void) testDoFunctionCall {
    NSArray* expect = [NSArray arrayWithObjects:N(2),N(3),N(4),nil];
    PC(@"x = [1,2,3]; b = []; def func(z) { for(o in z) { yield o; }; }; func(x) { |y| b << y + 1; }; b;");
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testSimpleHash {
    NSDictionary* expect = [NSDictionary dictionaryWithObject:@"hello" forKey:XS(@"world")];
    PC(@"x = { :world => 'hello' }; x;");
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testHashDoFunction {
    NSString* expect = @"Hello world!";
    PC(@"def func(d) { for(k in d.allKeys) { yield k,d[k]; }; return str; }; str = ''; func(:Hello => 'world!') { |k,v| str << k << ' ' << v; }; str;");
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testStringArray {
    NSArray* expect = [NSArray arrayWithObjects:@"hello",@"world",nil];
    PC(@"%w(hello world);");
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testQuestionFunction {
    PC(@"def isTwo?(num) { return num == 2; }; isTwo?(2);");
    P(var);
    assertThat(var,is(equalTo(BL(YES))));
}

-(void) testSelfAssignOutsideOfClass {
    PC(@"def func(a) { if(a > 5) { self = 3; }; return self; }; func(7);");
    P(var);
    assertThat(var,is(equalTo(N(3))));
}

-(void) testEval {
    PC(@"x = 3; n = 'x + 4;'; eval(n);");
    P(var);
    assertThat(var,is(equalTo(N(7))));
}

-(void) testEval2 {
    PC(@"n = 'x = 3;'; eval(n); x + 4;");
    P(var);
    assertThat(var,is(equalTo(N(7))));
}

-(void) testEval3 {
    PC(@"n = '@x = 4;'; class EvalTest { def test { eval(n); }; }; y = EvalTest.alloc.init; y.test; y.x;");
    P(var);
    assertThat(var,is(equalTo(N(4))));
}

-(void) testSet {
    PC(@"def x(y,v) { if(y) { set z = v; }; z; }; a = x(1,2); a;");
    P(var);
    assertThat(var,is(equalTo(N(2))));
}

-(void) testVariadic {
    PC(@"NSString.stringWithFormat('%@ %@','hello','world');");
    P(var);
    assertThat(var,is(equalTo(@"hello world")));
}

-(void) testVariadic2 {
    NSArray* expect = [NSArray arrayWithObjects:@"hello",@"world",nil];
    PC(@"NSArray.arrayWithObjects('hello','world',nil);");
    P(var);
    assertThat(var,is(equalTo(expect)));
}

-(void) testEmptyVariadic {
    PC(@"NSString.stringWithFormat('hello');");
    P(var);
    assertThat(var,is(equalTo(@"hello")));
}

-(void) testFalseVariadic {
    PC(@"NSString.stringWithString('hello','world');");
    P(var);
    assertThat(var,is(equalTo(@"hello")));
}

-(void) testAlias {
    PC(@"def osize(s) { return s; }; alias osize size; size 25;");
    P(var);
    assertThat(var,is(equalTo(N(25))));
}

-(void) testAlias2 {
    PC(@"$osize=25; alias $osize $size; $size;");
    P(var);
    assertThat(var,is(equalTo(N(25))));
}

-(void) testCallFunctionUsingSymbol {
    PC(@"def symbolfunc(x) { return x*22; }; :symbolfunc(2);");
    P(var);
    assertThat(var,is(equalTo(N(44))));
}

-(void) testAtSelector {
    PC(@"@selector(load:);");
    P(var);
    assertThat(var,is(equalTo(NSStringFromSelector(@selector(load:)))));
}

-(void) testForwardPipe {
    PC(@"def fpipetest(x) { return x + 1; }; 2 |> fpipetest;");
    P(var);
    assertThat(var,is(equalTo(N(3))));
}

-(void) testBackwardPipe {
    PC(@"def bpipetest(x) { return x + 1; }; bpipetest <| 2;");
    P(var);
    assertThat(var,is(equalTo(N(3))));
}

-(void) testForwardPipeSimpleNest {
    PC(@"def xfpipetest(x) { return x + 1; }; 2 |> xfpipetest |> xfpipetest;");
    P(var);
    assertThat(var,is(equalTo(N(4))));
}

-(void) testBackwardPipeSimpleNest {
    PC(@"def xbpipetest(x) { return x + 1; }; xbpipetest <| xbpipetest <| 2;");
    P(var);
    assertThat(var,is(equalTo(N(4))));
}

-(void) testForwardBackwardPipeNest {
    PC(@"def yfpipetest(x) { return x + 1; }; def ybpipetest(x) { return x + 1; }; ybpipetest <| 2 |> yfpipetest;");
    P(var);
    assertThat(var,is(equalTo(N(4))));
}

-(void) testForeachDefined {
    PC(@"def foreach(__d,&body) {" 
        "   var = __d::[0];" 
        "   arr = __d[var];"
        "   for(i = 0; i < arr.count; i+=1) {" 
        "       eval('#{var} = arr[i]; body();');" 
        "   };" 
        "};"
        "$s = 0;"
        "foreach :x => [1,2,3] do { s += x; };" 
        "s;"
    );
    P(var);
    
    assertThat(var,is(equalTo(N(6))));
}

-(void) testPartialFunctionCall {
    PC(@"def add(x,y) { return x + y; }; add1 = add(1); [add1(1),add1(2),add1(3)];");
    P(var);
    
    assertThat(var,is(equalTo([NSArray arrayWithObjects:N(2),N(3),N(4),nil])));
}

-(void) testPartialFunctionCallForward {
    PC(@"def add(x,y) { return x + y; }; add1 = add(1); [1 |> add1,2 |> add1,3 |> add1];");
    P(var);
    
    assertThat(var,is(equalTo([NSArray arrayWithObjects:N(2),N(3),N(4),nil])));
}

-(void) testPartialFunctionCallBackward {
    PC(@"def div(x,y) { return y / x; }; div20 = div(20); [div20 <| 2,div20 <| 5,div20 <| 10];");
    P(var);
    
    assertThat(var,is(equalTo([NSArray arrayWithObjects:N(10),N(4),N(2),nil])));
}

-(void) testAttachCommentFunction {
    PC(@"//* @desc:[This function returns a multiple of 10.] @arg(x):[This argument specifies which multiple to return.] */ def mul10(x) { return x*10; };");
    SVBlock* node = [context parse];
    SVFunction* func = [node.statements objectAtIndex:0];
    assertThat(func.comments,is(equalTo(@" @desc:[This function returns a multiple of 10.] @arg(x):[This argument specifies which multiple to return.] ")));
}

-(void) testSdocQuickTest {
    PC(@"class SDocNode { def init { @desc = ''; @args = {}; self; }; };"
       "def sdoc(node) { n = SDocNode.alloc.init; n.instance_eval(node); n; };"
       "code = <<-CODE @desc='This function returns a multiple of 10.'; @args['x']='This argument specifies which multiple to return.'; CODE;"
       "n = sdoc(code);"
       "[n.desc,n.args];"
       );
    
    P(var);
    assertThat(var,is(equalTo([NSArray arrayWithObjects:@"This function returns a multiple of 10.",[NSDictionary dictionaryWithObjectsAndKeys:@"This argument specifies which multiple to return.",@"x",nil],nil])));
}

-(void) testSdocQuickTest2 {
    PC(@"//* @desc:[Test method] @arg(x):[Test argument] */ def test(x) { x + 10; };");
    
    SVFunction* func = [[[context parse] statements] objectAtIndex:0];
    assertThat(func.comments,is(equalTo(@" @desc:[Test method] @arg(x):[Test argument] ")));
    assertThat(func.name,is(equalTo(@"test")));
    assertThat(func.arguments,is(equalTo([NSArray arrayWithObjects:[SVFunctionArgument argumentWithName:@"x"],nil])));
}

-(void) testDynamicScope {
    PC(@"def add() { x + 5; }; x = 5; y = add(); x = 10; z = add(); [y,z];");
    P(var);
    assertThat(var,is(equalTo([NSArray arrayWithObjects:N(10),N(15),nil])));
}
@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.