diff --git a/src/Makefile.src b/src/Makefile.src index 4b67679eb2db1393f160d320a32d56865f63d387..09f4a0ef1eee331a29373651a9183888a56f20ed 100644 --- a/src/Makefile.src +++ b/src/Makefile.src @@ -61,9 +61,8 @@ LD=$(CC) LDFLAGS=$(CFLAGS) RUNPIKE=$(TMP_BUILDDIR)/pike -m $(TMP_LIBDIR)/master.pike $(PIKEOPTS) -FIXDEP=$(TMP_BINDIR)/fixdepends.sh -MAKE_FLAGS = "prefix=$(prefix)" "exex_prefix=$(exex_prefix)" "CC=$(CC)" "OTHERFLAGS=$(OTHERFLAGS)" "FIXDEP=$(FIXDEP)" "DEBUGDEF=$(DEBUGDEF)" +MAKE_FLAGS = "prefix=$(prefix)" "exec_prefix=$(exec_prefix)" "CC=$(CC)" "OTHERFLAGS=$(OTHERFLAGS)" "TMP_BINDIR=$(TMP_BINDIR)" "DEBUGDEF=$(DEBUGDEF)" "TMP_LIBDIR=$(TMP_LIBDIR)" # Add alloca.o if you don't have alloca() on your machine. # Add ualarm.o if you don't have ualarm() on your machine. @@ -157,6 +156,7 @@ spotless: clean -rm -f lexical.c mon.out *.ln config.status -rm -f $(TMP_BINDIR)/driver $(TMP_BINDIR)/*~ $(TMP_BINDIR)/#*# -rm -f .pure driver* l.outa* + -rm -f modules/*/testsuite # create tags tags: @@ -167,16 +167,18 @@ TAGS: # verify / debug verify: testsuite - $(RUNPIKE) $(SRCDIR)/test/test_pike.pike testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike testsuite + ( cd modules ; $(MAKE) $(MAKE_FLAGS) verify ) # verify / debug verbose verbose_verify: testsuite - $(RUNPIKE) $(SRCDIR)/test/test_pike.pike testsuite --verbose + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike testsuite --verbose + ( cd modules ; $(MAKE) $(MAKE_FLAGS) verbose_verify ) # verify & debug VERBOSE gdb_verify: testsuite @echo >.gdbinit handle SIGUSR1 nostop noprint pass - @echo >>.gdbinit run -m $(TMP_LIBDIR)/master.pike $(PIKEOPTS) $(SRCDIR)/test/test_pike.pike testsuite -v -v -f + @echo >>.gdbinit run -m $(TMP_LIBDIR)/master.pike $(PIKEOPTS) $(TMP_BINDIR)/test_pike.pike testsuite -v -v -f gdb ./pike @rm .gdbinit @@ -203,7 +205,7 @@ peep.o: peep_engine.c # make dependencies (requires compiled Pike) depend: language.c - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) ( cd modules ; $(MAKE) $(MAKE_FLAGS) depend ) docs: @@ -237,7 +239,7 @@ config.status: $(SRCDIR)/configure ./config.status --recheck $(SRCDIR)/Makefile.in: $(SRCDIR)/Makefile.src - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) Makefile: $(SRCDIR)/Makefile.in config.status CONFIG_FILES=Makefile CONFIG_HEADERS= ./config.status @@ -248,7 +250,7 @@ machine.h: stamp-h stamp-h: machine.h.in config.status CONFIG_FILES= CONFIG_HEADERS=machine.h ./config.status -testsuite: $(SRCDIR)/test/create_testsuite - m4 <$(SRCDIR)/test/create_testsuite >testsuite +testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >testsuite diff --git a/src/modules/Makefile.src b/src/modules/Makefile.src index d0e94271db752c19d8711c1183742424b2575926..7a8b68184f5ad7a6b9e9028229aa11dd1dde12a6 100644 --- a/src/modules/Makefile.src +++ b/src/modules/Makefile.src @@ -3,7 +3,7 @@ MODULES=@subdirs@ MODULE_OBJS=@MODULE_OBJS@ -MAKE_FLAGS = "prefix=$(prefix)" "exex_prefix=$(exex_prefix)" "CC=$(CC)" "OTHERFLAGS=$(OTHERFLAGS)" "FIXDEP=$(FIXDEP)" "DEBUGDEF=$(DEBUGDEF)" +MAKE_FLAGS = "prefix=$(prefix)" "exec_prefix=$(exec_prefix)" "CC=$(CC)" "OTHERFLAGS=$(OTHERFLAGS)" "TMP_BINDIR=$(TMP_BINDIR)" "TMP_LIBDIR=$(TMP_LIBDIR)" all: modules @@ -17,8 +17,14 @@ linker_options: $(MODULE_OBJS) done ; ) >linker_options depend: - gcc -MM $(PREFLAGS) @srcdir@/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) @srcdir@/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) depend ) ; done clean: for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) clean ) ; done + +verify: + for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) verify ) ; done + +verbose_verify: + for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) verbose_verify ) ; done diff --git a/src/modules/call_out/Makefile.src b/src/modules/call_out/Makefile.src index 0de1983c20ea991e4703f07109ad3f8a690806ba..ef937e37489f1532b3e736524de943aff8d2005f 100644 --- a/src/modules/call_out/Makefile.src +++ b/src/modules/call_out/Makefile.src @@ -14,4 +14,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/call_out/testsuite.in b/src/modules/call_out/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..6fa1711338dcbd9d482e4589260d84f3242e23ce --- /dev/null +++ b/src/modules/call_out/testsuite.in @@ -0,0 +1,14 @@ +// - call_out, call_out_info, remove_call_out, find_call_out +test_do(call_out(a,100000)) +test_true(call_out(lambda() {},1000.0)) +test_true(remove_call_out(call_out(lambda() {},1000.0)) != -1) +test_true(find_call_out(call_out(lambda() {},1000.0)) > 990) +test_false(zero_type(remove_call_out(call_out(lambda() {},1000.0)))) +test_true(arrayp(call_out_info())) +test_true(sizeof(call_out_info()) > 0) +test_true(call_out_info()[-1][0] > 1) +test_eq(find_call_out(call_out_info()[-1][2]), call_out_info()[-1][0]) +test_eq(find_call_out(a),-1) +test_true(zero_type(find_call_out(a))) +test_do(remove_call_out(call_out_info()[-1][2])) +test_true(!sizeof(call_out_info()) || function_name(call_out_info()[-1][2])!="a") diff --git a/src/modules/files/Makefile.src b/src/modules/files/Makefile.src index 7cfca629e9cce7ebd3fdc8529082a736324eef4a..349f5590318b422c786d64090b66ada3a90d5712 100644 --- a/src/modules/files/Makefile.src +++ b/src/modules/files/Makefile.src @@ -15,5 +15,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/files/testsuite.in b/src/modules/files/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..e1164f66ee3601e9ad5150058c8ea6e2ccb3a1d1 --- /dev/null +++ b/src/modules/files/testsuite.in @@ -0,0 +1,93 @@ +// tests for file module +test_true(programp((program)"/precompiled/file")) +test_do(add_efun("FILE",(program)"/precompiled/file")) +test_true(programp(FILE)) +test_true(programp((program)"/precompiled/port")) +test_any(object o; o=clone(FILE); destruct(o); return 1,1) + +// - file->open +// - file->close +test_any(object o=clone(FILE); return o->open("conftest","wct") && o->close(),1) + +// - file_stat +test_eq(file_stat("conftest")[1],0) + +// - rm +test_true(rm("conftest")) +test_eq(file_stat("conftest"),0) + +// - file->write +test_any(int e; object o=clone(FILE); if(!o->open("conftest","wct")) return -1; e=o->write("sune"); if(!o->close()) return -1; return e,4) + +// - file->read +test_any(string s; object o=clone(FILE); if(!o->open("conftest","r")) return -1; s=o->read(4); if(!o->close()) return -1; return s,"sune") + +test_any(string s; object o=clone(FILE); if(!o->open("conftest","r")) return -1; s=o->read(999999); if(!o->close()) return -1; return s,"sune") + +test_any(int e; object o=clone(FILE); if(!o->open("conftest","wct")) return -1; e=o->write(sprintf("%'+-*'100000s","")); if(!o->close()) return -1; return e,100000) + +test_any(string s; object o=clone(FILE); if(!o->open("conftest","r")) return -1; s=o->read(9999999); if(!o->close()) return -1; return s,sprintf("%'+-*'100000s","")) + +// - file->seek +// - file->tell +test_any(object o=clone(FILE); return o->open("conftest","r") && o->read(4711) && o->tell() == 4711 && o->close(),1) + +// - file->stat +test_any(object o=clone(FILE); return equal(o->open("conftest","r") && o->stat(), file_stat("conftest")),1) + +// - file->errno +test_do(clone(FILE,"stdin")->errno()) + +// - file->set_nonblocking +// - file->set_blocking +// - file->set_id +// - file->query_id +test_false(clone(FILE,"stdin")->query_id()) + +// - file->query_read_callback +test_do(clone(FILE,"stdin")->query_read_callback()) + +// - file->query_write_callback +test_do(clone(FILE,"stdin")->query_write_callback()) + +// - file->query_close_callback +test_do(clone(FILE,"stdin")->query_close_callback()) + +// - file->open_socket +// - file->connect +// - file->query_address +// - file->pipe +test_any([[object o=clone(FILE),o2=o->pipe();o->write("1"); return o2->read(1)]],"1") +test_any([[object o=clone(FILE),o2=o->pipe();o2->write("1"); return o->read(1)]],"1") + +// - file->dup +test_any([[object o=clone(FILE); o->open("conftest","r"); o=o->dup(); return o->read(100)]] ,sprintf("%'+-*'100s","")) + +// - file->assign +est_any([[object o=clone(FILE),o2=clone(FILE); o->open("conftest","r"); o2->assign(o); return o2->read(100)]] ,sprintf("%'+-*'100s","")) + +// - file->dup2 +test_any([[object o=clone(FILE),o2=clone(FILE); o2->pipe(); o->open("conftest","r"); o->dup2(o2); return o2->read(100)]] ,sprintf("%'+-*'100s","")) + +test_eq(popen("echo foo"),"foo\n") + +// - socket->bind +// - socket->set_id +// - socket->query_id +// - socket->errno +// - socket->accept + +test_true(rm("conftest")) +test_eq(file_stat("conftest"),0) + +// - file_stat +// - perror +// - rm +// - mkdir +// - get_dir +test_true(arrayp(get_dir("."))) + +// - cd +// - getcwd +test_true(stringp(getcwd())) +test_eq('/',getcwd()[0]) diff --git a/src/modules/gdbmmod/Makefile.src b/src/modules/gdbmmod/Makefile.src index 8918ad4889a6e4fcd828cddcd265552c98eade1d..5aae3999463b27125e3403b97c0342636e0eb346 100644 --- a/src/modules/gdbmmod/Makefile.src +++ b/src/modules/gdbmmod/Makefile.src @@ -16,4 +16,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/gdbmmod/testsuite.in b/src/modules/gdbmmod/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..06f598934c079d45cc59af476eaa684f7cd1cf25 --- /dev/null +++ b/src/modules/gdbmmod/testsuite.in @@ -0,0 +1,52 @@ +// gdbm +cond( [[ master()->programs["/precompiled/gdbm"] ]], +[[ + define([[GDBM]],[[ (program)"/precompiled/gdbm" ]]) + test_true(programp(GDBM)) + test_do(destruct(clone(GDBM))) + + define([[GDBMTESTS]], + [[ + test_do(rm("test.gdbm")) + test_do(add_efun("GDBMBASE",clone(GDBM,"test.gdbm"))) + test_true(file_stat("test.gdbm")) + + GDBMNULLTEST + test_true(GDBMBASE->store("foo","bar")) + GDBMNULLTEST + test_equal(GDBMBASE->fetch("foo"),"bar") + test_do([[int e; for(e=0;e<1000;e++) GDBMBASE->store("x"+e,"y"+e)]]) + GDBMNULLTEST + test_any(int e; for(e=0;e<1000;e++) if(GDBMBASE->fetch("x"+e)!="y"+e) return e; return -1,-1) + GDBMNULLTEST + test_true(GDBMBASE->store(sprintf("%'23'100000s",""),sprintf("%'32'100000s",""))) + test_true(GDBMBASE->fetch(sprintf("%'23'100000s",""))==sprintf("%'32'100000s","")) + GDBMNULLTEST + test_equal(GDBMBASE->fetch("foo"),"bar") + test_any(int e; for(e=0;e<1000;e++) if(GDBMBASE->fetch("x"+e)!="y"+e) return e; return -1,-1) + test_true(GDBMBASE->fetch(sprintf("%'23'100000s",""))==sprintf("%'32'100000s","")) + test_any(int e; string k; for(k=GDBMBASE->firstkey();k;k=GDBMBASE->nextkey(k)) e++; return e,1002) + + test_do(GDBMBASE->sync()) + test_do(GDBMBASE->reorganize()) + test_do(GDBMBASE->close()) + ]]) + + define([[GDBMNULLTEST]],[[ + test_false(GDBMBASE->fetch("slakjdfasdf")) + ]]) + + GDBMTESTS + + define([[GDBMNULLTEST]],[[ + test_false(GDBMBASE->fetch("slakjdfasdf")) + test_do(GDBMBASE->reorganize()) + test_do(GDBMBASE->sync()) + test_do(GDBMBASE->close()) + test_do(GDBMBASE->create("test.gdbm")) + ]]) + + GDBMTESTS + + test_do(rm("test.gdbm")) +]]) diff --git a/src/modules/gmpmod/Makefile.src b/src/modules/gmpmod/Makefile.src index 9c2029bb31c1d6cc59916cb67728dc5f08a0db6e..a5e5383e25647f5df07725606b19eb82ca364572 100644 --- a/src/modules/gmpmod/Makefile.src +++ b/src/modules/gmpmod/Makefile.src @@ -16,4 +16,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/gmpmod/testsuite.in b/src/modules/gmpmod/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..0cca2dbfa8d6f37f1d1cc042c20d7e26dbffaaea --- /dev/null +++ b/src/modules/gmpmod/testsuite.in @@ -0,0 +1,51 @@ +// mpz +cond( [[ master()->programs["/precompiled/mpz"] ]], +[[ + define([[MPZ]],[[(program)"/precompiled/mpz"]]) + test_true(programp(MPZ)) + test_false(clone(MPZ)) + test_do(destruct(clone(MPZ))) + test_eq(clone(MPZ,99)+1,100) + test_eq(clone(MPZ,100)*10,1000) + test_eq(clone(MPZ,"100")*10.0,1000) + test_eq(clone(MPZ,100.0)*clone(MPZ,3),300) + test_eq(clone(MPZ,100.0)/4,25) + test_eq(clone(MPZ,42)%10,2) + test_eq(clone(MPZ,10)<<1,20) + test_eq(clone(MPZ,10)>>1,5) + test_eq(clone(MPZ,66)+11,77) + test_eq(clone(MPZ,66)-11,55) + test_eq(clone(MPZ,17)&18,16) + test_eq(clone(MPZ,17)|7,31) + test_eq(-clone(MPZ,17),17) + test_eq((~clone(MPZ,17)) & 255,0xf0) + test_true(stringp((string)clone(MPZ,17))) + test_eq((string)clone(MPZ,17),"17") + test_true(intp((int)clone(MPZ,17))) + test_eq((int)clone(MPZ,17),17) + test_false(clone(MPZ,0)) + test_true(clone(MPZ,1)) + + define([[mpz_test_cmp]],[[ + test_cmp(clone(MPZ,$1), $2) + test_cmp($1, clone(MPZ,$2)) + test_cmp(clone(MPZ, $1), clone(MPZ, $2)) + ]]) + + define([[mpz_test_type1]],[[ + mpz_test_cmp($1,$2) + mpz_test_cmp($1.0,$2) + mpz_test_cmp("$1",$2) + ]]) + + define([[mpz_test_type2]],[[ + mpz_test_type1($1,$2) + mpz_test_type1($1,$2.0) + mpz_test_type1($1,"$2") + ]]) + + mpz_test_type2(1,2) + mpz_test_type2(-2,1) + +]]); + diff --git a/src/modules/image/Makefile.src b/src/modules/image/Makefile.src index cc1938e55d97e6f60ffeea60173614ee24ee6883..cde0451ff4be2af43273da005e7d7325419fd1bc 100644 --- a/src/modules/image/Makefile.src +++ b/src/modules/image/Makefile.src @@ -21,5 +21,20 @@ pure: image.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/image/testsuite.in b/src/modules/image/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/modules/math/Makefile.src b/src/modules/math/Makefile.src index 44f0678005d6d14eefbe50563e4da76011b8a1ea..3796cf0e8da9ef08bf50aea3d6f4289e6093c984 100644 --- a/src/modules/math/Makefile.src +++ b/src/modules/math/Makefile.src @@ -15,4 +15,20 @@ clean: -rm -f *.o depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/math/testsuite.in b/src/modules/math/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..44001823a24bd9919a07b70aa889b62ecf877c8e --- /dev/null +++ b/src/modules/math/testsuite.in @@ -0,0 +1,45 @@ +// - Here we try the math module + +// - tan +test_true(floatp(tan(0.5))) +test_eq(0.5,tan(atan(0.5))) +test_eq(0.5,atan(tan(0.5))) +// - asin +test_true(floatp(asin(0.7))) +test_eq(asin(0.0),0.0) +// - atan +test_true(floatp(atan(0.7))) +test_true(3.1415 < 4.0*atan(1.0)) +test_true(3.1416 > 4.0*atan(1.0)) +// - sin +test_true(floatp(sin(1.2))) +test_true(sin(atan(1.0))>0.707) +test_true(sin(atan(1.0))<0.708) +// - acos +test_true(acos(0.7) > 0.795) +test_true(acos(0.7) < 0.796) +// - cos +test_true(floatp(cos(1.2))) +test_true(cos(atan(1.0))>0.707) +test_true(cos(atan(1.0))<0.708) +// - sqrt +test_eq(4,sqrt(16)) +test_eq(4,sqrt(17)) +test_eq(4,sqrt(24)) +test_eq(4.0,sqrt(16.0)) +// - floor +test_eq(17.0,floor(17.0)) +test_eq(17.0,floor(17.1)) +test_eq(17.0,floor(17.7)) +// - ceil +test_eq(17.0,ceil(17.0)) +test_eq(18.0,ceil(17.1)) +test_eq(18.0,ceil(17.7)) +// - exp +// - log +test_true(2.70001>exp(log(2.7))) +test_true(2.69999<exp(log(2.7))) +test_true(2.70001>log(exp(2.7))) +test_true(2.69999<log(exp(2.7))) +// - pow +test_eq(pow(10.0,10.0),10000000000.0) diff --git a/src/modules/pipe/Makefile.src b/src/modules/pipe/Makefile.src index f8dd060cf0ed5cd624647b8622f585c839c303bb..c1191d78334e72c85b5ff952c3c34e3a4a68f2c3 100644 --- a/src/modules/pipe/Makefile.src +++ b/src/modules/pipe/Makefile.src @@ -14,4 +14,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/pipe/testsuite.in b/src/modules/pipe/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/modules/readlinemod/Makefile.src b/src/modules/readlinemod/Makefile.src index 46940d347237f433b766176f8936b2d3e964d638..1ff6139ca46364ec868e1c3134d1c0a38f5d6d22 100644 --- a/src/modules/readlinemod/Makefile.src +++ b/src/modules/readlinemod/Makefile.src @@ -16,4 +16,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/readlinemod/testsuite.in b/src/modules/readlinemod/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/modules/regexp/Makefile.src b/src/modules/regexp/Makefile.src index 0ca33fdcc447e431db40c7e52e44cd1eaabbe542..7122a279c69d62c9684667cd653d093ff3911f5e 100644 --- a/src/modules/regexp/Makefile.src +++ b/src/modules/regexp/Makefile.src @@ -14,4 +14,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/regexp/testsuite.in b/src/modules/regexp/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..860677c2d6213fea4919fdb35d610dd014501cbc --- /dev/null +++ b/src/modules/regexp/testsuite.in @@ -0,0 +1,33 @@ +// - Here we try the regexp module +test_true(programp((program)"/precompiled/regexp")) +test_any(object o; o=clone((program)"/precompiled/regexp"); destruct(o); return 1,1) + +// regexp->create +test_any(object o; o=clone((program)"/precompiled/regexp","^.*$"); destruct(o); return 1,1) + +// regexp->match +test_eq(clone((program)"/precompiled/regexp","^.*$")->match(""),1) +test_eq(clone((program)"/precompiled/regexp","^.*$")->match("a"),1) +test_eq(clone((program)"/precompiled/regexp","^.*$")->match("-"),1) +test_eq(clone((program)"/precompiled/regexp","^$")->match(""),1) +test_eq(clone((program)"/precompiled/regexp","^.$")->match("a"),1) +test_eq(clone((program)"/precompiled/regexp","^.$")->match("-"),1) +test_eq(clone((program)"/precompiled/regexp","^[abc]$")->match("-"),0) +test_eq(clone((program)"/precompiled/regexp","^[abc]$")->match("a"),1) +test_eq(clone((program)"/precompiled/regexp","^[abc]$")->match("c"),1) +test_eq(clone((program)"/precompiled/regexp","^[^abc]$")->match("-"),1) +test_eq(clone((program)"/precompiled/regexp","^[^abc]$")->match("a"),0) +test_eq(clone((program)"/precompiled/regexp","^[^abc]$")->match("c"),0) +test_eq(clone((program)"/precompiled/regexp","^a*$")->match("aaaa"),1) +test_eq(clone((program)"/precompiled/regexp","^(a|bb)*$")->match("aabbabb"),1) +test_eq(clone((program)"/precompiled/regexp","^(a|bb)*$")->match(""),1) +test_eq(clone((program)"/precompiled/regexp","^(a|bb)+$")->match(""),0) +test_eq(clone((program)"/precompiled/regexp","^(a|bb)+$")->match("aaa"),1) +test_eq(clone((program)"/precompiled/regexp","^(a|bb)+$")->match("bbb"),0) +test_eq(clone((program)"/precompiled/regexp","^(a|bb)+$")->match("bbaabba"),1) +test_eq(clone((program)"/precompiled/regexp","^a|b$")->match("a"),1) +test_eq(clone((program)"/precompiled/regexp","^a|b$")->match("b"),1) + +// regexp->split +test_equal(clone((program)"/precompiled/regexp","^(a*)[^a]*$")->split("aaabbb"),({"aaa"})) + diff --git a/src/modules/spider/Makefile.src b/src/modules/spider/Makefile.src index 40ed0d61d1fdfce4c3ee7e3d6c8fe69803d28708..902f1c55108612b45855319361e5d2248eac0a36 100644 --- a/src/modules/spider/Makefile.src +++ b/src/modules/spider/Makefile.src @@ -14,5 +14,21 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/spider/testsuite.in b/src/modules/spider/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/modules/sprintf/Makefile.src b/src/modules/sprintf/Makefile.src index a6a33e732228bf75a025a436b544148ff1480acf..480d2c48eeeb360ae3ce75cb93929e8553b25d41 100644 --- a/src/modules/sprintf/Makefile.src +++ b/src/modules/sprintf/Makefile.src @@ -14,4 +14,20 @@ clean: -rm -f *.o *.a depend: - gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR) + +#verify / debug +module_testsuite: $(SRCDIR)/testsuite.in + $(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite + +verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite + +verbose_verify: module_testsuite + $(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose + +gdb_verify: module_testsuite + @echo >.gdbinit handle SIGUSR1 nostop noprint pass + @echo >>.gdbinit run -m @srcdir@/../../../lib/master.pike $(PIKEOPTS) @srcdir@/../../../bin/test_pike.pike module_testsuite -v -v -f + gdb ./pike + @rm .gdbinit diff --git a/src/modules/sprintf/testsuite.in b/src/modules/sprintf/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..1ced592cf4ff2f1f819bb715723abbb93bf671e2 --- /dev/null +++ b/src/modules/sprintf/testsuite.in @@ -0,0 +1,52 @@ +// - sprintf module +test_true(stringp(sprintf(""))) +test_eq(sprintf("%d",1),"1") +test_eq(sprintf("%%"),"%") +test_eq(sprintf("%d",1),"1") +test_eq(sprintf("%d",-1),"-1") +test_eq(sprintf("%u",1<<31),"2147483648") +test_eq(sprintf("%o",255),"377") +test_eq(sprintf("%x",255),"ff") +test_eq(sprintf("%X",255),"FF") +test_eq(sprintf("%c",255),"\377") +test_eq(sprintf("%2c",65535),"\377\377") +test_eq(sprintf("%3c",0xffffff),"\377\377\377") +test_true(stringp(sprintf("%f",255.0))) +test_true(stringp(sprintf("%g",255.0))) +test_true(stringp(sprintf("%e",255.0))) +test_true(stringp(sprintf("%e",255.0))) +test_eq(sprintf("%s","foobaR"),"foobaR") +test_eq(sprintf("%s","foo\nbar"),"foo\nbar") +test_true(stringp(sprintf("%O",this_object()))) +test_true(stringp(sprintf("%O",({})))) +test_eq(sprintf("%n"),"") +test_eq(sprintf("%t",1),"int") +test_eq(sprintf("%t",this_object()),"object") +test_eq(sprintf("%{%d\n%}",({1,2,3,4})),"1\n2\n3\n4\n") + +test_eq(strlen(sprintf("%1000s","")),1000) +test_eq(sprintf("%2d",1)," 1") +test_eq(sprintf("%2d",1)," 1") +test_eq(sprintf("%2d",2222),"2222") +test_eq(sprintf("%!2d",2222),"22") +test_eq(sprintf("%!!2d",2222),"2222") +test_eq(sprintf("% d",2)," 2") +test_eq(sprintf("% d",-2),"-2") +test_eq(sprintf("%+d",2),"+2") +test_eq(sprintf("%+d",-2),"-2") +test_eq(sprintf("%-2d",2),"2 ") +test_eq(sprintf("%|3d",2)," 2 ") +test_eq(sprintf("%-=3s","f o bar gaz"),"f o\nbar\ngaz") +dnl test_eq(sprintf("%/3s","f o bargaz"),"f o\nbar\ngaz") +dnl test_true(stringp(sprintf("%3#s","f\no\nbargaz\nonk"))) +dnl test_true(stringp(sprintf("%3$s","f\no\nbargaz\nonk"))) +test_eq(sprintf("%*d",3,3)," 3") +test_eq(sprintf("%'FOO'10s","BAR"),"FOOFOOFBAR") +test_eq(sprintf("%d %<d %<d",2),"2 2 2") +test_true(stringp(sprintf("%O",({1,2,"foo"})))) +test_true(stringp(sprintf("%O",([1:2,"foo":"bar"])))) + +dnl . : and ; hasn't been tested +dnl ^, @ and _ hasn't been tested yet +test_eval_error(sprintf("%d")) + diff --git a/src/testsuite.in b/src/testsuite.in new file mode 100644 index 0000000000000000000000000000000000000000..edaeab54c3241a206aed82ffa9b2b7c29ad5f47e --- /dev/null +++ b/src/testsuite.in @@ -0,0 +1,1591 @@ +// ++ +test_any([[int e; e++; return e;]],1) +test_any([[int e; ++e; return e;]],1) +test_any([[int e; return e++;]],0) +test_any([[int e; return ++e;]],1) +test_any([[int e; if(e++) return 0; return e;]],1) + +// -- +test_any([[int e; e--; return e;]],-1) +test_any([[int e; --e; return e;]],-1) +test_any([[int e; return e--;]],0) +test_any([[int e; return --e;]],-1) +test_any([[int e; if(e--) return 0; return e;]],-1) + +test_compile_error_low(master()->add_precompiled_program(\"/test\",compile_string(\"int foo() { return 17; }\",\"62\"))) + +test_any([[function f=random_seed; int t; foreach(allocate(1),t) f(t); return 1;]],1) +test_compile([[while(0)if(0)continue;else;]]) +test_program([[int b=1,c; int a() { c=b+2; return c==3; }]]) +test_true([[ ("foobar"/"o") & ({ "foo" }) ]]) +test_any([[ array a="foo bar"/" "; return sizeof(a & ({"foo"}))]],1) + +// glob +test_false(glob("foo","bar")) +test_true(glob("foo","foo")) +test_true(glob("f?o","foo")) +test_true(glob("f??","foo")) +test_true(glob("?o?","foo")) +test_true(glob("f*","foo")) +test_true(glob("*o","foo")) +test_false(glob("*f","foo")) +test_false(glob("o*","foo")) +test_false(glob("?f?","foo")) +test_equal([[glob("?f?",({"ff","ffff","off","fff",""}))]],[[({"off","fff"})]]) +test_equal([[glob("foo*bar",({"foobar","foobargazonk","","foofoobar","fobar","fooar"}))]],[[({"foobar","foofoobar"})]]) + +// localtime +cond([[all_efuns()->localtime]], +[[ +test_true(mappingp(localtime(0))) +]]) + +// strerror +cond([[all_efuns()->strerror]], +[[ +test_do(strerror(1)) +test_true(stringp(strerror(2)||"")) +]]) + + +// sort +test_equal(sort(({1,3,2,4})),({1,2,3,4})) +test_equal(sort(({4,3,2,1})),({1,2,3,4})) +test_equal([[lambda() {string *a=({1,2,3,4}); sort(({4,3,2,1}),a); return a; }()]],[[({4,3,2,1})]] ) +test_equal([[lambda() {string *a=({1,2,3,4}),*b=a+({}); sort(({4,3,2,1}),a,b); return b; }()]],[[({4,3,2,1})]] ) + + +// m_delete +test_equal(([1:1]),m_delete(a(),0)) +test_equal(([1:1]),m_delete(([1:1,0:3]),0)) +test_any(mapping a=([1:1]); return a==m_delete(a,1),1) +test_any([[mapping m=([]); m[1]++; return m[1];]],1) +test_any([[mapping m=([1:1]); m[1]++; return m[1];]],2) +test_any([[mapping m=([]); m[1]++; m[1]++; return m[1];]],2) + +// mapping tests + +test_any([[mapping m=([]);int e; + for(e=0;e<1000;e++) m[e]=e; + for(e=0;e<1000;e++) if(m[e]!=e) return 0; + return 1; +]],1) + +test_any([[mapping m=([]);int e; + for(e=0;e<1000;e++) m[e]=e; + for(e=999;e>=0;e--) if(m[e]!=e) return 0; + return 1; +]],1) + + +test_any([[mapping m=([]);int e; + for(e=999;e>=0;e--) m[e]=e; + for(e=0;e<1000;e++) if(m[e]!=e) return 0; + return 1; +]],1) + +test_any([[mapping m=([]);int e; + for(e=999;e>=0;e--) m[e]=e; + for(e=999;e>=0;e--) if(m[e]!=e) return 0; + return 1; +]],1) + + +test_any([[mapping m=([]);int e; + for(e=0;e<1000;e++) m[reverse(e)]=e; + for(e=0;e<1000;e++) if(m[reverse(e)]!=e) return 0; + return 1; +]],1) + + +test_any([[mapping m=([]);int e; + for(e=999;e>=0;e--) m[reverse(e)]=e; + for(e=0;e<1000;e++) if(m[reverse(e)]!=e) return 0; + return 1; +]],1) + + +test_any([[mapping m=([]);int e; + for(e=0;e<1000;e++) m[reverse(e)]=e; + for(e=0;e<1000;e++) m_delete(m,reverse(e)); + return sizeof(m); +]],0) + +test_any([[mapping m=([]);int e; + for(e=0;e<1000;e++) m[reverse(e)]=e; + for(e=0;e<1000;e+=2) m_delete(m,reverse(e)); + for(e=0;e<1000;e+=2) if(m[reverse(e)]) return 0; + for(e=1;e<1000;e+=2) if(m[reverse(e)]!=e) return 0; + return 1; +]],1) + +test_any([[mapping m=([]);int e; + for(e=0;e<1000;e++) m[reverse(e)]=e; + for(e=0;e<1000;e++) m[reverse(e)]++; + for(e=0;e<1000;e++) if(m[reverse(e)]!=e+1) return 0; + return 1; +]],1) + +test_any([[mapping m=([]);int e; + mixed a,b; + a=allocate(1000); + b=allocate(1000); + for(e=0;e<1000;e++) + { + m[reverse(e)]=e; + a[e]=reverse(e); + b[e]=e; + } + add_efun("mtest_m",m); + add_efun("mtest_i",a); + add_efun("mtest_v",b); + return 1; +]],1) + + +test_eq([[sizeof(mtest_m)]],sizeof(mtest_i)) +test_equal(sort_array(indices(mtest_m)),sort_array(mtest_i)) +test_equal(sort_array(values(mtest_m)),sort_array(mtest_v)) +test_equal(mtest_m,copy_value(mtest_m)) +test_any([[int e; for(e=0;e<1000;e++) if(!equal(mtest_m[mtest_i[e] ],mtest_v[e])) return 0; return 1;]],1) + + +test_any([[mapping m=([]);int e; + mixed a,b; + a=allocate(100); + b=allocate(100); + for(e=0;e<100;e++) + { + m[reverse(e-50)]=e-50; + a[e]=reverse(e-50); + b[e]=reverse(e-50); + } + add_efun("mtest_m2",m); + add_efun("mtest_i2",a); + add_efun("mtest_v2",b); + return 1; +]],1) + +test_any([[int e;mapping q=([]),p=([]); for(e=0;e<1000;e++) { p[reverse(e)]=e; q+=([reverse(e):e]); if(!equal(sort(indices(p)),sort(indices(q)))) return 0; } return 1;]],1) +test_any([[mapping m=([]); m+=(["foo":"bar"]); m+=(["bar":"foo"]); m+=(["foo":"foo"]); if(sizeof(m)==3) return 1; return m["foo"]=="foo" && m["bar"]=="foo"]],1) + +test_equal(sort(indices(mtest_m|mtest_m2)),sort(mtest_i|mtest_i2)) +test_equal(sort(indices(mtest_m&mtest_m2)),sort(mtest_i&mtest_i2)) +test_equal(sort(indices(mtest_m-mtest_m2)),sort(mtest_i-mtest_i2)) +test_equal(sort(indices(mtest_m^mtest_m2)),sort(mtest_i^mtest_i2)) +test_equal(sort(indices(mtest_m2|mtest_m)),sort(mtest_i2|mtest_i)) +test_equal(sort(indices(mtest_m2&mtest_m)),sort(mtest_i2&mtest_i)) +test_equal(sort(indices(mtest_m2-mtest_m)),sort(mtest_i2-mtest_i)) +test_equal(sort(indices(mtest_m2^mtest_m)),sort(mtest_i2^mtest_i)) + +define(MTEST,[[test_equal([[mkmapping(indices(allocate($1)),reverse(indices(allocate($1))))]],[[mkmapping(reverse(indices(allocate($1))),indices(allocate($1)))]])]]) + +MTEST(0) +MTEST(1) +MTEST(2) +MTEST(3) +MTEST(5) +MTEST(8) +MTEST(13) +MTEST(21) +MTEST(34) +MTEST(55) + +define([[MTEST]]) + +test_do(add_efun("mtest_m"); add_efun("mtest_i"); add_efun("mtest_v");) +test_do(add_efun("mtest_m2"); add_efun("mtest_i2"); add_efun("mtest_v2");) + +// rows +test_equal([[rows(({1,2,3,4,5,6,7,8,9}),({6,7,2}))]],[[({7,8,3})]]) +test_equal([[rows(({1,2,3,4,5,6,7,8,9}),({0,4,1}))]],[[({1,5,2})]]) +test_equal([[rows(({1,2,3,4,5,6,7,8,9}),({8,3,5}))]],[[({9,4,6})]]) + +// column +test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),0)]],[[({1,5,8})]]) +test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),1)]],[[({2,6,9})]]) +test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),2)]],[[({3,7,0})]]) + + +// gc +ifefun(gc, +[[ + test_true(intp(gc())); + test_any([[ gc(); array a=({0}); a[0]=a; a=0; return gc() > 0; ]],1); +]]) + + +test_eq("\377"[0],255) +test_do(add_efun("foo",clone(class {int i;}))) +test_eq(foo->i,0) +test_do(foo->i=17) +test_eq(foo->i,17) +test_do(add_efun("foo")); +test_do(add_efun("foo",clone(class {int *i=({0});}))) +test_eq(foo->i[0],0) +test_do(foo->i[0]=17) +test_eq(foo->i[0],17) +test_do(add_efun("foo")); + +// signum, signame +test_eq(signum("SIGKILL"),9) +test_eq(signum("SIGINT"),2) +test_eq(signame(9),"SIGKILL") +test_eq(signame(2),"SIGINT") + +// kill, signal, getpid +test_true(intp(getpid())) +test_do(signal(signum("SIGUSR1"),lambda() { add_efun("AFJLLAF",17); })) +test_do(kill(getpid(),signum("SIGUSR1"))) +test_eq(AFJLLAF,17) +test_do(add_efun("AFJLLAF")) +test_do(signal(signum("SIGUSR1",0))) +test_do(signal(signum("SIGUSR1"))) + +// typeof +test_eq(typeof(1),"int") +test_eq(typeof(""),"string") +test_eq(typeof(""[0]),"int") +test_eq(typeof(0.0),"float") +test_eq(typeof(all_efuns()["all_efuns"]),"mixed") + +// class +test_true(programp(class {})) +test_true(functionp(clone(class { int foo() { return 1; }})->foo)) +test_true(clone(class { int foo() { return 1; }})->foo()) +test_true(clone(class { int i=1; })->i) +test_false(clone(class { int foo() { return 1; }})->bar) +test_eq(clone(clone(class { program foo=class { int i=20; }; })->foo)->i,20) + +// type checks +test_compile_error([[} int foo() { return]]); +test_compile_error([[} void foo() { return 1]]); + +// Not yet cataloged +test_any(int i=10; { int i; } return i, 10) +test_program(void foo(int a ,int b); function(int,int:void) a() { return foo; }) +test_program(void foo(int a, int ... b); function(int,int ...:void) a() { return foo; }) +test_program(void foo(); function(:void) a() { return foo; }) +test_compile_error([[} void foo(); function(:string) a() { return foo;]]) + +test_do(lambda(){return;}()) +test_equal( ({ lambda() { return 3; } , lambda() { return 7; }, lambda() { return 9; } })(), ({ 3,7,9 })) +test_any(int *a=({10}); a[0]++; return a[0], 11) +test_any(mapping a=([10:11]); a[10]++; return a[10], 12) +test_equal(mkmapping( ({3,6,2}), ({"3","6","2"})), ([3:"3", 6:"6", 2:"2"])) +test_equal(sum(([3:"3", 6:"6", 2:"2"])), ([3:"3", 6:"6", 2:"2"])) +test_true(sum(([3:"3", 6:"6", 2:"2"])) != ([3:"3", 6:"6", 2:"2"])) + +test_true(predef::stringp("")) +test_equal([["a,b,4,7,8s,asfd,a,d,f" / ","]],[["a,b,4,7,8s,asfd,a,d,f" / ","]]) +test_any([[string *a="a,b"/","; a[0]="c"; return equal(a,({"c","b"}))]],1) +test_true(0||1) +test_true(1||0) +test_true(!0||!0) +test_true(!0&&!0) +test_any(mixed a=1; a+=1; return a,2) +test_any(mixed a=1; a-=1; return a,0) +test_equal("abcd"/"" - indices("abcd"),({"a","b","c","d"})) +test_equal("abcd"/"" & indices("abcd"),({})) +test_eq(sizeof("abcd"/"" & "de"/""),1) +test_equal( ({0,0,0,0,0}), ({0,0,0,0,0})) +test_equal( ({0,0,0,0,0}), allocate(5,"object")) +test_equal(mkmapping("abcd"/"","jklm"/"") | mkmapping("jclm"/"","alcd"/""), + mkmapping("abcdjlm"/"","jklmacd"/"")) +test_program(int foo() { return 17;} mixed a() { return foo() == 17; }) +test_any([[mixed a; a=2; a=a*3; return a]],6) +test_any([[mixed a = ({1}); a=a+({2}); return equal(a,({1,2}))]],1) +test_define_program(/test,[[int foo() { return 17; }]]) +test_any(function bar=clone((program)"/test")->foo; return bar(),17) + +// sscanf +test_any([[mixed a; return sscanf("11","%d",a)]],1) +test_any([[mixed a; sscanf("11","%d",a); return a]],11) +test_any([[mixed a; sscanf("11","%o",a); return a]],011) +test_any([[mixed a; sscanf("11","%x",a); return a]],0x11) +test_any([[mixed a; sscanf("11","%D",a); return a]],11) +test_any([[mixed a; sscanf("0x11","%D",a); return a]],0x11) +test_any([[mixed a; sscanf("011","%D",a); return a]],011) +test_any([[mixed a,b; return sscanf("11foo","%dfoo",a)]],1) +test_any([[mixed a,b; sscanf("11foo","%dfoo",a); return a]],11) +test_any([[mixed a,b; return sscanf("11foo","%d%s",a,b)]],2) +test_any([[mixed a,b; sscanf("11foo","%d%s",a,b); return b]],"foo") +test_any([[mixed a,b; return sscanf("foo","%c%s",b,a)]],2) +test_any([[mixed a,b; sscanf("foo","%c%s",b,a); return b]],'f') +test_any([[mixed a,b; sscanf("foo","%c%s",b,a); return a]],"oo") +test_any([[mixed a,b; return sscanf("1.0","%f",a)]],1) +test_any([[mixed a,b; sscanf("1.0","%f",a); return a]],1.0) +test_any([[mixed a,b; sscanf("abcdeFGji","%[a-z]%s",a,b); return a]],"abcde") +test_any([[mixed a,b; sscanf("abcdeFGji","%[a-z]%s",a,b); return b]],"FGji") + +test_any([[mixed a,b; return sscanf("foo-%-bar","%s-%%-%s",a,b);]],2) +test_any([[mixed a,b; sscanf("foo-%-bar","%s-%%-%s",a,b); return a]],"foo") +test_any([[mixed a,b; sscanf("foo-%-bar","%s-%%-%s",a,b); return b]],"bar") +test_any([[mixed a; sscanf("ab","%2c",a); return a]],'a'*256+'b') +test_any([[mixed a; sscanf("abc","%3c",a); return a]],'a'*256*256+'b'*256+'c') +test_any([[mixed a; sscanf("abc","%2c",a); return a]],'a'*256+'b') +test_any([[mixed a; sscanf("ac","%3c",a); return a]],0) +test_any([[mixed a; sscanf("ab","%2s",a); return a]],"ab") +test_any([[mixed a; sscanf("abc","%3s",a); return a]],"abc") +test_any([[mixed a; sscanf("abc","%2s",a); return a]],"ab") +test_any([[mixed a; sscanf("ac","%3s",a); return a]],0) + +// Basics +test_true(1) +test_true("") +test_true(!0) +test_true(!(!1)) +test_true(this_object()) +test_true(a) // a is the test function +test_true(0.0) +test_true(([])) +test_true(({})) +test_true((<>)) +test_true(object_program(this_object())) + +// testing ! +test_equal(!"",0) +test_equal(!this_object(),0) +test_equal(!this_function(),0) + +// testing == +test_true(1==1) +test_true(!(1==2)) +test_true(""=="") +test_true(!(""=="foo")) +test_true(this_object()==this_object()) +test_true(this_function()==a) +test_true(2.0==2.0) +test_true(({})==({})) + +// testing != +test_true(({1})!=({1})) +test_true(1!=2) +test_true(!(1==2)) +test_true(!(""!="")) +test_true(""!="foo") + +test_cmp(1,2) +test_cmp(1.0,2.0) +test_cmp(1,2.0) +test_cmp(1.0,2) +test_cmp("a","b") +test_cmp("","b") + +// hex construction +test_eq(0,0x0) +test_eq(1,0x1) +test_eq(10,0xa) +test_eq(16,0x10) +test_eq(65535,0xffff) +test_eq(17*257*65537,0x11111111) + +// octal construction +test_eq(0,00) +test_eq(1,01) +test_eq(8,010) +test_eq(64,0100) +test_eq(1073741824,010000000000) +test_eq((8+1)*(8*8+1)*(8*8*8*8+1),011111111) + +// string construction tests +test_eq(16,"\20"[0]) +test_eq(16,"\020"[0]) +test_eq(255,"\377"[0]) +test_eq(4,'\4') +test_true("\r"[0]!='r') +test_eq("\r"[0],'\r') +test_eq("\n"[0],'\n') + +// testing + +test_eq(1+1,2) +test_eq(1+(-2),-1) +test_eq((-2)+(-2),-4) +test_eq("hi"+"there","hithere") +test_eq("human"+"number"+666,"humannumber666") +test_eq("human"+("number"+666),"humannumber666") +test_eq(("human"+"number")+666,"humannumber666") +test_eq(("human"+"number")+666+111,"humannumber666111") +test_eq("humannumber"+(666+111),"humannumber777") +test_eq("a"+"b"+"c"+"d"+"e"+"f"+"g"+"h"+"i"+"j"+"k"+"l"+"m"+"n"+"o"+"p"+"q"+"r"+"s"+"t"+"u"+"v"+"x"+"y","abcdefghijklmnopqrstuvxy") +test_eq(1.0+1.0,2.0) +test_eq(1.0+(-1.0),0.0) +test_eq((-1.0)+(-1.0),-2.0) +test_eq(1.0+1,2.0) +test_eq(1+1.0,2.0) +test_eq(1+(-1.0),0.0) +test_eq(1.0+(-1),0.0) +test_eq((-1)+(-1.0),-2.0) +test_eq((-1.0)+(-1),-2.0) +test_equal(({1,2,3})+({4,5,6}),({1,2,3,4,5,6})) +test_equal((<1,2,3,4>)+(<4,5,6>),(<1,2,3,4,4,5,6>)) +test_equal(([0:1,3:6])+([5:2,3:6]),([0:1,3:6,3:6,5:2])) +test_eval_error(return this_object() + this_object()) + +// testing - +test_eq(10-3,7) +test_eq(3-10,-7) +test_eq(10.0-3.0,7.0) +test_eq(3.0-10.0,-7.0) +test_eq(10-3.0,7.0) +test_eq(3-10.0,-7.0) +test_eq(10.0-3,7.0) +test_eq(3.0-10,-7.0) +test_eq("foobargazonk"-"o","fbargaznk") +test_equal(({"foo","bar","gazonk"})-({"foo","gazonk"}),({"bar"})) +test_equal(({"c","foo","bar","gazonk","a","b",})-({"foo","gazonk"}),({"c","bar","a","b"})) +test_equal((<"foo","bar","gazonk">)-(<"foo","gazonk">),(<"bar">)) +test_equal((["foo":3,"bar":4,"gazonk":5])-(["foo":3,"gazonk":8]),(["bar":4])) + +// testing ~ +test_eq(-1-4,~4) +test_eq(-1-627893874,~627893874) + +// testing * +test_eq(3*4,12) +test_eq(4*3,12) +test_eq(2*2*2*2*2,32) +test_eq(3.0*4.0,12.0) +test_eq(4.0*3.0,12.0) +test_eq(2.0*2.0*2.0*2.0*2.0,32.0) +test_eq(3*4.0,12.0) +test_eq(4*3.0,12.0) +test_eq(2*2.0*2.0*2.0*2.0,32.0) +test_eq(3.0*4,12.0) +test_eq(4.0*3,12.0) +test_eq(2.0*2*2.0*2*2.0,32.0) +test_eq(({"foo","bar","gazonk"})*"-","foo-bar-gazonk") + +// testing / +test_eq(12/3,4) +test_eq(13/3,4) +test_eq(14/3,4) +test_eq(15/3,5) +test_eval_error(return 15/0) +test_eq(12.0/3.0,4.0) +test_eq(14.0/4.0,3.5) +test_eq(15.0/3.0,5.0) +test_eq(12/3.0,4.0) +test_eq(14/4.0,3.5) +test_eq(15/3.0,5.0) +test_eq(12.0/3,4.0) +test_eq(14.0/4,3.5) +test_eq(15.0/3,5.0) +test_eval_error(return 15.0/0.0) +test_equal("foo-bar-gazonk"/"-",({"foo","bar","gazonk"})) +test_equal("foobargazonk"/"",({"f","o","o","b","a","r","g","a","z","o","n","k"})) + +// testing % +test_eq(12%3,0) +test_eq(13%3,1) +test_eq(14%3,2) +test_eq(15%3,0) +test_eval_error(return 15 % 0) +test_eq(12.0 % 3.0,0.0) +test_eq(13.0 % 3.0,1.0) +test_eq(14.0 % 3.0,2.0) +test_eq(14.5 % 3.0,2.5) +test_eq(15.0 % 3.0,0.0) +test_eq(13 % 3.0,1.0) +test_eq(14 % 3.0,2.0) +test_eq(13.0 % 3,1.0) +test_eq(14.0 % 3,2.0) +test_eq(14.5 % 3,2.5) +test_eval_error(return 15.0 % 0.0) + +// testing && +test_eq(0 && 1,0) +test_eq(1 && 0,0) +test_eq(0 && 0,0) +test_eq(1 && 1,1) +test_eq(78 && 1,1) +test_eq(78 && 99,99) +test_eq(78 && 99,99) + +// testing || +test_eq(0 || 1,1) +test_eq(1 || 0,1) +test_eq(0 || 0,0) +test_eq(1 || 1,1) +test_eq(78 || 1,78) +test_eq(78 || 0,78) + +// testing | +test_eq(0 | 0,0) +test_eq(1 | 1,1) +test_eq(4 | 1,5) +test_eq(1 | 9,9) +test_equal( sort_array(({1,2,3,4,4}) | ({3,5,6})), ({1,2,3,4,4,5,6})) +test_equal( (<4,5,6>) | (<5,5,5>), (<4,5,5,5,6>) ) +test_equal( ([-4:8,8:7]) | ([3:3,8:3]), ([-4:8,8:3,3:3]) ) + +// testing & +test_eq(0 & 0,0) +test_eq(1 & 1,1) +test_eq(4 & 1,0) +test_eq(1 & 9,1) +test_equal( ({1,2,3,4,4}) & ({3,5,6}), ({3})) +test_equal( (<4,5,6>) & (<5,5,5>), (<5>) ) +test_equal( ([-4:8,8:7]) & ([3:3,8:3]), ([8:3]) ) + +// testing ^ +test_eq(0 ^ 0,0) +test_eq(1 ^ 1,0) +test_eq(4 ^ 1,5) +test_eq(1 ^ 9,8) +test_equal( ({1,2,3,4,4}) ^ ({3,5,6}), ({1,2,4,4,5,6})) +test_equal( (<4,5,6>) ^ (<5,5,5>), (<4,5,5,6>) ) +test_equal( ([-4:8,8:7]) ^ ([3:3,8:3]), ([-4:8,3:3]) ) + +// testing << +test_eq(1<<0,1) +test_eq(1<<1,2) +test_eq(1<<10,1024) +test_eq(5<<3,40) + +// testing >> +test_eq(9>>2,2) +test_eq(1>>1,0) +test_eq(1024>>10,1) +test_eq(47>>3,5) + +// testing ? : +test_true(0?0:1) +test_true(1?1:0) +test_true(""?1:0) +test_true(!0?1:0) +test_true(!(!1)?1:0) +test_true(this_object()?1:0) +test_true(a?1:0) // a is the test function +test_true(0.0?1:0) +test_true(([])?1:0) +test_true(({})?1:0) +test_true((<>)?1:0) +test_true(object_program(this_object())?1:0) + +// testing indexing +test_eq("foo"[0],'f') +test_eq("foo"[1],'o') +test_eq("foo"[2],'o') +test_eq("foo"[-1],'o') +test_eq("foo"[-2],'o') +test_eq("foo"[-3],'f') +test_eq(({'f','o','o'})[0],'f') +test_eq(({'f','o','o'})[1],'o') +test_eq(({'f','o','o'})[2],'o') +test_eq(({'f','o','o'})[-1],'o') +test_eq(({'f','o','o'})[-2],'o') +test_eq(({'f','o','o'})[-3],'f') +test_eq(([0:'f',1:'o',2:'o'])[0],'f') +test_eq(([0:'f',1:'o',2:'o'])[1],'o') +test_eq(([0:'f',1:'o',2:'o'])[2],'o') +test_eq(([0:'f',1:'o',2:'o'])[3],0) +test_eq(([0:'f',1:'o',2:'o'])[-1],0) +test_eq((<'f','o','o'>)['o'],1) +test_eq((<'f','o','o'>)['f'],1) +test_eq((<'f','o','o'>)['b'],0) +test_eq((<'f','o','o'>)[-1],0) + +// index assigning +test_any(mixed a=({1}); a[0]=2; return equal(a,({2})),1) +test_any(mixed a=(<1>); a[1]=2; return equal(a,(<1>)),1) +test_any(mixed a=(<1>); a[0]=2; return equal(a,(<1,0>)),1) +test_any(mixed a=(<1>); a[1]=0; return equal(a,(<>)),1) +test_any(mixed a=(<1>); a[0]=0; return equal(a,(<1>)),1) +test_any(mixed a=([1:1]); a[0]=0; return equal(a,([1:1,0:0])),1) +test_any(mixed a=([1:1]); a[1]=0; return equal(a,([1:0])),1) + +test_define_program(/test,[[public int q,w,e,r; mixed t; mixed getw() { return w; } void setw(int _) { w=_; }]]) +test_eq(clone((program)"/test")->q,0) +test_eq(clone((program)"/test")->w,0) +test_eq(clone((program)"/test")->e,0) +test_eq(clone((program)"/test")->r,0) +test_eq(clone((program)"/test")->getw(),0) +test_any(object o=clone((program)"/test"); o->setw(17); return o->w,17) +test_any(object o=clone((program)"/test"); o->w=17; return o->getw(),17) + +test_eq(clone((program)"/test")["q"],0) +test_eq(clone((program)"/test")["w"],0) +test_eq(clone((program)"/test")["e"],0) +test_eq(clone((program)"/test")["r"],0) +test_eq(clone((program)"/test")["getw"](),0) +test_any(object o=clone((program)"/test"); o["setw"](17); return o["w"],17) +test_any(object o=clone((program)"/test"); o["w"]=17; return o["getw"](),17) + +// testing range +test_eq("foObar"[0..0],"f") +test_eq("foobargazonk"[3..5],"bar") +test_eq("foo"[1..10],"oo") +test_eq("foo"[-100..0],"f") +test_eq("foo"[-100..100],"foo") +test_eq("foo"[1..0],"") +test_eq("foo"[0..-100],"") +test_eq("foobargazonk"[0..],"foobargazonk") +test_eq("foobargazonk"[1..],"oobargazonk") +test_eq("foobargazonk"[5..],"rgazonk") +test_eq("foobargazonk"[..2],"foo") +test_eq("foobargazonk"[..5],"foobar") +test_equal(({1,2,3})[0..0],({1})) +test_equal(({1,2,3})[1..2],({2,3})) +test_equal(({1,2,3})[2..10],({3})) +test_equal(({1,2,3})[-100..0],({1})) +test_equal(({1,2,3})[-100..100],({1,2,3})) +test_equal(({1,2,3})[1..0],({})) +test_equal(({1,2,3})[0..-100],({})) + +// testing @ +test_equal(({1,2,3}),lambda(mixed ... x) { return x; }(@a())) +test_equal(explode("foo",""),lambda(mixed ... x) { return x; }(@a())) +test_any([[mixed *a=({1,2,3}); return lambda(mixed ... x) { return x; }(@a) !=a]],1) + +// testing += +test_any(int a=1; a+=10; return a,11) +// testing -= +test_any(int a=1; a-=10; return a,-9) +// testing &= +test_any(int a=3; a&=10; return a,2) +// testing |= +test_any(int a=3; a|=10; return a,11) +// testing ^= +test_any(int a=3; a^=10; return a,9) +// testing <<= +test_any(int a=3; a<<=2; return a,12) +// testing <<= +test_any(int a=12; a>>=2; return a,3) +// testing *= +test_any(int a=12; a*=2; return a,24) +// testing /= +test_any(int a=12; a/=2; return a,6) +// testing %= +test_any(int a=12; a%=7; return a,5) + +// testing control structs +test_any(return 1,1) +test_any(return lambda(){return 1;} (),1 ) +test_any(if(0) return 0; else return 1,1) +test_any(if(0) return 0; return 1,1) +test_any(if(1) return 1; else return 0,1) +test_any(if("") return 1; else return 0,1) +test_any(if(!0) return 1; else return 0,1) +test_any(if(!(!1)) return 1; else return 0,1) +test_any(if(this_object()) return 1; else return 0,1) +test_any(if(a) return 1; else return 0,1) dnl a is the test function +test_any(if(0.0) return 1; else return 0,1) +test_any(if(([])) return 1; else return 0,1) +test_any(if(({})) return 1; else return 0,1) +test_any(if((<>)) return 1; else return 0,1) +test_any(if(object_program(this_object())) return 1; else return 0,1) + +// break +test_any(while(1) break; return 1,1) +test_any(while(1) if(1) break; return 1,1) + +// for +test_any(int e; for(e=0;e<10;e++) break; return e,0) +test_any(int e; for(e=0;e<10;e++) continue; return e,10) +test_any(int e;string t=""; for(e=0;e<10;e++) t+=e; return t,"0123456789") +test_any(int e;string t=""; for(e=0;e<=10;e++) t+=e; return t,"012345678910") +test_any(int e;string t=""; for(e=9;e>0;e--) t+=e; return t,"987654321") +test_any(int e;string t=""; for(e=9;e>=0;e--) t+=e; return t,"9876543210") +test_any(int e;string t=""; for(e=9;e!=0;e--) t+=e; return t,"987654321") +test_any(int e;string t=""; for(e=2;e!=10;e++) t+=e; return t,"23456789") +test_any(int e;string t=""; for(e=0;e>-10;e--) t+=e; return t,"0-1-2-3-4-5-6-7-8-9") + +// foreach +test_any([[int e;string t=""; foreach(({7,6,3,8}),e) t+=e; return t]],"7638") +test_any([[string s;if(1) foreach(({}),s); else foreach(({}),s); return 1]],1) + +// do-whilte +test_any(int e;string t=""; e=0; do{ t+=e; }while(++e<6); return t,"012345";) + +// while +test_any(int e;string t=""; e=8; while(--e) t+=e; return t,"7654321";) +test_any(int e;string t=""; e=8; while(e--) t+=e; return t,"76543210";) +test_any(int e;string t=""; e=0; while(++e<6) t+=e; return t,"12345";) +test_any(int e=1;string t=""; while(e<20){t+=e;e*=2;} return t,"124816";) + +// Switch +test_any(switch("") { case -1: case "gazonk": return 0; } return 1,1) +test_any(switch("") { case -2: case "gazonk": return 0; } return 1,1) +test_any(switch("") { case 0: case "gazonk": return 0; } return 1,1) +test_any(switch("") { case "gazonk": case 0: return 0; } return 1,1) +test_any(switch(0) { case 0: case "gazonk": return 0; } return 1,0) +test_any(switch("gazonk") { case "gazonk": case 0: return 0; } return 1,0) +test_any(switch(0) { case "": } return 1,1) +test_any(switch(1) { case 1: return 1; default: } return 0,1) +test_any(switch(2) { case 1: return 0; default: return 1;} return 0,1) +test_any(switch(1) { default: return 0; case 1: return 1; } return 0,1) +test_any(switch(2) { default: return 1; case 1: return 0; } return 0,1) +test_any(switch(0) { case "apa": case 1.0: return 0; } return 1,1) +test_any(switch("apa") { case "apa": return 1; case 1.0: } return 0,1) +test_any(switch(1.0) { case "apa": return 0; case 1.0: return 1; } return 0,1) +test_any(switch("sune") { case "gunnel": return 0; case "gunnar": return 1; case "sune": case "gusten": return 0; } return 0,0) +test_any(switch("a") { case "a": return 1; case "b": case "c": case "d": case 'a': case '1': case '0': default: } return 0,1) +test_any(switch("b") { case "a": return 0; case "b": return 1; case "c": case "d": case 'a': case '1': case '0': default: } return 0,1) +test_any(switch("c") { case "a": case "b": return 0; case "c": return 1; case "d": case 'a': case '1': case '0': default: } return 0,1) +test_any(switch("d") { case "a": case "b": case "c": return 0; case "d": return 1; case 'a': case '1': case '0': default: } return 0,1) +test_any(switch('a') { case "a": case "b": case "c": case "d": return 0; case 'a': return 1; case '1': case '0': default: } return 0,1) +test_any(switch('1') { case "a": case "b": case "c": case "d": case 'a': return 0; case '1': return 1; case '0': default: } return 0,1) +test_any(switch('0') { case "a": case "b": case "c": case "d": case 'a': case '1': return 0; case '0': return 1; default: } return 0,1) +test_any(switch("a") { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,1) +test_any(switch("b") { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,2) +test_any(switch("c") { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,3) +test_any(switch("d") { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,4) +test_any(switch('a') { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,5) +test_any(switch('1') { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,6) +test_any(switch('0') { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,7) +test_any(switch('9') { case "a": return 1; case "b": return 2; case "c": return 3; case "d": return 4; case 'a': return 5; case '1': return 6; case '0': return 7; default: return 8; } return 9,8) + + +define(test_switch0,[[ +test_any(switch($1) { $2; $3; $4; $5; } return 0,$6) +test_any(switch($1) { default: return 0; $2; $3; $4; $5; } return -1,$6) +test_any(switch($1) { $2; default: return 0; $3; $4; $5; } return -1,$6) +test_any(switch($1) { $2; $3; default: return 0; $4; $5; } return -1,$6) +test_any(switch($1) { $2; $3; $4; default: return 0; $5; } return -1,$6) +test_any(switch($1) { $2; $3; $4; $5; default: return 0; } return -1,$6) +]]) + +define(test_switch1,[[ +test_switch0($1, $2,$3,$4,$5, $6) +test_switch0($1, $2,$3,$5,$4, $6) +]]) + +define(test_switch2,[[ +test_switch1($1, $2,$3,$4,$5, $6) +test_switch1($1, $2,$4,$3,$5, $6) +test_switch1($1, $2,$5,$4,$3, $6) +]]) + +define(test_switch3,[[ +test_switch2($1,case $2:return 2,case $3:return 3,case $4:return 4,case $5:return 5,$6) +test_switch2($1,case $3:return 3,case $2:return 2,case $4:return 4,case $5:return 5,$6) +test_switch2($1,case $4:return 4,case $3:return 3,case $2:return 2,case $5:return 5,$6) +test_switch2($1,case $5:return 5,case $3:return 3,case $4:return 4,case $2:return 2,$6) +]]) + +define(test_switch4,[[ +test_switch3($1,$2,$3,$4,$5,0) +test_switch3($2,$2,$3,$4,$5,2) +test_switch3($3,$2,$3,$4,$5,3) +test_switch3($4,$2,$3,$4,$5,4) +test_switch3($5,$2,$3,$4,$5,5) +]]) + +test_switch4(17,18,19,20,21) +test_switch4("a","b","c","d","e") +test_switch4("a",0,"c","d","e") +test_switch4(1.0,2.0,3.0,4.0,5.0) +test_switch4(this_object(),"",0,4.0,1) + +test_any(int e;string t=""; for(e=0;e<10;e++) switch(e) { default: t+=e; case 4..8: } return t,"01239") +test_any([[float e,q; q=0.0; for(e=0.1;e<10.0;e+=1.0) switch(e) { default: q+=e; case 4.0..8.0: } return q]],0.1+1.1+2.1+3.1+8.1+9.1) + +// testing preprocessor +test_any(int e; object o=clone((program)"/precompiled/file"); if(!o->open("conftest.h","wct")) return -1; e=o->write("return 17;\n"); if(!o->close()) return -1; return e,11) +test_any([[ +#include "conftest.h" +]],17) +dnltest_any([[ +dnl#include <conftest.h> +dnl]],17) +test_true(intp(__LINE__)) +test_true(stringp(__FILE__)) +test_true(stringp(__DATE__)) +test_true(stringp(__TIME__)) + +// #define +test_any([[ +#define FOOa 1 +return FOOa; +]],1) + +test_any([[ +#define FOOa array +FOOa(int) b; +return 1; +]],1) + +test_any([[ +#define FOOb 17 +#undef FOOb +#define FOOb 1 +return FOOb; +]],1) + +test_compile_error([[ +#define FOOc FOOc FOO +FOO +]]) + +test_compile_error([[ +#error FOOd +FOO +]]) + +// /* */ +test_any([[ +/* return 99; * / /* */ +return 1; +]],1) + +// // +test_any([[ +// return 99; +return 1; +]],1) + +// #if +define(test_if_true,[[test_any([[ +#if $1 +return 1; +#else +return 0; +#endif +]],1)]]) +define(test_if_false,[[test_any([[ +#if $1 +return 1; +#else +return 0; +#endif +]],0)]]) + +test_if_true(1) +test_if_false(0) + +// #if == +test_if_true(1==1) +test_if_false(1==2) + +// #if != +test_if_true(1!=2) +test_if_false(1!=1) + +// #if ( ) +test_if_true( (((1))==1) ) +test_if_false( ((1)==(2)) ) + +// #if -1 +test_if_true( -1 ) +test_if_true( (-1) ) +test_if_true( (-1==0-1) ) + +// #if ~ +test_if_true( (-1-1==~1) ) + +// #if ?: +test_if_true( 17 == ( 1 ? 17 : 18 ) ) +test_if_true( 18 == ( 0 ? 17 : 18 ) ) + +// #if || +test_if_true( 10 == ( 10 || 20 ) ) +test_if_true( 20 == ( 0 || 20 ) ) + +// #if && +test_if_true( 0 == ( 0 && 20 ) ) +test_if_true( 20 == ( 10 && 20 ) ) + +// #if | +test_if_true( 3 == ( 1 | 2 ) ) +test_if_true( 2 == ( 2 | 2 ) ) + +// #if ^ +test_if_true( 0 == ( 2 ^ 2 ) ) +test_if_true( 3 == ( 1 ^ 2 ) ) + +// #if & +test_if_true( 0 == ( 1 & 2 ) ) +test_if_true( 2 == ( 2 & 7 ) ) + +// #if <= >= < > ! strings, floats + +define(test_if_cmp,[[ +test_if_true($1<$2) +test_if_true(!($1>$2)) +test_if_true($2>$1) +test_if_true(!($2<$1)) +test_if_true($1<=$2) +test_if_true(!($1>=$2)) +test_if_true($2>=$1) +test_if_true(!($2<=$1)) +test_if_true($2<=$2) +test_if_true($1>=$1) ]]) + +test_if_cmp(1,2) +test_if_cmp(1.0,2.0) +test_if_cmp("a","b") + +// #if << +test_if_true(1<<10==1024) +test_if_true(5<<3==40) + +// #if >> +test_if_true(1024>>10==1) +test_if_true(47>>3==5) + +// #if + +test_if_true(1024+10==1034) +test_if_true(47+3==50) + +// #if - +test_if_true(1024-10==1014) +test_if_true(47-3==44) + +// #if * +test_if_true(1024*10==10240) + +// #if / +test_if_true(47/3==15) + +test_compile_error([[ +#if 1/0 +return 1; +#else +return 0; +#endif +]]) + +// #if % +test_if_true(47%3==2) +test_compile_error([[ +#if 1%0 +return 1; +#else +return 0; +#endif +]]) + +// #if [ ] +test_if_true("foo"[0]=='f') + +// #if defined +test_any([[ +#define FOOe 0 +#if defined(FOOe) +return 1; +#else +return 0; +#endif +]],1) + +// #if define < x +test_any([[ +#define FOOf 1 +#if FOOf < 2 +return 1; +#else +return 0; +#endif +]],1) + +// #if define < x +test_any([[ +#define FOOg 1 +#if FOOg < 0 +return 0; +#else +return 1; +#endif +]],1) + +// #if x < define +test_any([[ +#define FOOh 1 +#if 0 < FOOh +return 1; +#else +return 0; +#endif +]],1) + +// #if x < define +test_any([[ +#define FOOi 1 +#if 2 < FOOi +return 0; +#else +return 1; +#endif +]],1) + +// #if efun +// see test for add_efun() + +// #if /* */ +test_any([[ +#if 1 /* trying to be mean // * / */ /* /* */ +return 1; /* */ +#define foo +# 1 "---" +#undef foo +#else /* trying to be mean // * / */ /* /* */ +return 0; // +#endif /* trying to be mean // * / */ /* /* */ +]],1) + +test_any([[ +#if 0 /* trying to be mean // * / */ /* /* */ +return 0; /* */ +#define foo +# 1 "---" +#undef foo +#else /* trying to be mean // * / */ /* /* */ +return 1; // +#endif /* trying to be mean // * / */ /* /* */ +]],1) + +// #if // +test_any([[ +#if 1 //* trying to be mean // */ */ +return 1; +#else //* trying to be mean // */ */ +return 0; +#endif //* trying to be mean // */ */ +]],1) + +test_any([[ +#if 0 //* trying to be mean // */ */ +return 0; +#else //* trying to be mean // */ */ +return 1; +#endif //* trying to be mean // */ */ +]],1) + +test_any([[ +#define FOOj +#if defined(FOOj) +return 1; +#else +return 0; +#endif +]],1) + +test_any([[ +#if defined(FOOk) +return 0; +#else +return 1; +#endif +]],1) + +// #ifdef +test_any([[ +#ifdef FOOl +return 0; +#else +return 1; +#endif +]],1) + +test_any([[ +#define FOOm +#ifdef FOOm +return 1; +#else +return 0; +#endif +]],1) + +// #ifndef +test_any([[ +#define FOOo +#ifndef FOOo +return 0; +#else +return 1; +#endif +]],1) + +test_any([[ +#ifndef FOOp +return 1; +#else +return 0; +#endif +]],1) + +// #else +test_any([[ +#if 1 +return 1; +#else +FEL +#if 0 +FEL +#else +FEL +#endif +return 0; +#endif +]],1) + +test_any([[ +#if 0 +FEL +#if 0 +FEL +#else +FEL +#if 1 +FEL +#else +FEL +#endif +#endif +return 0; +#else +return 1; +#endif +]],1) + +// #elif +test_any([[ +#if 0 +return 0; +#elif 0 +return 0; +#else +return 1; +#endif +]],1) + +test_any([[ +#if 0 +return 0; +#elif 1 +return 1; +#else +return 0; +#endif +]],1) + +test_any([[ +#if 1 +return 1; +#elif 1 +return 0; +#else +return 0; +#endif +]],1) + +// #elseif +test_any([[ +#if 0 +return 0; +#elseif 0 +return 0; +#else +return 1; +#endif +]],1) + +test_any([[ +#if 0 +return 0; +#elseif 0 +return 0; +#elseif 1 +return 1; +#elseif 0 +return 0; +#elseif 0 +return 0; +#else +FEL +#endif +]],1) + +test_any([[ +#if 0 +return 0; +#elseif 1 +return 1; +#else +return 0; +#endif +]],1) + +test_any([[ +#if 1 +return 1; +#elseif 1 +return 0; +#else +return 0; +#endif +]],1) + +// #pragma +// FIXME: add tests for real pragmas +test_any([[ +#pragma whatever +return 1; +]],1) + +// #include +// FIXME add test for #include + +// foop +define(do_test_foop,[[ +test_eq($1 (17), !($2)) +test_eq($1 (1.7), !($2-1)) +test_eq($1 ("17"), !($2-2)) +test_eq($1 (this_object()), !($2-3)) +test_eq($1 (a), !($2-4)) // a is the test function +test_eq($1 (({})), !($2-5)) +test_eq($1 (([])), !($2-6)) +test_eq($1 ((<>)), !($2-7)) +test_eq($1 (object_program(this_object())), !($2-8)) +]]) + +do_test_foop(intp,0) +do_test_foop(floatp,1) +do_test_foop(stringp,2) +do_test_foop(objectp,3) +do_test_foop(functionp,4) +do_test_foop(arrayp,5) +do_test_foop(mappingp,6) +do_test_foop(multisetp,7) +do_test_foop(programp,8) + +// add_efun +test_do(add_efun("foobar",lambda() { return 1; })) +test_any([[ +#if efun(foobar) +return 1; +#else +return 0; +#endif +]],1) +test_eq(foobar(),1) +test_do(add_efun("foobar")) +test_any([[ +#if efun(foobar) +return 1; +#else +return 0; +#endif +]],0) + +// - aggregate +test_true(arrayp(aggregate())) +test_eq(sizeof(aggregate()),0) +test_equal(aggregate(1,2,3,4),({1,2,3,4})) + +// - aggregate_multiset +test_true(multisetp(aggregate_multiset())) + +// - aggregate_mapping +test_true(multisetp(aggregate_multiset())) + +// - all_efuns +test_true(mappingp(all_efuns())) +test_true(all_efuns()["all_efuns"]) +test_eq(all_efuns()["all_efuns"],all_efuns) + +// - allocate +test_true(arrayp(allocate(0))) +test_equal(allocate(2),({0,0})) +test_false(allocate(2)==({0,0})) + +// - backtrace +test_true(arrayp(backtrace())) +test_eq(backtrace()[-1][2],a) + +// - call_function +test_eq(1,call_function(a)) +test_eq(1,call_function(lambda(int a){ return a; },1)) +test_eq(1,call_function(intp,1)) + +// - capitalize +test_eq(capitalize("fubar"),"Fubar") +test_eq(capitalize("FooBar"),"FooBar") +test_eq(capitalize("-"),"-") + +// - clone +// clone is already tested a lot by this script +test_true(objectp(clone(compile_string("int foo() { return 17; }")))) +test_eq(clone(compile_string("int foo() { return 17; }"))->foo(),17) + +// - combine_path +test_eq([[combine_path("/foo/bar/gazonk/","..")]],"/foo/bar") +test_eq([[combine_path("/.../","sune")]],"/.../sune") +test_eq([[combine_path("/","foo/.../sune")]],"/foo/.../sune") +test_eq([[combine_path("/./foo/bar//gazonk/","../")]],"/foo/bar/") +test_eq([[combine_path("/","/foo/./bar/gazonk/..")]],"/foo/bar") +test_eq([[combine_path("/","/foo/bar/gazonk/../../")]],"/foo/") +test_eq([[combine_path("/","/foo//bar/gazonk/../..")]],"/foo") +test_eq([[combine_path("/","/foo/bar/./gazonk/../../..")]],"/") +test_eq([[combine_path("/","/foo/../bar//./gazonk/../..")]],"/") +test_eq([[combine_path("/","/foo/././/bar/gazonk/../../../..")]],"/") + +// - compile_file +// FIXME: add tests for compile_file + +// - compile_string +// see test for clone() + +// - copy_value +test_eq(copy_value(1),1) +test_eq(copy_value(""),"") +test_eq(copy_value(1.0),1.0) +test_eq(copy_value(this_object()),this_object()) +test_eq(copy_value(a),a) +define(do_test_copy_value,[[ +test_any([[mixed x=$1; return x==x]],1) +test_any([[mixed x=$1; return copy_value(x)!=x]],1) +test_any([[mixed x=$1; return equal(copy_value(x),x)]],1)]]) +do_test_copy_value( ({1}) ) +do_test_copy_value( ([]) ) +do_test_copy_value( (<>) ) +do_test_copy_value( (< ([]), ({1}) ,"" , 1.0 >) ) + +// - crypt +test_true(stringp(crypt("hej"))) +test_true(crypt("hej",crypt("hej"))) + +// - ctime +test_true(stringp(ctime(0))) + +// - destruct +// FIXME put tests for destruct here. +test_do(add_efun("PROG",compile_string("int foo() { return 1; }"))); +test_any([[object o=clone(PROG); destruct(o); return o]],0); +test_any([[object o=clone(PROG); destruct(o); return objectp(o)]],0); +test_any([[object *o=({clone(PROG)}); destruct(o[0]); return o-({0}) ]],({})); +test_any([[mapping o=(["foo":clone(PROG)]); destruct(o["foo"]); return o["foo"]; ]],0); +dnl test_any([[object t; mapping o=([t=clone(PROG):"foo"]); destruct(t); return sizeof(o)]],0); +test_do([[object t,*o=({}); o+=({t=clone(PROG)}); destruct(t); o=({});]]); + +// - equal +// equl is already tested by this script + +// - exit +// FIXME put test for exit here + +// - explode +test_equal(({"a","b","c",}), explode("anna bnna c","nna ")) +test_equal(({"","",}),explode("hej","hej")) +test_equal(({"",}),explode("","hej")) + +// - fork() +// FIXME: add tests for fork + +// - function_name +test_eq(function_name(a),"a") +test_eq(function_name(function_name),0) + +// - function_object +test_eq(function_object(a),this_object()) +test_eq(function_name(function_object),0) + +// - get_function (actually in simulate.pike) +test_eq(a,get_function(this_object(),"a")) +test_eq(a,this_object()->a) + +// - hash +test_true(intp(hash("foo"))) +test_true(intp(hash("foo",10))) +test_true(hash("foo",10)<10) +test_true(hash("bar",10)<10) +test_true(hash("gazonk",10)<10) +test_eq(hash("foobargazonk"),hash("foobargazonk")) + +// - implode +test_eq([[implode(({}),"")]],"") +test_eq([[implode(explode("foo","o"),"o")]],"foo") +test_eq([[implode(({"foo","bar"}),"-")]],"foo-bar") +test_eq([[implode(({"foo",0,"bar"}),"-")]],"foo-bar") +test_eq([[implode(({1.0,"foo",0,"bar",this_object(),([])}),"-")]],"foo-bar") +test_eq([[implode(({"f","o","o"}),"")]],"foo") + +// - indices +test_equal(indices("foo"),({0,1,2})) +test_equal(indices(({'f','o','o'})),({0,1,2})) +test_equal(sort_array(indices(([7:3,8:9,99:12]))),({7,8,99})) +test_equal(sort_array(indices((<7,8,99>))),({7,8,99})) +test_equal(mkmultiset(indices(this_object())),(<"a","b">)) + +// - lower_case +test_equal(lower_case("foo"),"foo") +test_equal(lower_case("Foo"),"foo") +test_equal(lower_case("Foo1234-*~\n"),"foo1234-*~\n") + +// - next_object +test_true(objectp(next_object())) +test_any(int e;object o=next_object(); for(e=0;e<1000 && o;e++) o=next_object(o); return o,0) + +// - object_program +test_true(programp(object_program(this_object()))) + +// - query_host_name +test_true(stringp(query_host_name())) + +// - query_num_arg +test_eq(lambda(int ... q) { return query_num_arg(); }(),0) +test_eq(lambda(int ... q) { return query_num_arg(); }(1),1) +test_eq(lambda(int ... q) { return query_num_arg(); }(1,1),2) +test_eq(lambda(int ... q) { return query_num_arg(); }(1,1,1),3) +test_eq(lambda(int ... q) { return query_num_arg(); }(1,1,1,1),4) + +// - random +test_any([[int e,d;for(e=0;e<1000;e++){d=random(10); if(d<0 || d>=10) return 0;} return 1]],1) + +// random_seed +test_do(int p; foreach(({1,2,3,4,5}),p) random_seed(p)) +test_eq([[random_seed(17),random(20000)]],[[random_seed(17),random(20000)]]) +test_eq([[random_seed(18),random(20000)]],[[random_seed(18),random(20000)]]) +test_eq([[random_seed(19),random(20000)]],[[random_seed(19),random(20000)]]) + +// - replace +test_eq(replace("foobargazonk","o","-"),"f--bargaz-nk") +test_eq(replace("foobargazonk",({"o","a"}),({"()","<>"})),"f()()b<>rg<>z()nk") +test_eq(replace("f--barf--",({"f--","f--bar"}),({"f--bar","f--"})),"f--f--bar") +test_eq(replace("f--barf--",({"f--bar","f--"}),({"f--","f--bar"})),"f--f--bar") +test_equal(replace(({1,2,3,4,5,1,2,3,4}),3,-1),({1,2,-1,4,5,1,2,-1,4})) +test_equal(replace(([1:2,3:4,5:1,2:3]),3,-1),([1:2,3:4,5:1,2:-1])) + +// - reverse +test_eq(reverse("reverse"),"esrever") +test_eq(reverse(""),"") +test_eq(reverse("a"),"a") +test_equal(reverse(({1,5,9})),({9,5,1})) +test_equal(reverse(0x12345678),0x1e6a2c48) + +// - rusage +test_true(arrayp(rusage())) +test_true(sizeof(rusage())>0) + +// - search +test_eq(search("foolbar","gazonk"),-1) +test_eq(search("qowiueproqiuweproiwqueoplkjljlklksjjriwueproiuwerowieu","lkjljlklksjj"),24) +test_eq(search("lkjljlklksjjriwueproiuwerlskjdvlaskjfowieu","lkjljlklksjj"),0) +test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj","lkjljlklksjj"),24) +test_eq(search("foobargazonk","oo"),1) +test_eq(search("foobargazonk","o",3),9) +test_eq(search("foobargazonk","o",9),9) +test_eq(search("foobargazonk","o",10),-1) +test_eq(search("foobargazonk","x",9),-1) +test_eq(search(({56,8,2,6,2,7,3,56,7}),8),1) +test_eq(search(({56,8,2,6,2,7,3,56,7}),56,0),0) +test_eq(search(({56,8,2,6,2,7,3,56,7}),56,1),7) +test_eq(search(({56,8,2,6,2,7,3,56,7}),56,7),7) +test_eq(search(({56,8,2,6,2,7,3,56,7}),56,8),-1) +test_eq(search(({"foo"}),"foo"),0) +test_eq(search("fo-obar|gazonk"/"|","fo-obar"),0) +test_eq(search("fo-obar|gazonk"/"|","gazonk"),1) +test_eq(search(([1:2,3:4,5:6,7:8]),4),3) +test_true(zero_type(search(([1:2,3:4,5:6,7:8]),1))) +test_eq(search(([1:2,3:4,5:6,7:8]),8),7) + +// test large searches (find string, size, pattern) +define(test_search,[[ +test_eq(search(sprintf($1+"%'"+$3+"'*n",$2),$1),0) +test_eq(search(sprintf("%'"+$3+"'*n" ,$2),$1),-1) +test_eq(search(sprintf("%'"+$3+"'*n"+$1,$2),$1),$2) +test_eq(search(sprintf("%'"+$3+"'*n"+$1+"%'"+$3+"'*n",$2,$2),$1),$2) +]]) + +define(test_search2,[[dnl +test_search($1,$2,$3) +test_search($1,$2+1,$3) +test_search($1,$2+2,$3) +test_search($1,$2+3,$3) +]]) + +define(test_search3,[[dnl +test_search2($1,10,$2) +test_search2($1,1000,$2) +test_search2($1,100000,$2) +]]) + +define(test_search4,[[dnl +test_search3($1,"+-*") +test_search3($1,($1[0..strlen($1)-2])) +test_search3($1,($1[1..0x7fffffff])) +]]) + +test_search4("SUNE") +test_search4("-------------------+") +test_search4("�-------------------") +test_search4(sprintf("%'argel-bargel glop-glyf?'2000n")) + +// - sizeof +test_eq(sizeof("felbar"),6) +test_eq(sizeof(({"fulbar","gazonk",7})),3) +test_eq(sizeof(([8:3,6:6,7:0])),3) +test_eq(sizeof((<8,7,6,5,4,7>)),6) + +// - sleep +test_do(sleep(1)) +test_do(sleep(0.5)) + +// - sum +test_eq(sum(1,1),2) +test_eq(sum(1,-2),-1) +test_eq(sum(-2,-2),-4) +test_eq(sum("hi","there"),"hithere") +test_eq(sum("human","number",666),"humannumber666") +test_eq(sum("human","number",666),"humannumber666") +test_eq(sum("human","number",666),"humannumber666") +test_eq(sum("human","number",666,111),"humannumber666111") +test_eq(sum("humannumber",sum(666+111)),"humannumber777") +test_eq(sum("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y"),"abcdefghijklmnopqrstuvxy") +test_eq(sum(1.0+1.0),2.0) +test_eq(sum(1.0,-1.0),0.0) +test_eq(sum(-1.0,-1.0),-2.0) +test_equal(sum(({1,2,3}),({4,5,6})),({1,2,3,4,5,6})) +test_equal(sum((<1,2,3,4>),(<4,5,6>)),(<1,2,3,4,4,5,6>)) +test_equal(sum(([0:1,3:6]),([5:2,3:6])),([0:1,3:6,3:6,5:2])) + +// - this_object +test_true(objectp(this_object())) + +// - throw +test_eq(20,catch(throw(a()))) + +// - time +test_true(intp(time())) + +// - trace +test_do(trace(0)) +test_eq(trace(0),0) + +// - upper_case +test_equal(upper_case("fooq"),"FOOQ") +test_equal(upper_case("FooR"),"FOOR") +test_equal(upper_case("Foo1234-*~\n"),"FOO1234-*~\n") + +// - values +test_equal(values("foo"),({'f','o','o'})) +test_equal(values(({'f','o','o'})),({'f','o','o'})) +test_equal(sort_array(values(([7:3,8:9,99:12]))),({3,9,12})) +test_equal(values((<7,8,99>)),({1,1,1})) +test_equal(mkmultiset(values(this_object())),(<a,b>)) + +// - zero_type +test_eq(zero_type(0),0) +test_eq(zero_type(([])[7]),1) + +test_program(int b=10; mixed a() { return 1; }) +test_program(mixed b=10; mixed a() { return 1;}) +test_define_program(/test,[[int q,w,e,r,t; mixed foo() { return 10; }]]) + +test_program(inherit "/test"; mixed a() { return foo()==10; }) +test_program(inherit "/test"; mixed a() { return test::foo()==10; }) +test_program(inherit "/test" : bar; mixed a() { return bar::foo()==10; }) + +test_define_program(/test2,[[int z,x,c,v,b; mixed bar() { return 11; }]]) +test_program(inherit "/test"; inherit "/test2"; mixed a() { return foo()==10 && bar()==11; }) +test_program(inherit "/test2"; inherit "/test"; mixed a() { return foo()==10 && bar()==11; }) + +test_define_program(/test,[[int q,w,e,r; mixed t; mixed getw() { return w; } void setw(int _) { w=_; }]]) +test_define_program(/test2,[[int z,x,c,v,b; mixed getb() { return b; } void setb(int _) { b=_; }]]) + +test_program(inherit "/test"; inherit "/test2"; mixed a() { w=20; b=22; return getw()==20 && getb()==22; }) +test_program(inherit "/test"; inherit "/test2"; mixed a() { setw(20); setb(22); return w==20 && b==22; }) +test_program(inherit "/test2"; inherit "/test"; mixed a() { w=20; b=22; return getw()==20 && getb()==22; }) +test_program(inherit "/test2"; inherit "/test"; mixed a() { setw(20); setb(22); return w==20 && b==22; }) +