File tree

10 files changed

+166
-924
lines changed

10 files changed

+166
-924
lines changed
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,28 @@ module.exports = function(grunt) {
167167
src: '<%= concat.dist.dest %>',
168168
dest: 'dist/php.min.js'
169169
}
170+
},
171+
express: {
172+
test: {
173+
options: {
174+
script: __dirname + "/tests/test_server.js"
175+
}
176+
}
177+
},
178+
mocha: {
179+
desc: [__dirname + '/tests/results'],
180+
options: {
181+
run: false,
182+
urls: ['http://localhost:3000/index.html'],
183+
timeout: 10000
184+
}
170185
}
171186
});
172187

173188
grunt.loadNpmTasks('grunt-contrib-uglify');
174189
grunt.loadNpmTasks('grunt-contrib-concat');
190+
grunt.loadNpmTasks('grunt-express-server');
191+
grunt.loadNpmTasks('grunt-mocha');
175192

176-
grunt.registerTask('default', ['concat', 'uglify']);
193+
grunt.registerTask('default', ['concat', 'uglify', 'express', 'mocha']);
177194
};
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@
2929
"test": "grunt test"
3030
},
3131
"devDependencies": {
32+
"expect.js": "^0.3.1",
33+
"express": "^4.8.5",
3234
"grunt": "^0.4.5",
3335
"grunt-cli": "^0.1.13",
3436
"grunt-contrib-concat": "^0.5.0",
35-
"grunt-contrib-uglify": "^0.5.1"
37+
"grunt-contrib-uglify": "^0.5.1",
38+
"grunt-express-server": "^0.4.19",
39+
"grunt-mocha": "^0.4.11",
40+
"mocha": "^1.21.4"
3641
},
3742
"keywords": []
3843
}
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,113 @@
33
<head>
44
<title>php.js test suite</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6-
<script>
7-
var exports = {};
8-
</script>
9-
10-
<script src="src/include.js"></script>
11-
6+
<link rel="stylesheet" href="/mocha/mocha.css" />
7+
<script src="/expect/index.js"></script>
8+
<script src="/mocha/mocha.js"></script>
9+
<script>mocha.setup('bdd')</script>
10+
<script src="/dist/php.js"></script>
1211
<script src="adapters/filesystem/xhr.js"></script>
12+
<script>
13+
// phantomjs is using old version of jsc, doesn't have bind
14+
if (!Function..bind) {
15+
Function..bind = function (oThis) {
16+
if (typeof this !== "function") {
17+
// closest thing possible to the ECMAScript 5
18+
// internal IsCallable function
19+
throw new TypeError("Function..bind - what is trying to be bound is not callable");
20+
}
1321

14-
<script src="src/lib/diff_match_.js"></script>
22+
var aArgs = Array..slice.call(arguments, 1),
23+
fToBind = this,
24+
fNOP = function () {},
25+
fBound = function () {
26+
return fToBind.apply(this instanceof fNOP && oThis
27+
? this
28+
: oThis,
29+
aArgs.concat(Array..slice.call(arguments)));
30+
};
1531

16-
<script src="tests/tests.js"></script>
32+
fNOP. = this.;
33+
fBound. = new fNOP();
1734

18-
<style>
19-
body {
20-
font-family: Arial, Sans-Serif;
21-
font-size:11px;
35+
return fBound;
36+
};
2237
}
2338

24-
ins {
39+
function initOptions(test) {
40+
var opts = {
41+
POST: test.POST,
42+
RAW_POST: test.POST_RAW,
43+
GET: test.GET,
44+
ini: (test.INI !== undefined ) ? PHP.ini(test.INI) : {},
45+
SERVER: {
46+
SCRIPT_FILENAME: test.path.substring(0, test.path.length - 1)
47+
}
48+
};
2549

26-
background:#E6FFE6;
27-
}
28-
del {
29-
background:#FFE6E6;
30-
}
50+
if (test.ARGS !== undefined ) {
51+
var args = test.ARGS.trim().split(/\s/);
52+
args.unshift( path );
53+
opts.SERVER.argc = args.length;
54+
opts.SERVER.argv = args;
55+
} else if (test.GET !== undefined) {
56+
var args = test.GET.replace(/\+/g," ").trim().split(/\s/);
57+
opts.SERVER.argc = args.length;
58+
opts.SERVER.argv = args;
59+
}
3160

32-
li {
33-
white-space: pre;
34-
}
61+
opts.filesystem = new PHP.Adapters.XHRFileSystem();
3562

36-
</style>
63+
return opts;
64+
}
3765

38-
<script>
39-
40-
66+
function buildTests(suite, tests) {
67+
describe(suite, function() {
68+
tests.forEach(function(test) {
69+
it(test.TEST, function() {
70+
var engine = new PHP(test.FILE || test.FILEEOF, initOptions(test));
71+
var expected = ((test.EXPECT === undefined) ? ((test.EXPECTF === undefined ) ? test.EXPECTREGEX : test.EXPECTF) : test.EXPECT)
72+
.trim()
73+
.replace(/\%unicode\|string\%/g, "string")
74+
.replace(/\%string\|unicode\%/g, "string")
75+
.replace(/\%u\|b\%/g, "");
76+
var output = engine.vm.OUTPUT_BUFFER.replace(/\n/g, "\r\n").trim();
4177

42-
78+
if (test.EXPECTREGEX !== undefined) {
79+
expect(output).to.match(new RegExp("^" + expected + "$", "i"));
80+
} else if (test.EXPECT === undefined ) {
81+
var shouldBef = expected.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
82+
.replace(/\%d/g,"\\d+")
83+
.replace(/\%i/g,"(\\+|\\-)?\\d+")
84+
.replace(/\%s/g,".+")
85+
.replace(/\%c/g,".")
86+
.replace(/\%S/g,".*?")
87+
.replace(/\%x/g,"[0-9a-fA-F]+")
88+
.replace(/\%f/g,"[-+]?[0-9]*\\.?[0-9]*");
89+
expect(output).to.match(new RegExp("^" + shouldBef + "$", "i"));
90+
} else {
91+
expect(output).to.be(expected);
92+
}
93+
});
94+
})
95+
});
96+
}
4397
</script>
4498
</head>
4599
<body>
46-
<div id="tests"></div>
100+
<div id="mocha"></div>
101+
102+
<script src="/tests/ext/tokenizer"></script>
103+
<script src="/tests/basic"></script>
104+
<script src="/tests/func"></script>
105+
<script src="/tests/lang"></script>
106+
<script src="/tests/classes"></script>
107+
<script src="/tests/strings"></script>
108+
<script src="/tests/run-test"></script>
109+
<script src="/tests/output"></script>
110+
<script src="/phantomjs/bridge.js" type="text/javascript" charset="utf-8"></script>
47111
<script>
48-
49-
var tests = ["ext/tokenizer","basic","func","lang","classes","strings","run-test","output"];
50-
51-
52-
var el = document.getElementById("tests");
53-
tests.forEach(function( file ){
54-
var a = document.createElement("a");
55-
a.href = "?pack=" + file;
56-
a.innerHTML = file;
57-
el.appendChild( a );
58-
el.appendChild( document.createElement("br") );
59-
});
60-
61-
if (window.location.search.indexOf("?pack=") !== -1 ) {
62-
new PHP_Tests( window.location.search.split("?pack=")[1], document.getElementById("tests") );
63-
}
64-
65-
// new PHP_Tests( "ext/tokenizer", document.getElementById("tests") );
66-
// new PHP_Tests( "basic", document.getElementById("tests") );
67-
// new PHP_Tests( "func", document.getElementById("tests") );
68-
// new PHP_Tests( "lang", document.getElementById("tests") );
69-
// new PHP_Tests( "classes", document.getElementById("tests") );
70-
// new PHP_Tests( "strings", document.getElementById("tests") );
71-
// new PHP_Tests( "output", document.getElementById("tests") );
72-
112+
mocha.run();
73113
</script>
74114
</body>
75115
</html>
This file was deleted.

0 commit comments

Comments
 (0)