Revision: 3695 http://vexi.svn.sourceforge.net/vexi/?rev=3695&view=rev Author: mkpg2 Date: 2009-09-28 13:46:09 +0000 (Mon, 28 Sep 2009)
Log Message: ----------- Fix. Array.slice. Modified Paths: -------------- trunk/core/org.ibex.js/src/org/ibex/js/JSArray.jpp trunk/core/org.ibex.js/src_junit/test/js/exec/array/TestArray.java Added Paths: ----------- trunk/core/org.ibex.js/src_junit/test/js/exec/array/copy.js trunk/core/org.ibex.js/src_junit/test/js/exec/array/slice.js trunk/core/org.ibex.js/src_junit/test/js/exec/array/sort.js trunk/core/org.ibex.js/src_junit/test/js/exec/array/splice.js Removed Paths: ------------- trunk/core/org.ibex.js/src_junit/test/js/exec/array/testcopy.js trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsort.js trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsplice.js Modified: trunk/core/org.ibex.js/src/org/ibex/js/JSArray.jpp =================================================================== --- trunk/core/org.ibex.js/src/org/ibex/js/JSArray.jpp 2009-09-28 13:31:51 UTC (rev 3694) +++ trunk/core/org.ibex.js/src/org/ibex/js/JSArray.jpp 2009-09-28 13:46:09 UTC (rev 3695) @@ -284,9 +284,9 @@ if (end < 0) end = 0; if (start > length) start = length; if (end > length) end = length; - JSArray ret = new JSArray(end-start); - System.arraycopy(o, start, ret, 0, end-start); - return ret; + JS[] r = new JS[end-start]; + System.arraycopy(o, start, r, 0, end-start); + return new JSArray(r); } /** remove and return the portion of an array between the specified indice */ Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/array/TestArray.java =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/TestArray.java 2009-09-28 13:31:51 UTC (rev 3694) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/TestArray.java 2009-09-28 13:46:09 UTC (rev 3695) @@ -14,7 +14,7 @@ public static void main(String[] args) throws Throwable { JSTestSuite jts = new JSTestSuite(TestArray.class); - TestCase t = jts.createTestCase(jts.getResourceDirs(), "concat.js"); + TestCase t = jts.createTestCase(jts.getResourceDirs(), "slice.js"); t.runBare(); } } Copied: trunk/core/org.ibex.js/src_junit/test/js/exec/array/copy.js (from rev 3692, trunk/core/org.ibex.js/src_junit/test/js/exec/array/testcopy.js) =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/copy.js (rev 0) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/copy.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -0,0 +1,9 @@ + +var x = ["a","b","c","x","y","z"]; +var y = x.copy(); +sys.log.info(x.join(",")); +sys.log.info(y.join(",")); +sys.log.info(y.length); +assert(x.length==6); +assert(y.length==6); +assert(y.join()==x.join()); Added: trunk/core/org.ibex.js/src_junit/test/js/exec/array/slice.js =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/slice.js (rev 0) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/slice.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -0,0 +1,5 @@ + +var x = ["a","b","c","x","y","z"]; +var y = x.slice(2,4); +assert(y.length==2); +assert(y.join(",")=="c,x"); Copied: trunk/core/org.ibex.js/src_junit/test/js/exec/array/sort.js (from rev 3692, trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsort.js) =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/sort.js (rev 0) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/sort.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -0,0 +1,53 @@ +sys.import("shared"); + +var assertEqual = function(a,b){ + var stra = a.join(); + var strb = b.join(); + if(stra!=strb){ + sys.log.info("Arrays unequal"); + sys.log.info(stra); + sys.log.info(strb); + } + assert(stra==strb); +}; + +var comp = function(a,b){ + return a.compareTo(b); +}; + +var assertSort = function(expected, a){ + var x = a.copy().sort(); + assertEqual(expected,x); + var y = a.copy().sort(comp); + assertEqual(expected,y); +}; + +var a = []; +assertSort([],a); + +var b = ["m"]; +assertSort(["m"],b); + +var c = ["m","i"]; +assertSort(["i","m"],c); + +assertSort( + strToArray("acehilm"), + strToArray("michael")); + +assertSort( + strToArray(".abcdeeefghhijklmnoooopqrrsttuuvwxyz"), + strToArray("thequickbrownfoxjumpsoverthelazydog.")); + + + +/* +var x = ["m","i","c","h","a","e","l"]; +var y = x.copy(); +sys.log.info(x.join(",")); +sys.log.info(y.join(",")); +sys.log.info(y.length); +assert(x.length==6); +assert(y.length==6); +assert(y.join()==x.join()); +*/ \ No newline at end of file Copied: trunk/core/org.ibex.js/src_junit/test/js/exec/array/splice.js (from rev 3692, trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsplice.js) =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/splice.js (rev 0) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/splice.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -0,0 +1,11 @@ + +var x = ["a","b","c","x","y","z"]; +var y = x.splice(2,2); +assert(x.length==4); +assert(y.length==2); +assert(x.join(",")=="a,b,y,z"); +assert(y.join(",")=="c,x"); +var z = x.splice(2,0,"m","n"); +assert(z.length==0); +assert(x.length==6); +assert(x.join(","),"a,b,m,n,y,z"); Deleted: trunk/core/org.ibex.js/src_junit/test/js/exec/array/testcopy.js =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/testcopy.js 2009-09-28 13:31:51 UTC (rev 3694) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/testcopy.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -1,9 +0,0 @@ - -var x = ["a","b","c","x","y","z"]; -var y = x.copy(); -sys.log.info(x.join(",")); -sys.log.info(y.join(",")); -sys.log.info(y.length); -assert(x.length==6); -assert(y.length==6); -assert(y.join()==x.join()); Deleted: trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsort.js =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsort.js 2009-09-28 13:31:51 UTC (rev 3694) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsort.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -1,53 +0,0 @@ -sys.import("shared"); - -var assertEqual = function(a,b){ - var stra = a.join(); - var strb = b.join(); - if(stra!=strb){ - sys.log.info("Arrays unequal"); - sys.log.info(stra); - sys.log.info(strb); - } - assert(stra==strb); -}; - -var comp = function(a,b){ - return a.compareTo(b); -}; - -var assertSort = function(expected, a){ - var x = a.copy().sort(); - assertEqual(expected,x); - var y = a.copy().sort(comp); - assertEqual(expected,y); -}; - -var a = []; -assertSort([],a); - -var b = ["m"]; -assertSort(["m"],b); - -var c = ["m","i"]; -assertSort(["i","m"],c); - -assertSort( - strToArray("acehilm"), - strToArray("michael")); - -assertSort( - strToArray(".abcdeeefghhijklmnoooopqrrsttuuvwxyz"), - strToArray("thequickbrownfoxjumpsoverthelazydog.")); - - - -/* -var x = ["m","i","c","h","a","e","l"]; -var y = x.copy(); -sys.log.info(x.join(",")); -sys.log.info(y.join(",")); -sys.log.info(y.length); -assert(x.length==6); -assert(y.length==6); -assert(y.join()==x.join()); -*/ \ No newline at end of file Deleted: trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsplice.js =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsplice.js 2009-09-28 13:31:51 UTC (rev 3694) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/array/testsplice.js 2009-09-28 13:46:09 UTC (rev 3695) @@ -1,11 +0,0 @@ - -var x = ["a","b","c","x","y","z"]; -var y = x.splice(2,2); -assert(x.length==4); -assert(y.length==2); -assert(x.join(",")=="a,b,y,z"); -assert(y.join(",")=="c,x"); -var z = x.splice(2,0,"m","n"); -assert(z.length==0); -assert(x.length==6); -assert(x.join(","),"a,b,m,n,y,z"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn