Skip to content

Commit a4a9dcc

Browse files
committed
Test suite completes (But many many tests fail)
1 parent 27bb33e commit a4a9dcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+390
-381
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ setup:
66

77
test:
88
cd tests && npm install
9-
find functions -type f |grep -v '/_' |awk -F/ '{print $$NF}' |sed 's@\.js$$@@g' |xargs node tests/cli.js -f
9+
find functions -type f |grep -v '/_' |sed 's@\.js$$@@g' |awk -F/ '{print "node tests/cli.js -f "$$NF}' |bash
1010

1111
site:
1212
git pull && \
File renamed without changes.

experimental/filesystem/dirname.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

experimental/filesystem/pathinfo.js

Lines changed: 0 additions & 134 deletions
This file was deleted.

experimental/filesystem/realpath.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
function realpath (path) {
2-
// http://kevin.vanzonneveld.net
2+
// From: http://phpjs.org/functions
33
// + original by: mk.keck
44
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
55
// % note 1: Returned path is an url like e.g. 'http://yourhost.tld/path/'
66
// * example 1: realpath('../.././_supporters/pj_test_supportfile_1.htm');
77
// * returns 1: 'file:/home/kevin/workspace/_supporters/pj_test_supportfile_1.htm'
8-
var p = 0,
9-
arr = []; /* Save the root, if not given */
8+
9+
var p = 0;
10+
var arr = []; /* Save the root, if not given */
1011
var r = this.window.location.href; /* Avoid input failures */
1112
path = (path + '').replace('\\', '/'); /* Check if there's a port in path (like 'http://') */
1213
if (path.indexOf('://') !== -1) {
@@ -22,20 +23,21 @@ function realpath (path) {
2223
continue;
2324
} /* This reduces the realpath */
2425
if (arr[k] == '..') {
25-
/* But only if there more than 3 parts in the path-array.
26+
/* But only if there more than 3 parts in the path-array.
2627
* The first three parts are for the uri */
2728
if (path.length > 3) {
2829
path.pop();
2930
}
3031
} /* This adds parts to the realpath */
3132
else {
32-
/* But only if the part is not empty or the uri
33+
/* But only if the part is not empty or the uri
3334
* (the first three parts ar needed) was not
3435
* saved */
3536
if ((path.length < 2) || (arr[k] !== '')) {
3637
path.push(arr[k]);
3738
}
3839
}
39-
} /* Returns the absloute path as a string */
40+
} /* Returns the absolute path as a string */
41+
4042
return path.join('/');
4143
}

functions/funchand/register_shutdown_function.js renamed to experimental/funchand/register_shutdown_function.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ function register_shutdown_function (cb) {
33
// + original by: Brett Zamir (http://brett-zamir.me)
44
// * example 1: register_shutdown_function(function(first, middle, last) {alert('Goodbye '+first+' '+middle+' '+last+'!');}, 'Kevin', 'van', 'Zonneveld');
55
// * returns 1: 'Goodbye Kevin van Zonneveld!'
6+
67
var args = [],
78
_addEvent = function (el, type, handler, capturing) {
89
if (el.addEventListener) { /* W3C */

functions/info/assert.js renamed to experimental/info/assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function assert (assertion) {
22
// From: http://phpjs.org/functions
33
// + original by: Brett Zamir (http://brett-zamir.me)
4-
// % note 1: Do not pass untrusted user input to assert() in string form (you can test it beforehand though)
5-
// % note 2: Does not provide perfect arguments to the assertion callback, as far as file location or line number
4+
// % note 1: Do not pass untrusted user input to assert() in string form (you can test it beforehand though)
5+
// % note 2: Does not provide perfect arguments to the assertion callback, as far as file location or line number
66
// * example 1: assert('false === true');
77
// * returns 1: false
88

experimental/info/get_defined_constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function get_defined_constants (categorize) {
2+
// From: http://phpjs.org/functions
23
// + original by: Brett Zamir (http://brett-zamir.me)
34
// % note 1: Could possibly substitute some others like M_PI with JavaScript's Math.PI, etc., but here
45
// % note 1: sticking to PHP, except for changing: NULL to null, NAN to NaN, and INF to Number.POSITIVE_INFINITY

experimental/array/array.js renamed to functions/array/array.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ function array () {
22
// From: http://phpjs.org/functions
33
// + original by: d3x
44
// + improved by: Brett Zamir (http://brett-zamir.me)
5+
// * test: skip
56
// * example 1: array('Kevin', 'van', 'Zonneveld');
67
// * returns 1: ['Kevin', 'van', 'Zonneveld']
78
// * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
8-
// * example 2: var arr = array({0:2}, {a:41}, {2:3}).change_key_case('CASE_UPPER').keys();
9+
// * example 2: array({0:2}, {a:41}, {2:3}).change_key_case('CASE_UPPER').keys();
910
// * returns 2: [0,'A',2]
1011

12+
try {
13+
this.php_js = this.php_js || {};
14+
} catch (e) {
15+
this.php_js = {};
16+
}
17+
1118
var arrInst, e, __, that = this, PHPJS_Array = function PHPJS_Array() {},
12-
mainArgs = arguments, p = this.php_js = this.php_js || {},
19+
mainArgs = arguments, p = this.php_js,
1320
_indexOf = function (value, from, strict) {
1421
var i = from || 0, nonstrict = !strict, length = this.length;
1522
while (i < length) {

functions/array/array_change_key_case.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function array_change_key_case (array, cs) {
1616
// * example 6: array_change_key_case({ FuBaR: 42 }, 2);
1717
// * returns 6: {"FUBAR": 42}
1818
// * example 7: ini_set('phpjs.return_phpjs_arrays', 'on');
19-
// * example 7: var arr = array({a: 0}, {B: 1}, {c: 2});
19+
// * example 7: var arr = [{a: 0}, {B: 1}, {c: 2}];
2020
// * example 7: var newArr = array_change_key_case(arr);
21-
// * example 7: newArr.b
22-
// * returns 7: 1
21+
// * example 7: newArr.splice(1);
22+
// * returns 7: {b: 1}
2323

2424
var case_fn, key, tmp_ar = {};
2525

functions/array/array_filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function array_filter (arr, func) {
1010
// * example 2: var even = function (num) {return (!(num & 1));}
1111
// * example 2: array_filter([6, 7, 8, 9, 10, 11, 12], even);
1212
// * returns 2: {0: 6, 2: 8, 4: 10, 6: 12}
13-
// * example 3: var arr = array_filter({"a": 1, "b": false, "c": -1, "d": 0, "e": null, "f":'', "g":undefined});
13+
// * example 3: array_filter({"a": 1, "b": false, "c": -1, "d": 0, "e": null, "f":'', "g":undefined});
1414
// * returns 3: {"a":1, "c":-1};
1515

1616
var retObj = {},

functions/array/array_flip.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
function array_flip (trans) {
22
// From: http://phpjs.org/functions
33
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
4-
// + improved by: Pier Paolo Ramon (http://www.mastersoup.com/)
5-
// + improved by: Brett Zamir (http://brett-zamir.me)
4+
// + improved by: Pier Paolo Ramon (http://www.mastersoup.com/)
5+
// + improved by: Brett Zamir (http://brett-zamir.me)
6+
// - depends on: array
7+
// * test: skip
68
// * example 1: array_flip( {a: 1, b: 1, c: 2} );
79
// * returns 1: {1: 'b', 2: 'c'}
810
// * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
@@ -11,12 +13,15 @@ function array_flip (trans) {
1113

1214
var key, tmp_ar = {};
1315

14-
if (trans && typeof trans=== 'object' && trans.change_key_case) { // Duck-type check for our own array()-created PHPJS_Array
16+
// Duck-type check for our own array()-created PHPJS_Array
17+
if (trans && typeof trans === 'object' && trans.change_key_case) {
1518
return trans.flip();
1619
}
1720

1821
for (key in trans) {
19-
if (!trans.hasOwnProperty(key)) {continue;}
22+
if (!trans.hasOwnProperty(key)) {
23+
continue;
24+
}
2025
tmp_ar[trans[key]] = key;
2126
}
2227

functions/array/array_search.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function array_search (needle, haystack, argStrict) {
33
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
44
// + input by: Brett Zamir (http://brett-zamir.me)
55
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
6+
// - depends on: array
7+
// * test: skip
68
// * example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
79
// * returns 1: 'surname'
810
// * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');

functions/array/array_walk.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ function array_walk (array, funcname, userdata) {
33
// + original by: Johnny Mast (http://www.phpvrouwen.nl)
44
// + bugfixed by: David
55
// + improved by: Brett Zamir (http://brett-zamir.me)
6-
// % note 1: Using ini_set('phpjs.no-eval', true) will only work with
7-
// % note 1: user-defined string functions, not built-in functions like void()
6+
// - depends on: array
7+
// % note 1: Using ini_set('phpjs.no-eval', true) will only work with
8+
// % note 1: user-defined string functions, not built-in functions like void()
9+
// * test: skip
810
// * example 1: array_walk ({'a':'b'}, 'void', 'userdata');
911
// * returns 1: true
1012
// * example 2: array_walk ('a', 'void', 'userdata');
@@ -16,7 +18,7 @@ function array_walk (array, funcname, userdata) {
1618
// * example 5: ini_set('phpjs.return_phpjs_arrays', 'on');
1719
// * example 5: var arr = array({40: 'My age'}, {50: 'My IQ'});
1820
// * example 5: array_walk(arr, [window, 'prompt']);
19-
// * returns 5: [object Object]
21+
// * returns 5: '[object Object]'
2022
var key, value, ini;
2123

2224
if (!array || typeof array !== 'object') {

functions/array/end.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function end (arr) {
3333
var arrpos = pointers.indexOf(arr);
3434
if (Object.prototype.toString.call(arr) !== '[object Array]') {
3535
var ct = 0;
36+
var val;
3637
for (var k in arr) {
3738
ct++;
38-
var val = arr[k];
39+
val = arr[k];
3940
}
4041
if (ct === 0) {
4142
return false; // Empty

functions/array/natcasesort.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function natcasesort (inputArr) {
1818
// * example 1: $array1 = {a:'IMG0.png', b:'img12.png', c:'img10.png', d:'img2.png', e:'img1.png', f:'IMG3.png'};
1919
// * example 1: $array1 = natcasesort($array1);
2020
// * returns 1: {a: 'IMG0.png', e: 'img1.png', d: 'img2.png', f: 'IMG3.png', c: 'img10.png', b: 'img12.png'}
21+
2122
var valArr = [],
2223
k, i, ret, that = this,
2324
strictForIn = false,

functions/array/shuffle.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ function shuffle (inputArr) {
1414
// % note 1: behavior by default if IE ever does allow it; only gives shallow copy since
1515
// % note 1: is by reference in PHP anyways
1616
// * example 1: ini_set('phpjs.strictForIn', true);
17-
// * example 1: shuffle({5:'a', 2:'3', 3:'c', 4:5, 'q':5});
17+
// * example 2: var data = {5:'a', 2:'3', 3:'c', 4:5, 'q':5};
18+
// * example 1: shuffle(data);
19+
// * example 1: data;
1820
// * returns 1: {5:'a', 4:5, 'q':5, 3:'c', 2:'3'}
1921
// * example 2: ini_set('phpjs.strictForIn', true);
2022
// * example 2: var data = {5:'a', 2:'3', 3:'c', 4:5, 'q':5};
2123
// * example 2: shuffle(data);
22-
// * results 2: {5:'a', 'q':5, 3:'c', 2:'3', 4:5}
23-
// * returns 2: true
24+
// * example 2: data;
25+
// * returns 2: {5:'a', 'q':5, 3:'c', 2:'3', 4:5}
2426
var valArr = [],
2527
k = '',
2628
i = 0,

functions/array/uasort.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ function uasort (inputArr, sorter) {
1414
// % note 1: is by reference in PHP anyways
1515
// * example 1: fruits = {d: 'lemon', a: 'orange', b: 'banana', c: 'apple'};
1616
// * example 1: fruits = uasort(fruits, function (a, b) { if (a > b) {return 1;}if (a < b) {return -1;} return 0;});
17-
// * results 1: fruits == {c: 'apple', b: 'banana', d: 'lemon', a: 'orange'}
17+
// * example 1: fruits;
18+
// * returns 1: {c: 'apple', b: 'banana', d: 'lemon', a: 'orange'}
19+
1820
var valArr = [],
1921
tempKeyVal, tempValue, ret, k = '',
2022
i = 0,

functions/array/usort.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function usort (inputArr, sorter) {
1313
// % note 1: is by reference in PHP anyways
1414
// * example 1: stuff = {d: '3', a: '1', b: '11', c: '4'};
1515
// * example 1: stuff = usort(stuff, function (a, b) {return(a-b);});
16-
// * results 1: stuff = {0: '1', 1: '3', 2: '4', 3: '11'};
16+
// * example 1: stuff;
17+
// * returns 1: {0: '1', 1: '3', 2: '4', 3: '11'};
1718
var valArr = [],
1819
k = '',
1920
i = 0,

0 commit comments

Comments
 (0)