|
3 | 3 | <head>
|
4 | 4 | <title>php.js test suite</title>
|
5 | 5 | <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> |
12 | 11 | <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 | +} |
13 | 21 |
|
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 | +}; |
15 | 31 |
|
16 |
| -<script src="tests/tests.js"></script> |
| 32 | +fNOP. = this.; |
| 33 | +fBound. = new fNOP(); |
17 | 34 |
|
18 |
| -<style> |
19 |
| -body { |
20 |
| -font-family: Arial, Sans-Serif; |
21 |
| -font-size:11px; |
| 35 | +return fBound; |
| 36 | +}; |
22 | 37 | }
|
23 | 38 |
|
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 | +}; |
25 | 49 |
|
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 | +} |
31 | 60 |
|
32 |
| -li { |
33 |
| -white-space: pre; |
34 |
| -} |
| 61 | +opts.filesystem = new PHP.Adapters.XHRFileSystem(); |
35 | 62 |
|
36 |
| -</style> |
| 63 | +return opts; |
| 64 | +} |
37 | 65 |
|
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(); |
41 | 77 |
|
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 | +} |
43 | 97 | </script>
|
44 | 98 | </head>
|
45 | 99 | <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> |
47 | 111 | <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(); |
73 | 113 | </script>
|
74 | 114 | </body>
|
75 | 115 | </html>
|
0 commit comments