Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: Mocha
Fetching contributors…

Cannot retrieve contributors at this time

file 76 lines (50 sloc) 1.931 kb
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
var count = 1;
var tests = new Array();

var process = function (a, b) {
    
    //print("running test " + count);
    
    a = [JSTPreprocessor preprocessCode:a];
    
    if (a != b) {
        NSBeep();
        print("Failure for test " + count);
        print(a + "\nshould be equal to:\n" + b);
        return false;
    }
    
    print("Success for test " + count);
    
    count++;
    
    return true;
}

var addTest = function (a, b) {
    tests.push(new Array(a, b));
}

print("Staring preprocessing tests.")

addTest('print([4 - 5, b]);',
        'print([4 - 5, b]);');

addTest('print([a, b]);',
        'print([a,b]);');
        
addTest('[db executeUpdate:"insert into foo values (?, ?, ?)",\n 1, // comment!\n @"Hello",\n [NSDate date]];',
        'db.executeUpdate_("insert into foo values (?, ?, ?)",1,NSString.stringWithString_("Hello"),NSDate.date());');

addTest('[db executeUpdate:"insert into foo values (?, ?)", 1, "Hello"];',
        'db.executeUpdate_("insert into foo values (?, ?)",1,"Hello");');

addTest('var acorn = [JSTalk application:"Acorn"];',
        'var acorn = JSTalk.application_("Acorn");');

addTest('print([]);',
        'print([]);');

addTest('[fo doSomething:" a " + [b fun] + " c " in:nil];',
        'fo.doSomething_in_(" a " + b.fun() + " c ", nil);');

addTest('print([NSString stringWithString:@"a"+"b"])',
        'print(NSString.stringWithString_(NSString.stringWithString_("a")+"b"))');

addTest('[NSFullUserName() lowercaseString];',
        'NSFullUserName().lowercaseString();');



var stopOnFirstFail = false;
var shouldContinue = true;
var len = tests.length;
var idx = 0;
while (shouldContinue && idx < len) {
    var a = tests[idx][0];
    var b = tests[idx][1];
    
    shouldContinue = process(a, b);
    
    shouldContinue = stopOnFirstFail ? shouldContinue : true;
    
    idx++;
}

print("Done");

// what about "foo ? bar : xyz" ? Yea, gotta fix that.
Something went wrong with that request. Please try again.