package tests; class tclass_base { var value; function tclass_base(v) { value = v; } function toString() { return string(value); } } class tclass: tclass_base { function tclass(v) { tclass_base(v); } } function basics_test() { var v = new tclass(4); var v_base = new tclass_base(4); if (!(v instanceof tclass)) throw "instanceof 1"; if (!(v instanceof tclass_base)) throw "instanceof 2"; if (v_base instanceof tclass) throw "instanceof 3"; print("basics test passed! \n"); } function string_test() { var v = new tclass(4); if ( "1" + 2 + "3" != "123" ) throw "default toString in assignmet"; if ( "1" + 2 + "3" + v != "1234" ) throw "user defined toString in assignmet"; var s = new string("0123456789"); if( s[3] != '3' ) throw "item"; // substr test if ( "0123456789".substr(2,3) != "234" ) throw "substr 1"; if ( "0123456789".substr(2,10) != "23456789" ) throw "substr 2"; if ( "0123456789".substr(-2,8) != "01234567" ) throw "substr 3"; if ( "0123456789".substr(2,-8) != "" ) throw "substr 4"; // slice test if ( "0123456789".slice(2,6) != "2345" ) throw "slice 1"; if ( "0123456789".slice(2,-2) != "234567" ) throw "slice 2"; // case tests if ( "Hello World".to_upper() != "HELLO WORLD" ) throw "to_upper"; if ( "Hello World".to_lower() != "hello world" ) throw "to_lover"; // locale test /russian/. tested on win32 platform. others - not yet // locale("Russian"); // if ( "Привет Мир".to_lower() != "привет мир" ) throw "to_lover:" + "Привет Мир".to_lower(); // like test if ( !"Hello world".like("??[a-z]l*") ) throw "like 0"; if ( !"5*".like("5[*]") ) throw "like 1"; if ( !"?n".like("[?]n") ) throw "like 2"; if ( !"a".like("[a-cdf]") && !"f".like("[a-cdf]") ) throw "like 3"; if ( !"-".like("[-acdf]") && !"f".like("[-acdf]") ) throw "like 4"; if ( !"[".like("[[]") ) throw "like 5"; if ( !"abc?d".like("abc[?]d*") ) throw "like 5"; if ( !"abc?de".like("abc[?]d*") ) throw "like 6"; if ( !"abce".like("abc[def]") && !"abcz".like("abc[def]") ) throw "like 7"; if ( !"Hello".like("[a-zA-Z]*") && !"hello".like("[a-zA-Z]*") ) throw "like 8"; // if ( !"Шишига".like("[А-Я]*") ) throw "like 9"; print(string::printf("%d,%.2f,%s\n",123,123.45,"it is a string")); var ts = "1.2.3.4."; if( ts.replace(".","-") != "1-2-3-4-" ) throw "replace " + ts.replace(".","-") ; var sarr = "1,2,3,4,5,6".split(','); if(sarr.length != 6) throw "split 1"; if(int(sarr[0]) != 1 && int(sarr[5]) != 6) throw "split 2"; print("string test passed!\n"); } //compararator function for array sort function less(a,b) { return a < b; } function array_test() { var ar = new array(); var i; // push test for(var j=9;j>=0;j--) ar.push(j); if(ar.length != 10) throw "array.length"; for(i=0;i<10;i++) if(ar[i] != (9-i) ) throw "array.push"; ar[9] = 0; if(ar[9] != 0) throw "array.item"; //slice test var fragment = ar.slice(2,-2); if (fragment.length != 6) throw "array.slice"; // sort test (default) fragment.sort(); for(i=0;i\n",i, matches[i] ); reg.compile( RE_TCP_IP_ADDR ); pat = "127.0.0.1 localhost"; out.printf( "matching:%s\n", pat); if(reg.test( pat )) { out.printf( "matched:%s by %s\n", pat, reg); for(var k=0; k < reg.length; k++) out.printf( " element #%d = <%s>\n",k, reg[k] ); } out.printf("regexp 2 test passed! \n"); } function main() { try { basics_test(); string_test(); array_test(); date_test(); map_test(); regexp_test(); regexp_test_2(); print("all tests passed!\n"); } catch(e) { print("ERROR:" + e + "\n"); } }