From d913fdb2800d83680e413cd8a5f07b7f85deac6e Mon Sep 17 00:00:00 2001 From: "rumpf_a@web.de" <> Date: Sun, 21 Feb 2010 19:42:36 +0100 Subject: start of tests refactoring; sqlite3 new wrapper fixes --- lib/newwrap/sqlite3.nim | 64 +++---- lib/pure/times.nim | 6 +- tests/99bottles.nim | 1 - tests/accept/compile/tarrindx.nim | 13 ++ tests/accept/compile/tassign.nim | 31 ++++ tests/accept/compile/tcmdline.nim | 14 ++ tests/accept/compile/tcolors.nim | 39 +++++ tests/accept/compile/tconsteval.nim | 28 +++ tests/accept/compile/tconvert.nim | 38 +++++ tests/accept/compile/tdeprecated.nim | 6 + tests/accept/compile/tdialogs.nim | 17 ++ tests/accept/compile/tdllvar.nim | 16 ++ tests/accept/compile/tdumpast.nim | 35 ++++ tests/accept/compile/techo.nim | 3 + tests/accept/compile/tendian.nim | 3 + tests/accept/compile/tenum.nim | 8 + tests/accept/compile/tforwty.nim | 9 + tests/accept/compile/tforwty2.nim | 22 +++ tests/accept/compile/tgtk.nim | 61 +++++++ tests/accept/compile/thallo.nim | 83 +++++++++ tests/accept/compile/tident.nim | 22 +++ tests/accept/compile/tindent1.nim | 24 +++ tests/accept/compile/tio.nim | 7 + tests/accept/compile/titer.nim | 44 +++++ tests/accept/compile/tlastmod.nim | 18 ++ tests/accept/compile/tlexer.nim | 57 +++++++ tests/accept/compile/tlibs.nim | 21 +++ tests/accept/compile/tloops.nim | 64 +++++++ tests/accept/compile/tmath.nim | 85 ++++++++++ tests/accept/compile/tnew.nim | 49 ++++++ tests/accept/compile/tnewlibs.nim | 16 ++ tests/accept/compile/tnewsets.nim | 6 + tests/accept/compile/tnewuns.nim | 12 ++ tests/accept/compile/tobjcov.nim | 17 ++ tests/accept/compile/tobject2.nim | 21 +++ tests/accept/compile/tobjects.nim | 42 +++++ tests/accept/compile/toptions.nim | 22 +++ tests/accept/compile/tos.nim | 12 ++ tests/accept/compile/toverprc.nim | 25 +++ tests/accept/compile/tparedef.nim | 4 + tests/accept/compile/tparscfg.nim | 25 +++ tests/accept/compile/tparsefloat.nim | 3 + tests/accept/compile/tparsopt.nim | 27 +++ tests/accept/compile/tposix.nim | 16 ++ tests/accept/compile/tprep.nim | 28 +++ tests/accept/compile/tpush.nim | 15 ++ tests/accept/compile/tquicksort.nim | 24 +++ tests/accept/compile/tquit.nim | 6 + tests/accept/compile/tradix.nim | 319 +++++++++++++++++++++++++++++++++++ tests/accept/compile/treadln.nim | 12 ++ tests/accept/compile/treadx.nim | 12 ++ tests/accept/compile/trecmod.nim | 2 + tests/accept/compile/trecmod2.nim | 10 ++ tests/accept/compile/trepr.nim | 32 ++++ tests/accept/compile/tseq2.nim | 13 ++ tests/accept/compile/tseqcon2.nim | 9 + tests/accept/compile/tsizeof.nim | 10 ++ tests/accept/compile/tsockets.nim | 11 ++ tests/accept/compile/tstrace.nim | 16 ++ tests/accept/compile/tstrdesc.nim | 14 ++ tests/accept/compile/tstrdist.nim | 26 +++ tests/accept/compile/tstreams.nim | 7 + tests/accept/compile/tstrset.nim | 74 ++++++++ tests/accept/compile/tstrtabs.nim | 12 ++ tests/accept/compile/ttempl.nim | 27 +++ tests/accept/compile/ttempl3.nim | 26 +++ tests/accept/compile/ttime.nim | 6 + tests/accept/compile/ttuple1.nim | 16 ++ tests/accept/compile/tvarious.nim | 43 +++++ tests/accept/compile/twalker.nim | 13 ++ tests/accept/compile/typalias.nim | 15 ++ tests/accept/run/tack.nim | 15 ++ tests/accept/run/tambsym2.nim | 18 ++ tests/accept/run/tambsys.nim | 7 + tests/accept/run/tarray.nim | 27 +++ tests/accept/run/tarray2.nim | 18 ++ tests/accept/run/tassert.nim | 16 ++ tests/accept/run/tbind1.nim | 14 ++ tests/accept/run/tbind3.nim | 5 + tests/accept/run/tbintre2.nim | 25 +++ tests/accept/run/tbintree.nim | 101 +++++++++++ tests/accept/run/tcasestm.nim | 32 ++++ tests/accept/run/tclosure.nim | 26 +++ tests/accept/run/tcnstseq.nim | 11 ++ tests/accept/run/tconstr2.nim | 20 +++ tests/accept/run/tcopy.nim | 19 +++ tests/accept/run/tcurrncy.nim | 32 ++++ tests/accept/run/tfinally.nim | 10 ++ tests/accept/run/tfloat1.nim | 8 + tests/accept/run/tfloat2.nim | 8 + tests/accept/run/tformat.nim | 6 + tests/accept/run/thintoff.nim | 6 + tests/accept/run/tinit.nim | 6 + tests/accept/run/tints.nim | 41 +++++ tests/accept/run/tisopr.nim | 20 +++ tests/accept/run/titer2.nim | 10 ++ tests/accept/run/titer3.nim | 17 ++ tests/accept/run/titer5.nim | 10 ++ tests/accept/run/tlowhigh.nim | 18 ++ tests/accept/run/tmatrix.nim | 60 +++++++ tests/accept/run/tmultim1.nim | 23 +++ tests/accept/run/tmultim2.nim | 30 ++++ tests/accept/run/tnestif.nim | 18 ++ tests/accept/run/tnestprc.nim | 10 ++ tests/accept/run/toop1.nim | 82 +++++++++ tests/accept/run/topenarrayrepr.nim | 11 ++ tests/accept/run/topenlen.nim | 12 ++ tests/accept/run/toverflw.nim | 15 ++ tests/accept/run/toverl2.nim | 21 +++ tests/accept/run/toverlop.nim | 10 ++ tests/accept/run/toverwr.nim | 7 + tests/accept/run/tovfint.nim | 17 ++ tests/accept/run/tpos.nim | 29 ++++ tests/accept/run/tprintf.nim | 10 ++ tests/accept/run/tprocvar.nim | 26 +++ tests/accept/run/tquotewords.nim | 19 +++ tests/accept/run/tregex.nim | 19 +++ tests/accept/run/treguse.nim | 21 +++ tests/accept/run/tromans.nim | 65 +++++++ tests/accept/run/tseqcon.nim | 45 +++++ tests/accept/run/tsets.nim | 58 +++++++ tests/accept/run/tsidee2.nim | 11 ++ tests/accept/run/tsidee3.nim | 11 ++ tests/accept/run/tsimmeth.nim | 8 + tests/accept/run/tsplit.nim | 14 ++ tests/accept/run/tstrange.nim | 17 ++ tests/accept/run/tstrlits.nim | 14 ++ tests/accept/run/tstrutil.nim | 24 +++ tests/accept/run/tvardecl.nim | 9 + tests/accept/run/tvarnums.nim | 136 +++++++++++++++ tests/accept/run/tvartup.nim | 11 ++ tests/gc/gcbench.nim | 163 ++++++++++++++++++ tests/gc/gctest.nim | 197 +++++++++++++++++++++ tests/gcbench.nim | 171 ------------------- tests/gctest.nim | 197 --------------------- tests/mbind3.nim | 9 - tests/mbind4.nim | 9 - tests/mvarious.nim | 6 - tests/reject/99bottles.nim | 1 + tests/reject/t99bott.nim | 28 +++ tests/reject/tadrdisc.nim | 16 ++ tests/reject/tambsym.nim | 8 + tests/reject/tambsym3.nim | 8 + tests/reject/tbind2.nim | 10 ++ tests/reject/tbind4.nim | 6 + tests/reject/tblock1.nim | 11 ++ tests/reject/tconstr1.nim | 23 +++ tests/reject/tillrec.nim | 10 ++ tests/reject/tinout.nim | 9 + tests/reject/tinvalidnewseq.nim | 20 +++ tests/reject/tinvwhen.nim | 8 + tests/reject/titer4.nim | 3 + tests/reject/tnamspc.nim | 5 + tests/reject/tnoop.nim | 6 + tests/reject/tnot.nim | 15 ++ tests/reject/topaque.nim | 11 ++ tests/reject/topena1.nim | 5 + tests/reject/toverl.nim | 6 + tests/reject/trawstr.nim | 5 + tests/reject/trecinca.nim | 5 + tests/reject/trecincb.nim | 6 + tests/reject/treciter.nim | 7 + tests/reject/trectype.nim | 21 +++ tests/reject/trefs.nim | 16 ++ tests/reject/tsidee1.nim | 11 ++ tests/reject/tsidee4.nim | 10 ++ tests/reject/tsimtych.nim | 5 + tests/reject/tstatret.nim | 5 + tests/reject/tstmtexp.nim | 3 + tests/reject/ttempl2.nim | 14 ++ tests/reject/tunderscores.nim | 7 + tests/reject/typredef.nim | 3 + tests/scantest.nim | 62 ------- tests/t99bott.nim | 28 --- tests/tack.nim | 15 -- tests/tadrdisc.nim | 16 -- tests/tambsym.nim | 8 - tests/tambsym2.nim | 18 -- tests/tambsym3.nim | 8 - tests/tambsys.nim | 7 - tests/tarray.nim | 27 --- tests/tarray2.nim | 18 -- tests/tarrindx.nim | 13 -- tests/tassert.nim | 16 -- tests/tassign.nim | 31 ---- tests/tbind1.nim | 14 -- tests/tbind2.nim | 10 -- tests/tbind3.nim | 5 - tests/tbind4.nim | 6 - tests/tbintre2.nim | 25 --- tests/tbintree.nim | 101 ----------- tests/tblock1.nim | 11 -- tests/tcasestm.nim | 32 ---- tests/tclosure.nim | 26 --- tests/tcmdline.nim | 14 -- tests/tcnstseq.nim | 11 -- tests/tcolors.nim | 39 ----- tests/tconsteval.nim | 28 --- tests/tconstr1.nim | 23 --- tests/tconstr2.nim | 20 --- tests/tconvert.nim | 38 ----- tests/tcopy.nim | 19 --- tests/tcurrncy.nim | 32 ---- tests/tdeprecated.nim | 6 - tests/tdialogs.nim | 17 -- tests/tdllvar.nim | 16 -- tests/tdumpast.nim | 35 ---- tests/techo.nim | 3 - tests/tendian.nim | 3 - tests/tenum.nim | 8 - tests/tester.nim | 4 +- tests/tfinally.nim | 10 -- tests/tfloat1.nim | 8 - tests/tfloat2.nim | 8 - tests/tformat.nim | 6 - tests/tforwty.nim | 9 - tests/tforwty2.nim | 22 --- tests/tgtk.nim | 61 ------- tests/thallo.nim | 83 --------- tests/thintoff.nim | 6 - tests/tident.nim | 22 --- tests/tillrec.nim | 10 -- tests/tindent1.nim | 24 --- tests/tinit.nim | 6 - tests/tinout.nim | 9 - tests/tints.nim | 41 ----- tests/tinvalidnewseq.nim | 20 --- tests/tinvwhen.nim | 8 - tests/tio.nim | 7 - tests/tisopr.nim | 20 --- tests/titer.nim | 44 ----- tests/titer2.nim | 10 -- tests/titer3.nim | 17 -- tests/titer4.nim | 3 - tests/titer5.nim | 10 -- tests/tlastmod.nim | 18 -- tests/tlibs.nim | 21 --- tests/tloops.nim | 64 ------- tests/tlowhigh.nim | 18 -- tests/tmath.nim | 85 ---------- tests/tmatrix.nim | 60 ------- tests/tmultim1.nim | 23 --- tests/tmultim2.nim | 30 ---- tests/tnamspc.nim | 5 - tests/tnestif.nim | 18 -- tests/tnestprc.nim | 10 -- tests/tnew.nim | 49 ------ tests/tnewlibs.nim | 16 -- tests/tnewsets.nim | 6 - tests/tnewuns.nim | 12 -- tests/tnoop.nim | 6 - tests/tnot.nim | 15 -- tests/tobjcov.nim | 17 -- tests/tobject2.nim | 21 --- tests/tobjects.nim | 42 ----- tests/toop1.nim | 82 --------- tests/topaque.nim | 11 -- tests/topena1.nim | 5 - tests/topenarrayrepr.nim | 11 -- tests/topenlen.nim | 12 -- tests/toptions.nim | 22 --- tests/tos.nim | 12 -- tests/toverflw.nim | 15 -- tests/toverl.nim | 6 - tests/toverl2.nim | 21 --- tests/toverlop.nim | 10 -- tests/toverprc.nim | 25 --- tests/toverwr.nim | 7 - tests/tovfint.nim | 17 -- tests/tparedef.nim | 4 - tests/tparscfg.nim | 25 --- tests/tparsefloat.nim | 3 - tests/tparsopt.nim | 27 --- tests/tpos.nim | 29 ---- tests/tposix.nim | 16 -- tests/tprep.nim | 28 --- tests/tprintf.nim | 10 -- tests/tprocvar.nim | 26 --- tests/tpush.nim | 15 -- tests/tquicksort.nim | 24 --- tests/tquit.nim | 6 - tests/tquotewords.nim | 19 --- tests/tradix.nim | 319 ----------------------------------- tests/trawstr.nim | 5 - tests/treadln.nim | 12 -- tests/treadx.nim | 12 -- tests/trecinca.nim | 5 - tests/trecincb.nim | 6 - tests/treciter.nim | 7 - tests/trecmod.nim | 2 - tests/trecmod2.nim | 10 -- tests/trectype.nim | 21 --- tests/trefs.nim | 16 -- tests/tregex.nim | 19 --- tests/treguse.nim | 21 --- tests/trepr.nim | 32 ---- tests/tromans.nim | 65 ------- tests/tseq2.nim | 13 -- tests/tseqcon.nim | 45 ----- tests/tseqcon2.nim | 9 - tests/tsets.nim | 58 ------- tests/tsidee1.nim | 11 -- tests/tsidee2.nim | 11 -- tests/tsidee3.nim | 11 -- tests/tsidee4.nim | 10 -- tests/tsimmeth.nim | 8 - tests/tsimtych.nim | 5 - tests/tsizeof.nim | 10 -- tests/tsockets.nim | 11 -- tests/tsplit.nim | 14 -- tests/tstatret.nim | 5 - tests/tstmtexp.nim | 3 - tests/tstrace.nim | 16 -- tests/tstrange.nim | 17 -- tests/tstrdesc.nim | 14 -- tests/tstrdist.nim | 26 --- tests/tstreams.nim | 7 - tests/tstrlits.nim | 14 -- tests/tstrset.nim | 74 -------- tests/tstrtabs.nim | 12 -- tests/tstrutil.nim | 24 --- tests/ttempl.nim | 27 --- tests/ttempl2.nim | 14 -- tests/ttempl3.nim | 26 --- tests/ttime.nim | 6 - tests/ttuple1.nim | 16 -- tests/tunderscores.nim | 7 - tests/tvardecl.nim | 9 - tests/tvarious.nim | 43 ----- tests/tvarnums.nim | 136 --------------- tests/tvartup.nim | 11 -- tests/twalker.nim | 13 -- tests/typalias.nim | 15 -- tests/typredef.nim | 3 - tests/x11test.nim | 6 +- web/news.txt | 1 + 336 files changed, 4002 insertions(+), 4034 deletions(-) delete mode 100644 tests/99bottles.nim create mode 100644 tests/accept/compile/tarrindx.nim create mode 100644 tests/accept/compile/tassign.nim create mode 100644 tests/accept/compile/tcmdline.nim create mode 100644 tests/accept/compile/tcolors.nim create mode 100644 tests/accept/compile/tconsteval.nim create mode 100644 tests/accept/compile/tconvert.nim create mode 100644 tests/accept/compile/tdeprecated.nim create mode 100644 tests/accept/compile/tdialogs.nim create mode 100644 tests/accept/compile/tdllvar.nim create mode 100644 tests/accept/compile/tdumpast.nim create mode 100644 tests/accept/compile/techo.nim create mode 100644 tests/accept/compile/tendian.nim create mode 100644 tests/accept/compile/tenum.nim create mode 100644 tests/accept/compile/tforwty.nim create mode 100644 tests/accept/compile/tforwty2.nim create mode 100644 tests/accept/compile/tgtk.nim create mode 100644 tests/accept/compile/thallo.nim create mode 100644 tests/accept/compile/tident.nim create mode 100644 tests/accept/compile/tindent1.nim create mode 100644 tests/accept/compile/tio.nim create mode 100644 tests/accept/compile/titer.nim create mode 100644 tests/accept/compile/tlastmod.nim create mode 100644 tests/accept/compile/tlexer.nim create mode 100644 tests/accept/compile/tlibs.nim create mode 100644 tests/accept/compile/tloops.nim create mode 100644 tests/accept/compile/tmath.nim create mode 100644 tests/accept/compile/tnew.nim create mode 100644 tests/accept/compile/tnewlibs.nim create mode 100644 tests/accept/compile/tnewsets.nim create mode 100644 tests/accept/compile/tnewuns.nim create mode 100644 tests/accept/compile/tobjcov.nim create mode 100644 tests/accept/compile/tobject2.nim create mode 100644 tests/accept/compile/tobjects.nim create mode 100644 tests/accept/compile/toptions.nim create mode 100644 tests/accept/compile/tos.nim create mode 100644 tests/accept/compile/toverprc.nim create mode 100644 tests/accept/compile/tparedef.nim create mode 100644 tests/accept/compile/tparscfg.nim create mode 100644 tests/accept/compile/tparsefloat.nim create mode 100644 tests/accept/compile/tparsopt.nim create mode 100644 tests/accept/compile/tposix.nim create mode 100644 tests/accept/compile/tprep.nim create mode 100644 tests/accept/compile/tpush.nim create mode 100644 tests/accept/compile/tquicksort.nim create mode 100644 tests/accept/compile/tquit.nim create mode 100644 tests/accept/compile/tradix.nim create mode 100644 tests/accept/compile/treadln.nim create mode 100644 tests/accept/compile/treadx.nim create mode 100644 tests/accept/compile/trecmod.nim create mode 100644 tests/accept/compile/trecmod2.nim create mode 100644 tests/accept/compile/trepr.nim create mode 100644 tests/accept/compile/tseq2.nim create mode 100644 tests/accept/compile/tseqcon2.nim create mode 100644 tests/accept/compile/tsizeof.nim create mode 100644 tests/accept/compile/tsockets.nim create mode 100644 tests/accept/compile/tstrace.nim create mode 100644 tests/accept/compile/tstrdesc.nim create mode 100644 tests/accept/compile/tstrdist.nim create mode 100644 tests/accept/compile/tstreams.nim create mode 100644 tests/accept/compile/tstrset.nim create mode 100644 tests/accept/compile/tstrtabs.nim create mode 100644 tests/accept/compile/ttempl.nim create mode 100644 tests/accept/compile/ttempl3.nim create mode 100644 tests/accept/compile/ttime.nim create mode 100644 tests/accept/compile/ttuple1.nim create mode 100644 tests/accept/compile/tvarious.nim create mode 100644 tests/accept/compile/twalker.nim create mode 100644 tests/accept/compile/typalias.nim create mode 100644 tests/accept/run/tack.nim create mode 100644 tests/accept/run/tambsym2.nim create mode 100644 tests/accept/run/tambsys.nim create mode 100644 tests/accept/run/tarray.nim create mode 100644 tests/accept/run/tarray2.nim create mode 100644 tests/accept/run/tassert.nim create mode 100644 tests/accept/run/tbind1.nim create mode 100644 tests/accept/run/tbind3.nim create mode 100644 tests/accept/run/tbintre2.nim create mode 100644 tests/accept/run/tbintree.nim create mode 100644 tests/accept/run/tcasestm.nim create mode 100644 tests/accept/run/tclosure.nim create mode 100644 tests/accept/run/tcnstseq.nim create mode 100644 tests/accept/run/tconstr2.nim create mode 100644 tests/accept/run/tcopy.nim create mode 100644 tests/accept/run/tcurrncy.nim create mode 100644 tests/accept/run/tfinally.nim create mode 100644 tests/accept/run/tfloat1.nim create mode 100644 tests/accept/run/tfloat2.nim create mode 100644 tests/accept/run/tformat.nim create mode 100644 tests/accept/run/thintoff.nim create mode 100644 tests/accept/run/tinit.nim create mode 100644 tests/accept/run/tints.nim create mode 100644 tests/accept/run/tisopr.nim create mode 100644 tests/accept/run/titer2.nim create mode 100644 tests/accept/run/titer3.nim create mode 100644 tests/accept/run/titer5.nim create mode 100644 tests/accept/run/tlowhigh.nim create mode 100644 tests/accept/run/tmatrix.nim create mode 100644 tests/accept/run/tmultim1.nim create mode 100644 tests/accept/run/tmultim2.nim create mode 100644 tests/accept/run/tnestif.nim create mode 100644 tests/accept/run/tnestprc.nim create mode 100644 tests/accept/run/toop1.nim create mode 100644 tests/accept/run/topenarrayrepr.nim create mode 100644 tests/accept/run/topenlen.nim create mode 100644 tests/accept/run/toverflw.nim create mode 100644 tests/accept/run/toverl2.nim create mode 100644 tests/accept/run/toverlop.nim create mode 100644 tests/accept/run/toverwr.nim create mode 100644 tests/accept/run/tovfint.nim create mode 100644 tests/accept/run/tpos.nim create mode 100644 tests/accept/run/tprintf.nim create mode 100644 tests/accept/run/tprocvar.nim create mode 100644 tests/accept/run/tquotewords.nim create mode 100644 tests/accept/run/tregex.nim create mode 100644 tests/accept/run/treguse.nim create mode 100644 tests/accept/run/tromans.nim create mode 100644 tests/accept/run/tseqcon.nim create mode 100644 tests/accept/run/tsets.nim create mode 100644 tests/accept/run/tsidee2.nim create mode 100644 tests/accept/run/tsidee3.nim create mode 100644 tests/accept/run/tsimmeth.nim create mode 100644 tests/accept/run/tsplit.nim create mode 100644 tests/accept/run/tstrange.nim create mode 100644 tests/accept/run/tstrlits.nim create mode 100644 tests/accept/run/tstrutil.nim create mode 100644 tests/accept/run/tvardecl.nim create mode 100644 tests/accept/run/tvarnums.nim create mode 100644 tests/accept/run/tvartup.nim create mode 100644 tests/gc/gcbench.nim create mode 100644 tests/gc/gctest.nim delete mode 100644 tests/gcbench.nim delete mode 100644 tests/gctest.nim delete mode 100644 tests/mbind3.nim delete mode 100644 tests/mbind4.nim delete mode 100644 tests/mvarious.nim create mode 100644 tests/reject/99bottles.nim create mode 100644 tests/reject/t99bott.nim create mode 100644 tests/reject/tadrdisc.nim create mode 100644 tests/reject/tambsym.nim create mode 100644 tests/reject/tambsym3.nim create mode 100644 tests/reject/tbind2.nim create mode 100644 tests/reject/tbind4.nim create mode 100644 tests/reject/tblock1.nim create mode 100644 tests/reject/tconstr1.nim create mode 100644 tests/reject/tillrec.nim create mode 100644 tests/reject/tinout.nim create mode 100644 tests/reject/tinvalidnewseq.nim create mode 100644 tests/reject/tinvwhen.nim create mode 100644 tests/reject/titer4.nim create mode 100644 tests/reject/tnamspc.nim create mode 100644 tests/reject/tnoop.nim create mode 100644 tests/reject/tnot.nim create mode 100644 tests/reject/topaque.nim create mode 100644 tests/reject/topena1.nim create mode 100644 tests/reject/toverl.nim create mode 100644 tests/reject/trawstr.nim create mode 100644 tests/reject/trecinca.nim create mode 100644 tests/reject/trecincb.nim create mode 100644 tests/reject/treciter.nim create mode 100644 tests/reject/trectype.nim create mode 100644 tests/reject/trefs.nim create mode 100644 tests/reject/tsidee1.nim create mode 100644 tests/reject/tsidee4.nim create mode 100644 tests/reject/tsimtych.nim create mode 100644 tests/reject/tstatret.nim create mode 100644 tests/reject/tstmtexp.nim create mode 100644 tests/reject/ttempl2.nim create mode 100644 tests/reject/tunderscores.nim create mode 100644 tests/reject/typredef.nim delete mode 100644 tests/scantest.nim delete mode 100644 tests/t99bott.nim delete mode 100644 tests/tack.nim delete mode 100644 tests/tadrdisc.nim delete mode 100644 tests/tambsym.nim delete mode 100644 tests/tambsym2.nim delete mode 100644 tests/tambsym3.nim delete mode 100644 tests/tambsys.nim delete mode 100644 tests/tarray.nim delete mode 100644 tests/tarray2.nim delete mode 100644 tests/tarrindx.nim delete mode 100644 tests/tassert.nim delete mode 100644 tests/tassign.nim delete mode 100644 tests/tbind1.nim delete mode 100644 tests/tbind2.nim delete mode 100644 tests/tbind3.nim delete mode 100644 tests/tbind4.nim delete mode 100644 tests/tbintre2.nim delete mode 100644 tests/tbintree.nim delete mode 100644 tests/tblock1.nim delete mode 100644 tests/tcasestm.nim delete mode 100644 tests/tclosure.nim delete mode 100644 tests/tcmdline.nim delete mode 100644 tests/tcnstseq.nim delete mode 100644 tests/tcolors.nim delete mode 100644 tests/tconsteval.nim delete mode 100644 tests/tconstr1.nim delete mode 100644 tests/tconstr2.nim delete mode 100644 tests/tconvert.nim delete mode 100644 tests/tcopy.nim delete mode 100644 tests/tcurrncy.nim delete mode 100644 tests/tdeprecated.nim delete mode 100644 tests/tdialogs.nim delete mode 100644 tests/tdllvar.nim delete mode 100644 tests/tdumpast.nim delete mode 100644 tests/techo.nim delete mode 100644 tests/tendian.nim delete mode 100644 tests/tenum.nim delete mode 100644 tests/tfinally.nim delete mode 100644 tests/tfloat1.nim delete mode 100644 tests/tfloat2.nim delete mode 100644 tests/tformat.nim delete mode 100644 tests/tforwty.nim delete mode 100644 tests/tforwty2.nim delete mode 100644 tests/tgtk.nim delete mode 100644 tests/thallo.nim delete mode 100644 tests/thintoff.nim delete mode 100644 tests/tident.nim delete mode 100644 tests/tillrec.nim delete mode 100644 tests/tindent1.nim delete mode 100644 tests/tinit.nim delete mode 100644 tests/tinout.nim delete mode 100644 tests/tints.nim delete mode 100644 tests/tinvalidnewseq.nim delete mode 100644 tests/tinvwhen.nim delete mode 100644 tests/tio.nim delete mode 100644 tests/tisopr.nim delete mode 100644 tests/titer.nim delete mode 100644 tests/titer2.nim delete mode 100644 tests/titer3.nim delete mode 100644 tests/titer4.nim delete mode 100644 tests/titer5.nim delete mode 100644 tests/tlastmod.nim delete mode 100644 tests/tlibs.nim delete mode 100644 tests/tloops.nim delete mode 100644 tests/tlowhigh.nim delete mode 100644 tests/tmath.nim delete mode 100644 tests/tmatrix.nim delete mode 100644 tests/tmultim1.nim delete mode 100644 tests/tmultim2.nim delete mode 100644 tests/tnamspc.nim delete mode 100644 tests/tnestif.nim delete mode 100644 tests/tnestprc.nim delete mode 100644 tests/tnew.nim delete mode 100644 tests/tnewlibs.nim delete mode 100644 tests/tnewsets.nim delete mode 100644 tests/tnewuns.nim delete mode 100644 tests/tnoop.nim delete mode 100644 tests/tnot.nim delete mode 100644 tests/tobjcov.nim delete mode 100644 tests/tobject2.nim delete mode 100644 tests/tobjects.nim delete mode 100644 tests/toop1.nim delete mode 100644 tests/topaque.nim delete mode 100644 tests/topena1.nim delete mode 100644 tests/topenarrayrepr.nim delete mode 100644 tests/topenlen.nim delete mode 100644 tests/toptions.nim delete mode 100644 tests/tos.nim delete mode 100644 tests/toverflw.nim delete mode 100644 tests/toverl.nim delete mode 100644 tests/toverl2.nim delete mode 100644 tests/toverlop.nim delete mode 100644 tests/toverprc.nim delete mode 100644 tests/toverwr.nim delete mode 100644 tests/tovfint.nim delete mode 100644 tests/tparedef.nim delete mode 100644 tests/tparscfg.nim delete mode 100644 tests/tparsefloat.nim delete mode 100644 tests/tparsopt.nim delete mode 100644 tests/tpos.nim delete mode 100644 tests/tposix.nim delete mode 100644 tests/tprep.nim delete mode 100644 tests/tprintf.nim delete mode 100644 tests/tprocvar.nim delete mode 100644 tests/tpush.nim delete mode 100644 tests/tquicksort.nim delete mode 100644 tests/tquit.nim delete mode 100644 tests/tquotewords.nim delete mode 100644 tests/tradix.nim delete mode 100644 tests/trawstr.nim delete mode 100644 tests/treadln.nim delete mode 100644 tests/treadx.nim delete mode 100644 tests/trecinca.nim delete mode 100644 tests/trecincb.nim delete mode 100644 tests/treciter.nim delete mode 100644 tests/trecmod.nim delete mode 100644 tests/trecmod2.nim delete mode 100644 tests/trectype.nim delete mode 100644 tests/trefs.nim delete mode 100644 tests/tregex.nim delete mode 100644 tests/treguse.nim delete mode 100644 tests/trepr.nim delete mode 100644 tests/tromans.nim delete mode 100644 tests/tseq2.nim delete mode 100644 tests/tseqcon.nim delete mode 100644 tests/tseqcon2.nim delete mode 100644 tests/tsets.nim delete mode 100644 tests/tsidee1.nim delete mode 100644 tests/tsidee2.nim delete mode 100644 tests/tsidee3.nim delete mode 100644 tests/tsidee4.nim delete mode 100644 tests/tsimmeth.nim delete mode 100644 tests/tsimtych.nim delete mode 100644 tests/tsizeof.nim delete mode 100644 tests/tsockets.nim delete mode 100644 tests/tsplit.nim delete mode 100644 tests/tstatret.nim delete mode 100644 tests/tstmtexp.nim delete mode 100644 tests/tstrace.nim delete mode 100644 tests/tstrange.nim delete mode 100644 tests/tstrdesc.nim delete mode 100644 tests/tstrdist.nim delete mode 100644 tests/tstreams.nim delete mode 100644 tests/tstrlits.nim delete mode 100644 tests/tstrset.nim delete mode 100644 tests/tstrtabs.nim delete mode 100644 tests/tstrutil.nim delete mode 100644 tests/ttempl.nim delete mode 100644 tests/ttempl2.nim delete mode 100644 tests/ttempl3.nim delete mode 100644 tests/ttime.nim delete mode 100644 tests/ttuple1.nim delete mode 100644 tests/tunderscores.nim delete mode 100644 tests/tvardecl.nim delete mode 100644 tests/tvarious.nim delete mode 100644 tests/tvarnums.nim delete mode 100644 tests/tvartup.nim delete mode 100644 tests/twalker.nim delete mode 100644 tests/typalias.nim delete mode 100644 tests/typredef.nim diff --git a/lib/newwrap/sqlite3.nim b/lib/newwrap/sqlite3.nim index f2912f05f..23aaf091d 100644 --- a/lib/newwrap/sqlite3.nim +++ b/lib/newwrap/sqlite3.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2009 Andreas Rumpf +# (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -17,13 +17,13 @@ elif defined(macosx): else: const Lib = "libsqlite3.so" + const SQLITE_INTEGER* = 1 SQLITE_FLOAT* = 2 SQLITE_BLOB* = 4 SQLITE_NULL* = 5 SQLITE_TEXT* = 3 - TEXT* = 3 SQLITE_UTF8* = 1 SQLITE_UTF16LE* = 2 SQLITE_UTF16BE* = 3 # Use native byte order @@ -98,9 +98,9 @@ const type sqlite_int64* = int64 PPPChar* = ptr ptr cstring - T{.pure, final.} = object - P* = ptr T - PPSqlite3* = ptr P + TSqlite3 {.pure, final.} = object + PSqlite3* = ptr TSqlite3 + PPSqlite3* = ptr PSqlite3 TSqlLite3Context{.pure, final.} = object Pcontext* = ptr TSqlLite3Context Tstmt{.pure, final.} = object @@ -124,30 +124,30 @@ type Tresult_func* = proc (para1: pointer){.cdecl.} Tcreate_collation_func* = proc (para1: pointer, para2: int32, para3: pointer, para4: int32, para5: pointer): int32{.cdecl.} - Tcollation_needed_func* = proc (para1: pointer, para2: P, eTextRep: int32, + Tcollation_needed_func* = proc (para1: pointer, para2: PSqlite3, eTextRep: int32, para4: cstring){.cdecl.} -proc close*(para1: P): int32{.cdecl, dynlib: Lib, importc: "sqlite3_close".} -proc exec*(para1: P, sql: cstring, para3: Tcallback, para4: pointer, +proc close*(para1: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_close".} +proc exec*(para1: PSqlite3, sql: cstring, para3: Tcallback, para4: pointer, errmsg: var cstring): int32{.cdecl, dynlib: Lib, importc: "sqlite3_exec".} -proc last_insert_rowid*(para1: P): sqlite_int64{.cdecl, dynlib: Lib, +proc last_insert_rowid*(para1: PSqlite3): sqlite_int64{.cdecl, dynlib: Lib, importc: "sqlite3_last_insert_rowid".} -proc changes*(para1: P): int32{.cdecl, dynlib: Lib, importc: "sqlite3_changes".} -proc total_changes*(para1: P): int32{.cdecl, dynlib: Lib, +proc changes*(para1: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_changes".} +proc total_changes*(para1: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_total_changes".} -proc interrupt*(para1: P){.cdecl, dynlib: Lib, importc: "sqlite3_interrupt".} +proc interrupt*(para1: PSqlite3){.cdecl, dynlib: Lib, importc: "sqlite3_interrupt".} proc complete*(sql: cstring): int32{.cdecl, dynlib: Lib, importc: "sqlite3_complete".} proc complete16*(sql: pointer): int32{.cdecl, dynlib: Lib, importc: "sqlite3_complete16".} -proc busy_handler*(para1: P, +proc busy_handler*(para1: PSqlite3, para2: proc (para1: pointer, para2: int32): int32{.cdecl.}, para3: pointer): int32{.cdecl, dynlib: Lib, importc: "sqlite3_busy_handler".} -proc busy_timeout*(para1: P, ms: int32): int32{.cdecl, dynlib: Lib, +proc busy_timeout*(para1: PSqlite3, ms: int32): int32{.cdecl, dynlib: Lib, importc: "sqlite3_busy_timeout".} -proc get_table*(para1: P, sql: cstring, resultp: var cstringArray, +proc get_table*(para1: PSqlite3, sql: cstring, resultp: var cstringArray, nrow, ncolumn: var cint, errmsg: ptr cstring): int32{.cdecl, dynlib: Lib, importc: "sqlite3_get_table".} proc free_table*(result: cstringArray){.cdecl, dynlib: Lib, @@ -161,32 +161,32 @@ proc free*(z: cstring){.cdecl, dynlib: Lib, importc: "sqlite3_free".} #function sqlite3_snprintf(_para1:longint; _para2:Pchar; _para3:Pchar; args:array of const):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_snprintf'; proc snprintf*(para1: int32, para2: cstring, para3: cstring): cstring{.cdecl, dynlib: Lib, varargs, importc: "sqlite3_snprintf".} -proc set_authorizer*(para1: P, xAuth: proc (para1: pointer, para2: int32, +proc set_authorizer*(para1: PSqlite3, xAuth: proc (para1: pointer, para2: int32, para3: cstring, para4: cstring, para5: cstring, para6: cstring): int32{. cdecl.}, pUserData: pointer): int32{.cdecl, dynlib: Lib, importc: "sqlite3_set_authorizer".} -proc trace*(para1: P, xTrace: proc (para1: pointer, para2: cstring){.cdecl.}, +proc trace*(para1: PSqlite3, xTrace: proc (para1: pointer, para2: cstring){.cdecl.}, para3: pointer): pointer{.cdecl, dynlib: Lib, importc: "sqlite3_trace".} -proc progress_handler*(para1: P, para2: int32, +proc progress_handler*(para1: PSqlite3, para2: int32, para3: proc (para1: pointer): int32{.cdecl.}, para4: pointer){.cdecl, dynlib: Lib, importc: "sqlite3_progress_handler".} -proc commit_hook*(para1: P, para2: proc (para1: pointer): int32{.cdecl.}, +proc commit_hook*(para1: PSqlite3, para2: proc (para1: pointer): int32{.cdecl.}, para3: pointer): pointer{.cdecl, dynlib: Lib, importc: "sqlite3_commit_hook".} -proc open*(filename: cstring, ppDb: var P): int32{.cdecl, dynlib: Lib, +proc open*(filename: cstring, ppDb: var PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_open".} -proc open16*(filename: pointer, ppDb: var P): int32{.cdecl, dynlib: Lib, +proc open16*(filename: pointer, ppDb: var PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_open16".} -proc errcode*(db: P): int32{.cdecl, dynlib: Lib, importc: "sqlite3_errcode".} -proc errmsg*(para1: P): cstring{.cdecl, dynlib: Lib, importc: "sqlite3_errmsg".} -proc errmsg16*(para1: P): pointer{.cdecl, dynlib: Lib, +proc errcode*(db: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_errcode".} +proc errmsg*(para1: PSqlite3): cstring{.cdecl, dynlib: Lib, importc: "sqlite3_errmsg".} +proc errmsg16*(para1: PSqlite3): pointer{.cdecl, dynlib: Lib, importc: "sqlite3_errmsg16".} -proc prepare*(db: P, zSql: cstring, nBytes: int32, ppStmt: PPsqlite3_stmt, +proc prepare*(db: PSqlite3, zSql: cstring, nBytes: int32, ppStmt: PPsqlite3_stmt, pzTail: ptr cstring): int32{.cdecl, dynlib: Lib, importc: "sqlite3_prepare".} -proc prepare16*(db: P, zSql: pointer, nBytes: int32, ppStmt: PPsqlite3_stmt, +proc prepare16*(db: PSqlite3, zSql: pointer, nBytes: int32, ppStmt: PPsqlite3_stmt, pzTail: var pointer): int32{.cdecl, dynlib: Lib, importc: "sqlite3_prepare16".} proc bind_blob*(para1: Pstmt, para2: int32, para3: pointer, n: int32, @@ -259,13 +259,13 @@ proc column_type*(para1: Pstmt, iCol: int32): int32{.cdecl, dynlib: Lib, proc finalize*(pStmt: Pstmt): int32{.cdecl, dynlib: Lib, importc: "sqlite3_finalize".} proc reset*(pStmt: Pstmt): int32{.cdecl, dynlib: Lib, importc: "sqlite3_reset".} -proc create_function*(para1: P, zFunctionName: cstring, nArg: int32, +proc create_function*(para1: PSqlite3, zFunctionName: cstring, nArg: int32, eTextRep: int32, para5: pointer, xFunc: Tcreate_function_func_func, xStep: Tcreate_function_step_func, xFinal: Tcreate_function_final_func): int32{.cdecl, dynlib: Lib, importc: "sqlite3_create_function".} -proc create_function16*(para1: P, zFunctionName: pointer, nArg: int32, +proc create_function16*(para1: PSqlite3, zFunctionName: pointer, nArg: int32, eTextRep: int32, para5: pointer, xFunc: Tcreate_function_func_func, xStep: Tcreate_function_step_func, @@ -333,15 +333,15 @@ proc result_text16be*(para1: Pcontext, para2: pointer, para3: int32, importc: "sqlite3_result_text16be".} proc result_value*(para1: Pcontext, para2: Pvalue){.cdecl, dynlib: Lib, importc: "sqlite3_result_value".} -proc create_collation*(para1: P, zName: cstring, eTextRep: int32, +proc create_collation*(para1: PSqlite3, zName: cstring, eTextRep: int32, para4: pointer, xCompare: Tcreate_collation_func): int32{. cdecl, dynlib: Lib, importc: "sqlite3_create_collation".} -proc create_collation16*(para1: P, zName: cstring, eTextRep: int32, +proc create_collation16*(para1: PSqlite3, zName: cstring, eTextRep: int32, para4: pointer, xCompare: Tcreate_collation_func): int32{. cdecl, dynlib: Lib, importc: "sqlite3_create_collation16".} -proc collation_needed*(para1: P, para2: pointer, para3: Tcollation_needed_func): int32{. +proc collation_needed*(para1: PSqlite3, para2: pointer, para3: Tcollation_needed_func): int32{. cdecl, dynlib: Lib, importc: "sqlite3_collation_needed".} -proc collation_needed16*(para1: P, para2: pointer, para3: Tcollation_needed_func): int32{. +proc collation_needed16*(para1: PSqlite3, para2: pointer, para3: Tcollation_needed_func): int32{. cdecl, dynlib: Lib, importc: "sqlite3_collation_needed16".} proc libversion*(): cstring{.cdecl, dynlib: Lib, importc: "sqlite3_libversion".} #Alias for allowing better code portability (win32 is not working with external variables) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index a54af3254..70cb038a7 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -196,7 +196,11 @@ when not defined(ECMAScript): proc `-` (a, b: TTime): int64 = return toBiggestInt(difftime(a, b)) - proc getStartMilsecs(): int = return clock() div (clocksPerSec div 1000) + proc getStartMilsecs(): int = + #echo "clocks per sec: ", clocksPerSec + #return clock() div (clocksPerSec div 1000) + result = toInt(toFloat(clock()) / (toFloat(clocksPerSec) / 1000.0)) + proc getTime(): TTime = return timec(nil) proc getLocalTime(t: TTime): TTimeInfo = var a = t diff --git a/tests/99bottles.nim b/tests/99bottles.nim deleted file mode 100644 index 14904ac0f..000000000 --- a/tests/99bottles.nim +++ /dev/null @@ -1 +0,0 @@ -# Test if the compiler detects invalid module names diff --git a/tests/accept/compile/tarrindx.nim b/tests/accept/compile/tarrindx.nim new file mode 100644 index 000000000..13919cc2c --- /dev/null +++ b/tests/accept/compile/tarrindx.nim @@ -0,0 +1,13 @@ +# test another strange bug ... (I hate this compiler; it is much too buggy!) + +proc putEnv(key, val: string) = + # XXX: we have to leak memory here, as we cannot + # free it before the program ends (says Borland's + # documentation) + var + env: ptr array[0..500000, char] + env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2)) + for i in 0..len(key)-1: env[i] = key[i] + env[len(key)] = '=' + for i in 0..len(val)-1: + env[len(key)+1+i] = val[i] diff --git a/tests/accept/compile/tassign.nim b/tests/accept/compile/tassign.nim new file mode 100644 index 000000000..f51c20783 --- /dev/null +++ b/tests/accept/compile/tassign.nim @@ -0,0 +1,31 @@ +# Test the assignment operator for complex types which need RTTI + +type + TRec = object + x, y: int + s: string + seq: seq[string] + arr: seq[seq[array[0..3, string]]] + TRecSeq = seq[TRec] + +proc test() = + var + a, b: TRec + a.x = 1 + a.y = 2 + a.s = "Hallo!" + a.seq = @["abc", "def", "ghi", "jkl"] + a.arr = @[] + setLen(a.arr, 4) + a.arr[0] = @[] + a.arr[1] = @[] + + b = a # perform a deep copy here! + b.seq = @["xyz", "huch", "was", "soll"] + writeln(stdout, len(a.seq)) + writeln(stdout, a.seq[3]) + writeln(stdout, len(b.seq)) + writeln(stdout, b.seq[3]) + writeln(stdout, b.y) + +test() diff --git a/tests/accept/compile/tcmdline.nim b/tests/accept/compile/tcmdline.nim new file mode 100644 index 000000000..f43aecafa --- /dev/null +++ b/tests/accept/compile/tcmdline.nim @@ -0,0 +1,14 @@ +# Test the command line + +import + os, strutils + +var + i: int + params = paramCount() +i = 0 +writeln(stdout, "This exe: " & getApplicationFilename()) +writeln(stdout, "Number of parameters: " & $params) +while i <= params: + writeln(stdout, paramStr(i)) + i = i + 1 diff --git a/tests/accept/compile/tcolors.nim b/tests/accept/compile/tcolors.nim new file mode 100644 index 000000000..9d1034405 --- /dev/null +++ b/tests/accept/compile/tcolors.nim @@ -0,0 +1,39 @@ +import strutils + +type + TColor = distinct int32 + +proc rgb(r, g, b: range[0..255]): TColor = + result = TColor(r or g shl 8 or b shl 16) + +proc `$`(c: TColor): string = + result = "#" & toHex(int32(c), 6) + +echo rgb(34, 55, 255) + +when false: + type + TColor = distinct int32 + TColorComponent = distinct int8 + + proc red(a: TColor): TColorComponent = + result = TColorComponent(int32(a) and 0xff'i32) + + proc green(a: TColor): TColorComponent = + result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32) + + proc blue(a: TColor): TColorComponent = + result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32) + + proc rgb(r, g, b: range[0..255]): TColor = + result = TColor(r or g shl 8 or b shl 8) + + proc `+!` (a, b: TColorComponent): TColorComponent = + ## saturated arithmetic: + result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255)) + + proc `+` (a, b: TColor): TColor = + ## saturated arithmetic for colors makes sense, I think: + return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b)) + + rgb(34, 55, 255) diff --git a/tests/accept/compile/tconsteval.nim b/tests/accept/compile/tconsteval.nim new file mode 100644 index 000000000..ce90d7c27 --- /dev/null +++ b/tests/accept/compile/tconsteval.nim @@ -0,0 +1,28 @@ +import strutils + +const + HelpText = """ ++-----------------------------------------------------------------+ +| Maintenance program for Nimrod | +| Version $1| +| (c) 2009 Andreas Rumpf | ++-----------------------------------------------------------------+ +Compiled at: $2, $3 + +Usage: + koch [options] command [options for command] +Options: + --force, -f, -B, -b forces rebuild + --help, -h shows this help and quits +Possible Commands: + boot [options] bootstraps with given command line options + clean cleans Nimrod project; removes generated files + web generates the website + csource [options] builds the C sources for installation + zip builds the installation ZIP package + inno builds the Inno Setup installer +""" % [NimrodVersion & repeatChar(44-len(NimrodVersion)), + CompileDate, CompileTime] + +echo helpText + diff --git a/tests/accept/compile/tconvert.nim b/tests/accept/compile/tconvert.nim new file mode 100644 index 000000000..b23afde74 --- /dev/null +++ b/tests/accept/compile/tconvert.nim @@ -0,0 +1,38 @@ +import + Cairo + +converter FloatConversion64(x: int): float64 = return toFloat(x) +converter FloatConversion32(x: int): float32 = return toFloat(x) +converter FloatConversionPlain(x: int): float = return toFloat(x) + +const width = 500 +const height = 500 +const outFile = "CairoTest.png" + +var surface = Cairo_ImageSurfaceCreate(CAIRO_FORMAT_RGB24, width, height) +var ç = Cairo_Create(surface) + +ç.Cairo_SetSourceRGB(1, 1, 1) +ç.Cairo_Paint() + +ç.Cairo_SetLineWidth(10) +ç.Cairo_SetLineCap(CAIRO_LINE_CAP_ROUND) + +const count = 12 +var winc = width / count +var hinc = width / count +for i in 1 .. count-1: + var amount = i / count + ç.Cairo_SetSourceRGB(0, 1 - amount, amount) + ç.Cairo_MoveTo(i * winc, hinc) + ç.Cairo_LineTo(width - i * winc, height - hinc) + ç.Cairo_Stroke() + + ç.Cairo_SetSourceRGB(1 - amount, 0, amount) + ç.Cairo_MoveTo(winc, i * hinc) + ç.Cairo_LineTo(width - winc, height - i * hinc) + ç.Cairo_Stroke() + +echo(surface.Cairo_SurfaceWriteToPNG(outFile)) +surface.Cairo_SurfaceDestroy() + diff --git a/tests/accept/compile/tdeprecated.nim b/tests/accept/compile/tdeprecated.nim new file mode 100644 index 000000000..e287da3f9 --- /dev/null +++ b/tests/accept/compile/tdeprecated.nim @@ -0,0 +1,6 @@ +var + a {.deprecated.}: array[0..11, int] + +a[8] = 1 + + diff --git a/tests/accept/compile/tdialogs.nim b/tests/accept/compile/tdialogs.nim new file mode 100644 index 000000000..90f241cdf --- /dev/null +++ b/tests/accept/compile/tdialogs.nim @@ -0,0 +1,17 @@ +# Test the dialogs module + +import dialogs, gtk2 + +gtk_nimrod_init() + +var x = ChooseFilesToOpen(nil) +for a in items(x): + writeln(stdout, a) + +info(nil, "start with an info box") +warning(nil, "now a warning ...") +error(nil, "... and an error!") + +writeln(stdout, ChooseFileToOpen(nil)) +writeln(stdout, ChooseFileToSave(nil)) +writeln(stdout, ChooseDir(nil)) diff --git a/tests/accept/compile/tdllvar.nim b/tests/accept/compile/tdllvar.nim new file mode 100644 index 000000000..ab767770c --- /dev/null +++ b/tests/accept/compile/tdllvar.nim @@ -0,0 +1,16 @@ +import os + +proc getDllName: string = + result = "mylib.dll" + if ExistsFile(result): return + result = "mylib2.dll" + if ExistsFile(result): return + quit("could not load dynamic library") + +proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().} +proc myImport2(s: int) {.cdecl, importc, dynlib: getDllName().} + +myImport("test2") +myImport2(12) + + diff --git a/tests/accept/compile/tdumpast.nim b/tests/accept/compile/tdumpast.nim new file mode 100644 index 000000000..fb31af0ec --- /dev/null +++ b/tests/accept/compile/tdumpast.nim @@ -0,0 +1,35 @@ +# Dump the contents of a PNimrodNode + +import macros + +proc dumpit(n: PNimrodNode): string {.compileTime.} = + if n == nil: return "nil" + result = $n.kind + add(result, "(") + case n.kind + of nnkEmpty: nil # same as nil node in this representation + of nnkNilLit: add(result, "nil") + of nnkCharLit..nnkInt64Lit: add(result, $n.intVal) + of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal) + of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal) + of nnkIdent: add(result, $n.ident) + of nnkSym, nnkNone: assert false + else: + add(result, dumpit(n[0])) + for j in 1..n.len-1: + add(result, ", ") + add(result, dumpit(n[j])) + add(result, ")") + +macro dumpAST(n: stmt): stmt = + # dump AST as a side-effect and return the inner node + echo dumpit(n) + result = n[1] + +dumpAST: + proc add(x, y: int): int = + return x + y + + proc sub(x, y: int): int = return x - y + + diff --git a/tests/accept/compile/techo.nim b/tests/accept/compile/techo.nim new file mode 100644 index 000000000..beb21fa16 --- /dev/null +++ b/tests/accept/compile/techo.nim @@ -0,0 +1,3 @@ +# Simplest Nimrod program + +echo "Hallo, World!" diff --git a/tests/accept/compile/tendian.nim b/tests/accept/compile/tendian.nim new file mode 100644 index 000000000..256e2653c --- /dev/null +++ b/tests/accept/compile/tendian.nim @@ -0,0 +1,3 @@ +# test the new endian magic + +writeln(stdout, repr(system.cpuEndian)) diff --git a/tests/accept/compile/tenum.nim b/tests/accept/compile/tenum.nim new file mode 100644 index 000000000..6e53b9c08 --- /dev/null +++ b/tests/accept/compile/tenum.nim @@ -0,0 +1,8 @@ +# Test enums + +type + E = enum a, b, c, x, y, z + +var + en: E +en = a diff --git a/tests/accept/compile/tforwty.nim b/tests/accept/compile/tforwty.nim new file mode 100644 index 000000000..0f1d3697f --- /dev/null +++ b/tests/accept/compile/tforwty.nim @@ -0,0 +1,9 @@ +# Test 13: forward types + +type + PSym = ref TSym + + TSym = object + next: PSym + +var s: PSym diff --git a/tests/accept/compile/tforwty2.nim b/tests/accept/compile/tforwty2.nim new file mode 100644 index 000000000..5d15e112a --- /dev/null +++ b/tests/accept/compile/tforwty2.nim @@ -0,0 +1,22 @@ +# Test for a hard to fix internal error +# occured in the SDL library + +{.push dynlib: "SDL.dll", callconv: cdecl.} + +type + PSDL_semaphore = ptr TSDL_semaphore + TSDL_semaphore {.final.} = object + sem: Pointer #PSem_t; + when not defined(USE_NAMED_SEMAPHORES): + sem_data: int + when defined(BROKEN_SEMGETVALUE): + # This is a little hack for MacOS X - + # It's not thread-safe, but it's better than nothing + sem_value: cint + +type + PSDL_Sem = ptr TSDL_Sem + TSDL_Sem = TSDL_Semaphore + +proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {. + importc: "SDL_CreateSemaphore".} diff --git a/tests/accept/compile/tgtk.nim b/tests/accept/compile/tgtk.nim new file mode 100644 index 000000000..cd9254e4f --- /dev/null +++ b/tests/accept/compile/tgtk.nim @@ -0,0 +1,61 @@ + +import + gtk2, glib2, atk, gdk2, gdk2pixbuf, libglade2, pango, + pangoutils + +proc hello(widget: PGtkWidget, data: pointer) {.cdecl.} = + write(stdout, "Hello World\n") + +proc delete_event(widget: PGtkWidget, event: PGdkEvent, + data: pointer): bool {.cdecl.} = + # If you return FALSE in the "delete_event" signal handler, + # GTK will emit the "destroy" signal. Returning TRUE means + # you don't want the window to be destroyed. + # This is useful for popping up 'are you sure you want to quit?' + # type dialogs. + write(stdout, "delete event occurred\n") + # Change TRUE to FALSE and the main window will be destroyed with + # a "delete_event". + return false + +# Another callback +proc destroy(widget: PGtkWidget, data: pointer) {.cdecl.} = + gtk_main_quit() + +proc main() = + # GtkWidget is the storage type for widgets + var + window: PGtkWindow + button: PGtkButton + + gtk_nimrod_init() + window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)) + discard g_signal_connect(window, "delete_event", + Gcallback(delete_event), nil) + discard g_signal_connect(window, "destroy", Gcallback(destroy), nil) + # Sets the border width of the window. + gtk_container_set_border_width(window, 10) + + # Creates a new button with the label "Hello World". + button = GTK_BUTTON(gtk_button_new_with_label("Hello World")) + + discard g_signal_connect(button, "clicked", Gcallback(hello), nil) + + # This will cause the window to be destroyed by calling + # gtk_widget_destroy(window) when "clicked". Again, the destroy + # signal could come from here, or the window manager. + discard g_signal_connect_swapped(button, "clicked", + Gcallback(gtk_widget_destroy), window) + + # This packs the button into the window (a gtk container). + gtk_container_add(window, button) + + # The final step is to display this newly created widget. + gtk_widget_show(button) + + # and the window + gtk_widget_show(window) + + gtk_main() + +main() diff --git a/tests/accept/compile/thallo.nim b/tests/accept/compile/thallo.nim new file mode 100644 index 000000000..f1cae5897 --- /dev/null +++ b/tests/accept/compile/thallo.nim @@ -0,0 +1,83 @@ +# Hallo + +import + os, strutils, macros + +type + TMyEnum = enum + meA, meB, meC, meD + +when isMainModule: + {.hint: "this is the main file".} + +proc fac[T](x: T): T = + # test recursive generic procs + if x <= 1: return 1 + else: return x.`*`(fac(x-1)) + +macro macrotest(n: expr): stmt = + expectKind(n, nnkCall) + expectMinLen(n, 2) + result = newNimNode(nnkStmtList, n) + for i in 2..n.len-1: + result.add(newCall("write", n[1], n[i])) + result.add(newCall("writeln", n[1], newStrLitNode(""))) + +macro debug(n: expr): stmt = + result = newNimNode(nnkStmtList, n) + for i in 1..n.len-1: + result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i]))) + result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": "))) + result.add(newCall("writeln", newIdentNode("stdout"), n[i])) + +macrotest(stdout, "finally", 4, 5, "variable", "argument lists") +macrotest(stdout) + +#GC_disable() + +echo("This was compiled by Nimrod version " & system.nimrodVersion) +writeln(stdout, "Hallo", " World", "!") + +echo(["a", "b", "c", "d"].len) +for x in items(["What's", "your", "name", "?", ]): + echo(x) +var `name` = readLine(stdin) +{.breakpoint.} +echo("Hi " & thallo.name & "!\n") +debug(name) + +var testseq: seq[string] = @[ + "a", "b", "c", "d", "e" +] +echo(repr(testseq)) + +var dummy = "hallo" +echo(copy(dummy, 2, 3)) + +echo($meC) + +# test tuples: +for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]): + echo x + echo y + +proc simpleConst(): int = return 34 + +# test constant evaluation: +const + constEval3 = simpleConst() + constEval = "abc".contains('b') + constEval2 = fac(7) + +echo(constEval3) +echo(constEval) +echo(constEval2) +echo(1.`+`(2)) + +for i in 2..6: + for j in countdown(i+4, 2): + echo(fac(i * j)) + +when isMainModule: + {.hint: "this is the main file".} + diff --git a/tests/accept/compile/tident.nim b/tests/accept/compile/tident.nim new file mode 100644 index 000000000..1ed9894c6 --- /dev/null +++ b/tests/accept/compile/tident.nim @@ -0,0 +1,22 @@ + +type + TIdObj* = object of TObject + id*: int # unique id; use this for comparisons and not the pointers + + PIdObj* = ref TIdObj + PIdent* = ref TIdent + TIdent*{.acyclic.} = object + s*: string + +proc myNewString(L: int): string {.inline.} = + result = newString(L) + if result.len == L: echo("Length correct") + else: echo("bug") + for i in 0..L-1: + if result[i] == '\0': + echo("Correct") + else: + echo("Wrong") + +var s = myNewString(8) + diff --git a/tests/accept/compile/tindent1.nim b/tests/accept/compile/tindent1.nim new file mode 100644 index 000000000..0527b6e57 --- /dev/null +++ b/tests/accept/compile/tindent1.nim @@ -0,0 +1,24 @@ + +const romanNumbers1 = + [ + ("M", 1000), ("D", 500), ("C", 100), + ("L", 50), ("X", 10), ("V", 5), ("I", 1) ] + +const romanNumbers2 = + [ + ("M", 1000), ("D", 500), ("C", 100), + ("L", 50), ("X", 10), ("V", 5), ("I", 1) + ] + +const romanNumbers3 = + [ + ("M", 1000), ("D", 500), ("C", 100), + ("L", 50), ("X", 10), ("V", 5), ("I", 1) + ] + +const romanNumbers4 = [ + ("M", 1000), ("D", 500), ("C", 100), + ("L", 50), ("X", 10), ("V", 5), ("I", 1) + ] + + diff --git a/tests/accept/compile/tio.nim b/tests/accept/compile/tio.nim new file mode 100644 index 000000000..014c32d9f --- /dev/null +++ b/tests/accept/compile/tio.nim @@ -0,0 +1,7 @@ +# test the file-IO + +proc main() = + for line in lines("thallo.nim"): + writeln(stdout, line) + +main() diff --git a/tests/accept/compile/titer.nim b/tests/accept/compile/titer.nim new file mode 100644 index 000000000..19a11dc4e --- /dev/null +++ b/tests/accept/compile/titer.nim @@ -0,0 +1,44 @@ +# Test the new iterators + +iterator xrange(fromm, to: int, step = 1): int = + var a = fromm + while a <= to: + yield a + inc(a, step) + +iterator interval[T](a, b: T): T = + var x = a + while x <= b: + yield x + inc(x) + +# +#iterator lines(filename: string): (line: string) = +# var +# f: tTextfile +# shouldClose = open(f, filename) +# if shouldClose: +# setSpace(line, 256) +# while readTextLine(f, line): +# yield line +# finally: +# if shouldClose: close(f) +# + +for i in xrange(0, 5): + for k in xrange(1, 7): + write(stdout, "test") + +for j in interval(45, 45): + write(stdout, "test2!") + write(stdout, "test3?") + +for x in items(["hi", "what's", "your", "name"]): + echo(x) + +const + stringArray = ["hi", "what's", "your", "name"] + +for i in 0..len(stringArray)-1: + echo(stringArray[i]) + diff --git a/tests/accept/compile/tlastmod.nim b/tests/accept/compile/tlastmod.nim new file mode 100644 index 000000000..75b047fc8 --- /dev/null +++ b/tests/accept/compile/tlastmod.nim @@ -0,0 +1,18 @@ +# test the new LastModificationTime() proc + +import + os, times, strutils + +proc main() = + var + a, b: TTime + a = getLastModificationTime(ParamStr(1)) + b = getLastModificationTime(ParamStr(2)) + writeln(stdout, $a) + writeln(stdout, $b) + if a < b: + Write(stdout, "$2 is newer than $1\n" % [ParamStr(1), ParamStr(2)]) + else: + Write(stdout, "$1 is newer than $2\n" % [ParamStr(1), ParamStr(2)]) + +main() diff --git a/tests/accept/compile/tlexer.nim b/tests/accept/compile/tlexer.nim new file mode 100644 index 000000000..fe784280c --- /dev/null +++ b/tests/accept/compile/tlexer.nim @@ -0,0 +1,57 @@ +# We start with a comment +# This is the same comment + +# This is a new one! + +import + lexbase, os, strutils + +type + TMyRec {.final.} = object + x, y: int # coordinates + c: char # a character + a: int32 # an integer + + PMyRec = ref TMyRec # a reference to `TMyRec` + +proc splitText(txt: string): seq[string] # splits a text into several lines + # the comment continues here + # this is not easy to parse! + +proc anotherSplit(txt: string): list[string] = + # the comment should belong to `anotherSplit`! + # another problem: comments are statements! + +const + x = 0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64 # x ~~ 1.72826e35 + myNan = 0B01111111100000101100000000001000'f32 # NAN + y = """ + a rather long text. + Over many + lines. + """ + s = "\xff" + a = {0..234} + b = {0..high(int)} + v = 0'i32 + z = 6767566'f32 + +# small test program for lexbase + +proc main*(infile: string, a, b: int, someverylongnamewithtype = 0, + anotherlongthingie = 3) = + var + myInt: int = 0 + a b = 9 + s: sequence[string] + # this should be an error! + if initBaseLexer(L, infile, 30): nil + else: + writeln(stdout, "could not open: " & infile) + writeln(stdout, "Success!") + call(3, # we use 3 + 12, # we use 12 + 43 # we use 43 + ) + +main(ParamStr(1)) diff --git a/tests/accept/compile/tlibs.nim b/tests/accept/compile/tlibs.nim new file mode 100644 index 000000000..e3b6bd4c3 --- /dev/null +++ b/tests/accept/compile/tlibs.nim @@ -0,0 +1,21 @@ +# Test wether the bindings at least compile... + +import + unicode, cgi, terminal, libcurl, web, + parsexml, parseopt, parsecfg, + osproc, + sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf, + sdl_image, sdl_mixer_nosmpeg, + cursorfont, xatom, xf86vmode, xkb, xrandr, xshm, xvlib, keysym, xcms, xi, + xkblib, xrender, xutil, x, xf86dga, xinerama, xlib, xresource, xv, + gtk2, glib2, pango, gdk2, + cairowin32, cairoxlib, + odbcsql, + gl, glut, glu, glx, glext, wingl, + lua, lualib, lauxlib, mysql, sqlite3, python, tcl + +when defined(linux): + import + zlib, zipfiles + +writeln(stdout, "test compilation of binding modules") diff --git a/tests/accept/compile/tloops.nim b/tests/accept/compile/tloops.nim new file mode 100644 index 000000000..3d03256ad --- /dev/null +++ b/tests/accept/compile/tloops.nim @@ -0,0 +1,64 @@ +# Test nested loops and some other things + +proc andTest() = + var a = 0 == 5 and 6 == 6 + +proc incx(x: var int) = # is built-in proc + x = x + 1 + +proc decx(x: var int) = + x = x - 1 + +proc First(y: var int) = + var x: int + i_ncx(x) + if x == 10: + y = 0 + else: + if x == 0: + incx(x) + else: + x=11 + +proc TestLoops() = + var i, j: int + while i >= 0: + if i mod 3 == 0: + break + i = i + 1 + while j == 13: + j = 13 + break + break + + while True: + break + + +proc Foo(n: int): int = + var + a, old: int + b, c: bool + F_irst(a) + if a == 10: + a = 30 + elif a == 11: + a = 22 + elif a == 12: + a = 23 + elif b: + old = 12 + else: + a = 40 + + # + b = false or 2 == 0 and 3 == 9 + a = 0 + 3 * 5 + 6 + 7 + +8 # 36 + while b: + a = a + 3 + a = a + 5 + write(stdout, "Hallo!") + + +# We should come till here :-) +discard Foo(345) diff --git a/tests/accept/compile/tmath.nim b/tests/accept/compile/tmath.nim new file mode 100644 index 000000000..6a1dae54d --- /dev/null +++ b/tests/accept/compile/tmath.nim @@ -0,0 +1,85 @@ +# tests for the interpreter + +proc loops(a: var int) = + nil + #var + # b: int + #b = glob + #while b != 0: + # b = b + 1 + #a = b + +proc mymax(a, b: int): int = + #loops(result) + result = a + if b > a: result = b + +proc test(a, b: int) = + var + x, y: int + x = 0 + y = 7 + if x == a + b * 3 - 7 or + x == 8 or + x == y and y > -56 and y < 699: + y = 0 + elif y == 78 and x == 0: + y = 1 + elif y == 0 and x == 0: + y = 2 + else: + y = 3 + +type + TTokType = enum + tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf, + tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto + +proc testCase(t: TTokType): int = + case t + of tkNil, tkType, tkConst: result = 0 + of tkVar: result = 1 + of tkSymbol: result = 2 + of tkIf..tkFor: result = 3 + of tkLoop: result = 56 + else: result = -1 + test(0, 9) # test the call + +proc TestLoops() = + var + i, j: int + + while i >= 0: + if i mod 3 == 0: + break + i = i + 1 + while j == 13: + j = 13 + break + break + + while True: + break + + +var + glob: int + a: array [0..5, int] + +proc main() = + #glob = 0 + #loops( glob ) + var + res: int + s: string + #write(stdout, mymax(23, 45)) + write(stdout, "Hallo! Wie heißt du? ") + s = readLine(stdin) + # test the case statement + case s + of "Andreas": write(stdout, "Du bist mein Meister!\n") + of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n") + else: write(stdout, "ich kenne dich nicht!\n") + write(stdout, "Du heisst " & s & "\n") + +main() diff --git a/tests/accept/compile/tnew.nim b/tests/accept/compile/tnew.nim new file mode 100644 index 000000000..6527541a2 --- /dev/null +++ b/tests/accept/compile/tnew.nim @@ -0,0 +1,49 @@ +# Test the implementation of the new operator +# and the code generation for gc walkers +# (and the garbage collector): + +type + PNode = ref TNode + TNode = object + data: int + str: string + le, ri: PNode + + TStressTest = ref array [0..45, array [1..45, TNode]] + +proc finalizer(n: PNode) = + write(stdout, n.data) + write(stdout, " is now freed\n") + +proc newNode(data: int, le, ri: PNode): PNode = + new(result, finalizer) + result.le = le + result.ri = ri + result.data = data + +# now loop and build a tree +proc main() = + var + i = 0 + p: TStressTest + while i < 1000: + var n: PNode + + n = newNode(i, nil, newNode(i + 10000, nil, nil)) + inc(i) + new(p) + + write(stdout, "Simple tree node allocation worked!\n") + i = 0 + while i < 1000: + var m = newNode(i + 20000, nil, nil) + var k = newNode(i + 30000, nil, nil) + m.le = m + m.ri = k + k.le = m + k.ri = k + inc(i) + + write(stdout, "Simple cycle allocation worked!\n") + +main() diff --git a/tests/accept/compile/tnewlibs.nim b/tests/accept/compile/tnewlibs.nim new file mode 100644 index 000000000..aca2e3c30 --- /dev/null +++ b/tests/accept/compile/tnewlibs.nim @@ -0,0 +1,16 @@ +# Test wether the bindings at least compile... + +import + tcl, + sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf, + sdl_image, sdl_mixer_nosmpeg, + gtk2, glib2, pango, gdk2, + unicode, cgi, terminal, libcurl, + parsexml, parseopt, parsecfg, + osproc, + cairowin32, cairoxlib, + gl, glut, glu, glx, glext, wingl, + lua, lualib, lauxlib, mysql, sqlite3, + + +writeln(stdout, "test compilation of binding modules") diff --git a/tests/accept/compile/tnewsets.nim b/tests/accept/compile/tnewsets.nim new file mode 100644 index 000000000..415fe8f7e --- /dev/null +++ b/tests/accept/compile/tnewsets.nim @@ -0,0 +1,6 @@ +# new test for sets: + +const elem = ' ' + +var s: set[char] = {elem} +assert(elem in s and 'a' not_in s and 'c' not_in s ) diff --git a/tests/accept/compile/tnewuns.nim b/tests/accept/compile/tnewuns.nim new file mode 100644 index 000000000..5181e467c --- /dev/null +++ b/tests/accept/compile/tnewuns.nim @@ -0,0 +1,12 @@ +# test the new unsigned operations: + +import + strutils + +var + x, y: int + +x = 1 +y = high(int) + +writeln(stdout, $ ( x +% y ) ) diff --git a/tests/accept/compile/tobjcov.nim b/tests/accept/compile/tobjcov.nim new file mode 100644 index 000000000..da34fcb60 --- /dev/null +++ b/tests/accept/compile/tobjcov.nim @@ -0,0 +1,17 @@ +# Covariance is not type safe: + +type + TA = object + a: int + TB = object of TA + b: array[0..5000_000, int] + +proc ap(x: var TA) = x.a = -1 +proc bp(x: var TB) = x.b[high(x.b)] = -1 + +# in Nimrod proc (x: TB) is compatible to proc (x: TA), +# but this is not type safe: +var f: proc (x: var TA) = bp +var a: TA +f(a) # bp expects a TB, but gets a TA + diff --git a/tests/accept/compile/tobject2.nim b/tests/accept/compile/tobject2.nim new file mode 100644 index 000000000..8f69a6bac --- /dev/null +++ b/tests/accept/compile/tobject2.nim @@ -0,0 +1,21 @@ +# Tests the object implementation + +type + TPoint2d = object + x, y: int + + TPoint3d = object of TPoint2d + z: int # added a field + +proc getPoint( p: var TPoint2d) = + {.breakpoint.} + writeln(stdout, p.x) + +var + p: TPoint3d + +TPoint2d(p).x = 34 +p.y = 98 +p.z = 343 + +getPoint(p) diff --git a/tests/accept/compile/tobjects.nim b/tests/accept/compile/tobjects.nim new file mode 100644 index 000000000..8305e2838 --- /dev/null +++ b/tests/accept/compile/tobjects.nim @@ -0,0 +1,42 @@ +type + TBase = object + x, y: int + + TSubclassKind = enum ka, kb, kc, kd, ke, kf + TSubclass = object of TBase + case c: TSubclassKind + of ka, kb, kc, kd: + a, b: int + of ke: + d, e, f: char + else: nil + n: bool + +var + global: int + +var + s: string + r: float = 0.0 + i: int = 500 + 400 + +case i +of 500..999: write(stdout, "ha!\n") +of 1000..3000, 12: write(stdout, "ganz schön groß\n") +of 1, 2, 3: write(stdout, "1 2 oder 3\n") +else: write(stdout, "sollte nicht passieren\n") + +case readLine(stdin) +of "Rumpf": write(stdout, "Hallo Meister!\n") +of "Andreas": write(stdout, "Hallo Meister!\n") +else: write(stdout, "Nicht mein Meister!\n") + +global = global + 1 +write(stdout, "Hallo wie heißt du? \n") +s = readLine(stdin) +i = 0 +while i < len(s): + if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") + i = i + 1 + +write(stdout, "Du heißt " & s) diff --git a/tests/accept/compile/toptions.nim b/tests/accept/compile/toptions.nim new file mode 100644 index 000000000..95bb5cfbc --- /dev/null +++ b/tests/accept/compile/toptions.nim @@ -0,0 +1,22 @@ +# Converted by Pas2mor v1.54 +# Used command line arguments: +# -m -q -o bootstrap\options.mor options.pas +# + +type + # please make sure we have under 32 options (improves code efficiency!) + TOption = enum + optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck, + optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir, + optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly, + optSafeCode, # only allow safe code + optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib, + optGenGuiApp, optStackTrace + + TOptionset = set[TOption] + +var + gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck, + optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace} + compilerArgs: int + gExitcode: int8 diff --git a/tests/accept/compile/tos.nim b/tests/accept/compile/tos.nim new file mode 100644 index 000000000..9ab4295f8 --- /dev/null +++ b/tests/accept/compile/tos.nim @@ -0,0 +1,12 @@ +# test some things of the os module + +import os + +proc walkDirTree(root: string) = + for k, f in walkDir(root): + case k + of pcFile, pcLinkToFile: echo(f) + of pcDirectory: walkDirTree(f) + of pcLinkToDirectory: nil + +walkDirTree(".") diff --git a/tests/accept/compile/toverprc.nim b/tests/accept/compile/toverprc.nim new file mode 100644 index 000000000..f35528ace --- /dev/null +++ b/tests/accept/compile/toverprc.nim @@ -0,0 +1,25 @@ +# Test overloading of procs when used as function pointers + +import strutils + +proc parseInt(x: float): int = nil +proc parseInt(x: bool): int = nil +proc parseInt(x: float32): int = nil +proc parseInt(x: int8): int = nil +proc parseInt(x: TFile): int = nil +proc parseInt(x: char): int = nil +proc parseInt(x: int16): int = nil + +type + TParseInt = proc (x: string): int + +var + q = TParseInt(parseInt) + p: TParseInt = parseInt + +proc takeParseInt(x: proc (y: string): int): int = + result = x("123") + +echo "Give a list of numbers (separated by spaces): " +var x = stdin.readline.split.each(parseInt).max echo x, " is the maximum!" echo "another number: ", takeParseInt(parseInt) + diff --git a/tests/accept/compile/tparedef.nim b/tests/accept/compile/tparedef.nim new file mode 100644 index 000000000..dedebf6b7 --- /dev/null +++ b/tests/accept/compile/tparedef.nim @@ -0,0 +1,4 @@ +# This test is now superfluous: + +proc a(a: int) = + return diff --git a/tests/accept/compile/tparscfg.nim b/tests/accept/compile/tparscfg.nim new file mode 100644 index 000000000..618ecadd6 --- /dev/null +++ b/tests/accept/compile/tparscfg.nim @@ -0,0 +1,25 @@ + +import + os, parsecfg, strutils, streams + +var f = newFileStream(paramStr(1), fmRead) +if f != nil: + var p: TCfgParser + open(p, f, paramStr(1)) + while true: + var e = next(p) + case e.kind + of cfgEof: + echo("EOF!") + break + of cfgSectionStart: ## a ``[section]`` has been parsed + echo("new section: " & e.section) + of cfgKeyValuePair: + echo("key-value-pair: " & e.key & ": " & e.value) + of cfgOption: + echo("command: " & e.key & ": " & e.value) + of cfgError: + echo(e.msg) + close(p) +else: + echo("cannot open: " & paramStr(1)) diff --git a/tests/accept/compile/tparsefloat.nim b/tests/accept/compile/tparsefloat.nim new file mode 100644 index 000000000..38ed2db6d --- /dev/null +++ b/tests/accept/compile/tparsefloat.nim @@ -0,0 +1,3 @@ +import strutils + +echo ParseFloat("5000") / ParseFloat("10") diff --git a/tests/accept/compile/tparsopt.nim b/tests/accept/compile/tparsopt.nim new file mode 100644 index 000000000..2b2da7e51 --- /dev/null +++ b/tests/accept/compile/tparsopt.nim @@ -0,0 +1,27 @@ +# Test the new parseopt module + +import + parseopt + +proc writeHelp() = + writeln(stdout, "Usage: tparsopt [options] filename [options]") + +proc writeVersion() = + writeln(stdout, "Version: 1.0.0") + +var + filename = "" +for kind, key, val in getopt(): + case kind + of cmdArgument: + filename = key + of cmdLongOption, cmdShortOption: + case key + of "help", "h": writeHelp() + of "version", "v": writeVersion() + else: + writeln(stdout, "Unknown command line option: ", key, ": ", val) + of cmdEnd: assert(false) # cannot happen +if filename == "": + # no filename has been given, so we show the help: + writeHelp() diff --git a/tests/accept/compile/tposix.nim b/tests/accept/compile/tposix.nim new file mode 100644 index 000000000..bf0b49586 --- /dev/null +++ b/tests/accept/compile/tposix.nim @@ -0,0 +1,16 @@ +# Test Posix interface + +when not defined(windows): + + import posix + + var + u: Tutsname + + discard uname(u) + + writeln(stdout, u.sysname) + writeln(stdout, u.nodename) + writeln(stdout, u.release) + writeln(stdout, u.machine) + diff --git a/tests/accept/compile/tprep.nim b/tests/accept/compile/tprep.nim new file mode 100644 index 000000000..999b2f57f --- /dev/null +++ b/tests/accept/compile/tprep.nim @@ -0,0 +1,28 @@ +# Test the features that used to belong to the preprocessor + +import + times + +{.warning: "This is only a test warning!".} + +{.define: case2.} +{.define: case3.} +when defined(case1): + {.hint: "Case 1".} + when defined(case3): + {.hint: "Case 1.3".} +elif defined(case2): + {.hint: "Case 2".} + when defined(case3): + {.hint: "Case 2.3".} +elif defined(case3): + {.hint: "Case 3".} +else: + {.hint: "unknown case".} + +var + s: string +write(stdout, "compiled at " & system.compileDate & + " " & compileTime & "\n") +echo getDateStr() +echo getClockStr() diff --git a/tests/accept/compile/tpush.nim b/tests/accept/compile/tpush.nim new file mode 100644 index 000000000..5fb411a79 --- /dev/null +++ b/tests/accept/compile/tpush.nim @@ -0,0 +1,15 @@ +# test the new pragmas + +{.push warnings: off, hints: off.} +proc noWarning() = + var + x: int + echo(x) + +{.pop.} + +proc WarnMe() = + var + x: int + echo(x) + diff --git a/tests/accept/compile/tquicksort.nim b/tests/accept/compile/tquicksort.nim new file mode 100644 index 000000000..421564ecd --- /dev/null +++ b/tests/accept/compile/tquicksort.nim @@ -0,0 +1,24 @@ +proc QuickSort(list: seq[int]): seq[int] = + if len(list) == 0: + return @[] + var pivot = list[0] + var left: seq[int] = @[] + var right: seq[int] = @[] + for i in low(list)..high(list): + if list[i] < pivot: + left.add(list[i]) + elif list[i] > pivot: + right.add(list[i]) + result = QuickSort(left) & pivot & QuickSort(right) + +proc echoSeq(a: seq[int]) = + for i in low(a)..high(a): + echo(a[i]) + +var + list: seq[int] + +list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3]) +echoSeq(list) + + diff --git a/tests/accept/compile/tquit.nim b/tests/accept/compile/tquit.nim new file mode 100644 index 000000000..d4dc1522d --- /dev/null +++ b/tests/accept/compile/tquit.nim @@ -0,0 +1,6 @@ +# Test the new beforeQuit variable: + +proc myExit() {.noconv.} = + write(stdout, "just exiting...\n") + +addQuitProc(myExit) diff --git a/tests/accept/compile/tradix.nim b/tests/accept/compile/tradix.nim new file mode 100644 index 000000000..e7ca210e4 --- /dev/null +++ b/tests/accept/compile/tradix.nim @@ -0,0 +1,319 @@ +# implements and tests an efficient radix tree + +## another method to store an efficient array of pointers: +## We use a radix tree with node compression. +## There are two node kinds: + +const bitsPerUnit = 8*sizeof(int) + +type + TRadixNodeKind = enum rnLinear, rnFull, rnLeafBits, rnLeafLinear + PRadixNode = ptr TRadixNode + TRadixNode {.pure.} = object + kind: TRadixNodeKind + TRadixNodeLinear = object of TRadixNode + len: byte + keys: array [0..31, byte] + vals: array [0..31, PRadixNode] + + TRadixNodeFull = object of TRadixNode + b: array [0..255, PRadixNode] + TRadixNodeLeafBits = object of TRadixNode + b: array [0..7, int] + TRadixNodeLeafLinear = object of TRadixNode + len: byte + keys: array [0..31, byte] + +var + root: PRadixNode + +proc searchInner(r: PRadixNode, a: int): PRadixNode = + case r.kind + of rnLinear: + var x = cast[ptr TRadixNodeLinear](r) + for i in 0..ze(x.len)-1: + if ze(x.keys[i]) == a: return x.vals[i] + of rnFull: + var x = cast[ptr TRadixNodeFull](r) + return x.b[a] + else: assert(false) + +proc testBit(w, i: int): bool {.inline.} = + result = (w and (1 shl (i %% BitsPerUnit))) != 0 + +proc setBit(w: var int, i: int) {.inline.} = + w = w or (1 shl (i %% bitsPerUnit)) + +proc resetBit(w: var int, i: int) {.inline.} = + w = w and not (1 shl (i %% bitsPerUnit)) + +proc testOrSetBit(w: var int, i: int): bool {.inline.} = + var x = (1 shl (i %% bitsPerUnit)) + if (w and x) != 0: return true + w = w or x + +proc searchLeaf(r: PRadixNode, a: int): bool = + case r.kind + of rnLeafBits: + var x = cast[ptr TRadixNodeLeafBits](r) + return testBit(x.b[a /% BitsPerUnit], a) + of rnLeafLinear: + var x = cast[ptr TRadixNodeLeafLinear](r) + for i in 0..ze(x.len)-1: + if ze(x.keys[i]) == a: return true + else: assert(false) + +proc exclLeaf(r: PRadixNode, a: int) = + case r.kind + of rnLeafBits: + var x = cast[ptr TRadixNodeLeafBits](r) + resetBit(x.b[a /% BitsPerUnit], a) + of rnLeafLinear: + var x = cast[ptr TRadixNodeLeafLinear](r) + var L = ze(x.len) + for i in 0..L-1: + if ze(x.keys[i]) == a: + x.keys[i] = x.keys[L-1] + dec(x.len) + return + else: assert(false) + +proc in_Operator*(r: PRadixNode, a: TAddress): bool = + if r == nil: return false + var x = searchInner(r, a shr 24 and 0xff) + if x == nil: return false + x = searchInner(x, a shr 16 and 0xff) + if x == nil: return false + x = searchInner(x, a shr 8 and 0xff) + if x == nil: return false + return searchLeaf(x, a and 0xff) + +proc excl*(r: PRadixNode, a: TAddress): bool = + if r == nil: return false + var x = searchInner(r, a shr 24 and 0xff) + if x == nil: return false + x = searchInner(x, a shr 16 and 0xff) + if x == nil: return false + x = searchInner(x, a shr 8 and 0xff) + if x == nil: return false + exclLeaf(x, a and 0xff) + +proc addLeaf(r: var PRadixNode, a: int): bool = + if r == nil: + # a linear node: + var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) + x.kind = rnLeafLinear + x.len = 1'i8 + x.keys[0] = toU8(a) + r = x + return false # not already in set + case r.kind + of rnLeafBits: + var x = cast[ptr TRadixNodeLeafBits](r) + return testOrSetBit(x.b[a /% BitsPerUnit], a) + of rnLeafLinear: + var x = cast[ptr TRadixNodeLeafLinear](r) + var L = ze(x.len) + for i in 0..L-1: + if ze(x.keys[i]) == a: return true + if L <= high(x.keys): + x.keys[L] = toU8(a) + inc(x.len) + else: + # transform into a full node: + var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits))) + y.kind = rnLeafBits + for i in 0..ze(x.len)-1: + var u = ze(x.keys[i]) + setBit(y.b[u /% BitsPerUnit], u) + setBit(y.b[a /% BitsPerUnit], a) + dealloc(r) + r = y + else: assert(false) + +proc addInner(r: var PRadixNode, a: int, d: int): bool = + if d == 0: + return addLeaf(r, a and 0xff) + var k = a shr d and 0xff + if r == nil: + # a linear node: + var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) + x.kind = rnLinear + x.len = 1'i8 + x.keys[0] = toU8(k) + r = x + return addInner(x.vals[0], a, d-8) + case r.kind + of rnLinear: + var x = cast[ptr TRadixNodeLinear](r) + var L = ze(x.len) + for i in 0..L-1: + if ze(x.keys[i]) == k: # already exists + return addInner(x.vals[i], a, d-8) + if L <= high(x.keys): + x.keys[L] = toU8(k) + inc(x.len) + return addInner(x.vals[L], a, d-8) + else: + # transform into a full node: + var y = cast[ptr TRadixNodeFull](alloc0(sizeof(TRadixNodeFull))) + y.kind = rnFull + for i in 0..L-1: y.b[ze(x.keys[i])] = x.vals[i] + dealloc(r) + r = y + return addInner(y.b[k], a, d-8) + of rnFull: + var x = cast[ptr TRadixNodeFull](r) + return addInner(x.b[k], a, d-8) + else: assert(false) + +proc incl*(r: var PRadixNode, a: TAddress) {.inline.} = + discard addInner(r, a, 24) + +proc testOrIncl*(r: var PRadixNode, a: TAddress): bool {.inline.} = + return addInner(r, a, 24) + +iterator innerElements(r: PRadixNode): tuple[prefix: int, n: PRadixNode] = + if r != nil: + case r.kind + of rnFull: + var r = cast[ptr TRadixNodeFull](r) + for i in 0..high(r.b): + if r.b[i] != nil: + yield (i, r.b[i]) + of rnLinear: + var r = cast[ptr TRadixNodeLinear](r) + for i in 0..ze(r.len)-1: + yield (ze(r.keys[i]), r.vals[i]) + else: assert(false) + +iterator leafElements(r: PRadixNode): int = + if r != nil: + case r.kind + of rnLeafBits: + var r = cast[ptr TRadixNodeLeafBits](r) + # iterate over any bit: + for i in 0..high(r.b): + if r.b[i] != 0: # test all bits for zero + for j in 0..BitsPerUnit-1: + if testBit(r.b[i], j): + yield i*BitsPerUnit+j + of rnLeafLinear: + var r = cast[ptr TRadixNodeLeafLinear](r) + for i in 0..ze(r.len)-1: + yield ze(r.keys[i]) + else: assert(false) + +iterator elements*(r: PRadixNode): TAddress {.inline.} = + for p1, n1 in innerElements(r): + for p2, n2 in innerElements(n1): + for p3, n3 in innerElements(n2): + for p4 in leafElements(n3): + yield p1 shl 24 or p2 shl 16 or p3 shl 8 or p4 + +proc main() = + const + numbers = [128, 1, 2, 3, 4, 255, 17, -8, 45, 19_000] + var + r: PRadixNode = nil + for x in items(numbers): + echo testOrIncl(r, x) + for x in elements(r): echo(x) + +main() + + +when false: + proc traverse(r: PRadixNode, prefix: int, d: int) = + if r == nil: return + case r.kind + of rnLeafBits: + assert(d == 0) + var x = cast[ptr TRadixNodeLeafBits](r) + # iterate over any bit: + for i in 0..high(x.b): + if x.b[i] != 0: # test all bits for zero + for j in 0..BitsPerUnit-1: + if testBit(x.b[i], j): + visit(prefix or i*BitsPerUnit+j) + of rnLeafLinear: + assert(d == 0) + var x = cast[ptr TRadixNodeLeafLinear](r) + for i in 0..ze(x.len)-1: + visit(prefix or ze(x.keys[i])) + of rnFull: + var x = cast[ptr TRadixNodeFull](r) + for i in 0..high(r.b): + if r.b[i] != nil: + traverse(r.b[i], prefix or (i shl d), d-8) + of rnLinear: + var x = cast[ptr TRadixNodeLinear](r) + for i in 0..ze(x.len)-1: + traverse(x.vals[i], prefix or (ze(x.keys[i]) shl d), d-8) + + type + TRadixIter {.final.} = object + r: PRadixNode + p: int + x: int + + proc init(i: var TRadixIter, r: PRadixNode) = + i.r = r + i.x = 0 + i.p = 0 + + proc nextr(i: var TRadixIter): PRadixNode = + if i.r == nil: return nil + case i.r.kind + of rnFull: + var r = cast[ptr TRadixNodeFull](i.r) + while i.x <= high(r.b): + if r.b[i.x] != nil: + i.p = i.x + return r.b[i.x] + inc(i.x) + of rnLinear: + var r = cast[ptr TRadixNodeLinear](i.r) + if i.x < ze(r.len): + i.p = ze(r.keys[i.x]) + result = r.vals[i.x] + inc(i.x) + else: assert(false) + + proc nexti(i: var TRadixIter): int = + result = -1 + case i.r.kind + of rnLeafBits: + var r = cast[ptr TRadixNodeLeafBits](i.r) + # iterate over any bit: + for i in 0..high(r.b): + if x.b[i] != 0: # test all bits for zero + for j in 0..BitsPerUnit-1: + if testBit(x.b[i], j): + visit(prefix or i*BitsPerUnit+j) + of rnLeafLinear: + var r = cast[ptr TRadixNodeLeafLinear](i.r) + if i.x < ze(r.len): + result = ze(r.keys[i.x]) + inc(i.x) + + iterator elements(r: PRadixNode): TAddress {.inline.} = + var + a, b, c, d: TRadixIter + init(a, r) + while true: + var x = nextr(a) + if x != nil: + init(b, x) + while true: + var y = nextr(b) + if y != nil: + init(c, y) + while true: + var z = nextr(c) + if z != nil: + init(d, z) + while true: + var q = nexti(d) + if q != -1: + yield a.p shl 24 or b.p shl 16 or c.p shl 8 or q diff --git a/tests/accept/compile/treadln.nim b/tests/accept/compile/treadln.nim new file mode 100644 index 000000000..7703d5a56 --- /dev/null +++ b/tests/accept/compile/treadln.nim @@ -0,0 +1,12 @@ +# test the improved readline handling that does not care whether its +# Macintosh, Unix or Windows text format. + +var + inp: TFile + line: string + +if openFile(inp, "readme.txt"): + while not EndOfFile(inp): + line = readLine(inp) + echo("#" & line & "#") + closeFile(inp) diff --git a/tests/accept/compile/treadx.nim b/tests/accept/compile/treadx.nim new file mode 100644 index 000000000..13acb0514 --- /dev/null +++ b/tests/accept/compile/treadx.nim @@ -0,0 +1,12 @@ +import posix + +var inp = "" +var buf: array[0..10, char] +while true: + var r = read(0, addr(buf), sizeof(buf)-1) + add inp, $buf + if r != sizeof(buf)-1: break + +echo inp +#dafkladskölklödsaf ölksdakölfölksfklwe4iojr389wr 89uweokf sdlkf jweklr jweflksdj fioewjfsdlfsd + diff --git a/tests/accept/compile/trecmod.nim b/tests/accept/compile/trecmod.nim new file mode 100644 index 000000000..9d39d3ff7 --- /dev/null +++ b/tests/accept/compile/trecmod.nim @@ -0,0 +1,2 @@ +# recursive module +import mrecmod diff --git a/tests/accept/compile/trecmod2.nim b/tests/accept/compile/trecmod2.nim new file mode 100644 index 000000000..85fe2215f --- /dev/null +++ b/tests/accept/compile/trecmod2.nim @@ -0,0 +1,10 @@ +type + T1* = int # Module A exports the type ``T1`` + +import mrecmod2 # the compiler starts parsing B + +proc main() = + var i = p(3) # works because B has been parsed completely here + +main() + diff --git a/tests/accept/compile/trepr.nim b/tests/accept/compile/trepr.nim new file mode 100644 index 000000000..4a56842f6 --- /dev/null +++ b/tests/accept/compile/trepr.nim @@ -0,0 +1,32 @@ +# test the new "repr" built-in proc + +type + TEnum = enum + en1, en2, en3, en4, en5, en6 + + TPoint {.final.} = object + x, y, z: int + s: array [0..1, string] + e: TEnum + +var + p: TPoint + q: ref TPoint + s: seq[ref TPoint] + +p.x = 0 +p.y = 13 +p.z = 45 +p.s[0] = "abc" +p.s[1] = "xyz" +p.e = en6 + +new(q) +q^ = p + +s = @[q, q, q, q] + +writeln(stdout, repr(p)) +writeln(stdout, repr(q)) +writeln(stdout, repr(s)) +writeln(stdout, repr(en4)) diff --git a/tests/accept/compile/tseq2.nim b/tests/accept/compile/tseq2.nim new file mode 100644 index 000000000..03bdb3fab --- /dev/null +++ b/tests/accept/compile/tseq2.nim @@ -0,0 +1,13 @@ + + +proc `*` *(a, b: seq[int]): seq[int] = + # allocate a new sequence: + newSeq(result, len(a)) + # multiply two int sequences: + for i in 0..len(a)-1: result[i] = a[i] * b[i] + +when isMainModule: + # test the new ``*`` operator for sequences: + assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) + + diff --git a/tests/accept/compile/tseqcon2.nim b/tests/accept/compile/tseqcon2.nim new file mode 100644 index 000000000..6225c3bb1 --- /dev/null +++ b/tests/accept/compile/tseqcon2.nim @@ -0,0 +1,9 @@ +import os + +proc rec_dir(dir: string): seq[string] = + result = @[] + for kind, path in walk_dir(dir): + if kind == pcDirectory: + add(result, rec_dir(path)) + else: + add(result, path) diff --git a/tests/accept/compile/tsizeof.nim b/tests/accept/compile/tsizeof.nim new file mode 100644 index 000000000..f7b70dd4d --- /dev/null +++ b/tests/accept/compile/tsizeof.nim @@ -0,0 +1,10 @@ +# Test the sizeof proc + +type + TMyRecord {.final.} = object + x, y: int + b: bool + r: float + s: string + +write(stdout, sizeof(TMyRecord)) diff --git a/tests/accept/compile/tsockets.nim b/tests/accept/compile/tsockets.nim new file mode 100644 index 000000000..cc7d18b87 --- /dev/null +++ b/tests/accept/compile/tsockets.nim @@ -0,0 +1,11 @@ +import sockets +var s: TSocket +s = socket() + +s.connect("www.google.com", TPort(80)) + +var recvData: string = "" +echo(s.recvLine(recvData)) +echo(recvData) + + diff --git a/tests/accept/compile/tstrace.nim b/tests/accept/compile/tstrace.nim new file mode 100644 index 000000000..56f20a0dd --- /dev/null +++ b/tests/accept/compile/tstrace.nim @@ -0,0 +1,16 @@ +# Test the new stacktraces (great for debugging!) + +{.push stack_trace: on.} + +proc recTest(i: int) = + # enter + if i < 10: + recTest(i+1) + else: # should printStackTrace() + var p: ptr int = nil + p^ = 12 + # leave + +{.pop.} + +recTest(0) diff --git a/tests/accept/compile/tstrdesc.nim b/tests/accept/compile/tstrdesc.nim new file mode 100644 index 000000000..1c2e85b4b --- /dev/null +++ b/tests/accept/compile/tstrdesc.nim @@ -0,0 +1,14 @@ +var + x: array [0..2, int] + +x = [0, 1, 2] + +type + TStringDesc {.final.} = object + len, space: int # len and space without counting the terminating zero + data: array [0..0, char] # for the '\0' character + +var + emptyString {.exportc: "emptyString".}: TStringDesc + + diff --git a/tests/accept/compile/tstrdist.nim b/tests/accept/compile/tstrdist.nim new file mode 100644 index 000000000..3e1939e73 --- /dev/null +++ b/tests/accept/compile/tstrdist.nim @@ -0,0 +1,26 @@ +# compute the edit distance between two strings + +proc editDistance(a, b: string): int = + var + c: seq[int] + n = a.len + m = b.len + newSeq(c, (n+1)*(m+1)) + for i in 0..n: + c[i*n] = i # [i,0] + for j in 0..m: + c[j] = j # [0,j] + + for i in 1..n: + for j in 1..m: + var x = c[(i-1)*n + j]+1 + var y = c[i*n + j-1]+1 + var z: int + if a[i-1] == b[j-1]: + z = c[(i-1)*n + j-1] + else: + z = c[(i-1)*n + j-1]+1 + c[(i-1)*n + (j-1)] = min(x,min(y,z)) + return c[n*m] + +write(stdout, editDistance("abc", "abd")) diff --git a/tests/accept/compile/tstreams.nim b/tests/accept/compile/tstreams.nim new file mode 100644 index 000000000..68ca8eeeb --- /dev/null +++ b/tests/accept/compile/tstreams.nim @@ -0,0 +1,7 @@ +import streams + +var outp = newFileStream(stdout) +var inp = newFileStream(stdin) +write(outp, "Hallo! What is your name?") +var line = readLine(inp) +write(outp, "nice name: " & line) diff --git a/tests/accept/compile/tstrset.nim b/tests/accept/compile/tstrset.nim new file mode 100644 index 000000000..e19ccee4d --- /dev/null +++ b/tests/accept/compile/tstrset.nim @@ -0,0 +1,74 @@ +# test a simple yet highly efficient set of strings + +type + TRadixNodeKind = enum rnLinear, rnFull, rnLeaf + PRadixNode = ref TRadixNode + TRadixNode = object + kind: TRadixNodeKind + TRadixNodeLinear = object of TRadixNode + len: byte + keys: array [0..31, char] + vals: array [0..31, PRadixNode] + TRadixNodeFull = object of TRadixNode + b: array [char, PRadixNode] + TRadixNodeLeaf = object of TRadixNode + s: string + PRadixNodeLinear = ref TRadixNodeLinear + PRadixNodeFull = ref TRadixNodeFull + PRadixNodeLeaf = ref TRadixNodeLeaf + +proc search(r: PRadixNode, s: string): PRadixNode = + var r = r + var i = 0 + while r != nil: + case r.kind + of rnLinear: + var x = PRadixNodeLinear(r) + for j in 0..ze(x.len)-1: + if x.keys[j] == s[i]: + if s[i] == '\0': return r + r = x.vals[j] + inc(i) + break + break # character not found + of rnFull: + var x = PRadixNodeFull(r) + var y = x.b[s[i]] + if s[i] == '\0': + return if y != nil: r else: nil + r = y + inc(i) + of rnLeaf: + var x = PRadixNodeLeaf(r) + var j = 0 + while true: + if x.s[j] != s[i]: return nil + if s[i] == '\0': return r + inc(j) + inc(i) + +proc in_Operator*(r: PRadixNode, s: string): bool = + return search(r, s) != nil + +proc testOrincl*(r: var PRadixNode, s: string): bool = + nil + +proc incl*(r: var PRadixNode, s: string) = discard testOrIncl(r, s) + +proc excl*(r: var PRadixNode, s: string) = + var x = search(r, s) + if x == nil: return + case x.kind + of rnLeaf: PRadixNodeLeaf(x).s = "" + of rnFull: PRadixNodeFull(x).b['\0'] = nil + of rnLinear: + var x = PRadixNodeLinear(x) + for i in 0..ze(x.len)-1: + if x.keys[i] == '\0': + swap(x.keys[i], x.keys[ze(x.len)-1]) + dec(x.len) + break + +var + root: PRadixNode + diff --git a/tests/accept/compile/tstrtabs.nim b/tests/accept/compile/tstrtabs.nim new file mode 100644 index 000000000..299db609d --- /dev/null +++ b/tests/accept/compile/tstrtabs.nim @@ -0,0 +1,12 @@ +import strtabs + +var tab = newStringTable(["key1", "val1", "key2", "val2"], + modeStyleInsensitive) +for i in 0..80: + tab["key_" & $i] = "value" & $i + +for key, val in pairs(tab): + writeln(stdout, key, ": ", val) +writeln(stdout, "length of table ", $tab.len) + +writeln(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment})) diff --git a/tests/accept/compile/ttempl.nim b/tests/accept/compile/ttempl.nim new file mode 100644 index 000000000..dcf096671 --- /dev/null +++ b/tests/accept/compile/ttempl.nim @@ -0,0 +1,27 @@ +# Test the new template file mechanism + +import + os, times + +include "sunset.tmpl" + +const + tabs = [["home", "index"], + ["news", "news"], + ["documentation", "documentation"], + ["download", "download"], + ["FAQ", "question"], + ["links", "links"]] + + +var i = 0 +for item in items(tabs): + var content = $i + var file: TFile + if openFile(file, changeFileExt(item[1], "html"), fmWrite): + write(file, sunsetTemplate(current=item[1], ticker="", content=content, + tabs=tabs)) + closeFile(file) + else: + write(stdout, "cannot open file for writing") + inc(i) diff --git a/tests/accept/compile/ttempl3.nim b/tests/accept/compile/ttempl3.nim new file mode 100644 index 000000000..0c8fa9a94 --- /dev/null +++ b/tests/accept/compile/ttempl3.nim @@ -0,0 +1,26 @@ + +template withOpenFile(f: expr, filename: string, mode: TFileMode, + actions: stmt): stmt = + block: + var f: TFile + if open(f, filename, mode): + try: + actions + finally: + close(f) + else: + quit("cannot open for writing: " & filename) + +withOpenFile(txt, "ttempl3.txt", fmWrite): + writeln(txt, "line 1") + txt.writeln("line 2") + +# Test zero argument template: +template ha: expr = myVar[0] + +var + myVar: array[0..1, int] + +ha = 1 +echo(ha) + diff --git a/tests/accept/compile/ttime.nim b/tests/accept/compile/ttime.nim new file mode 100644 index 000000000..bad818816 --- /dev/null +++ b/tests/accept/compile/ttime.nim @@ -0,0 +1,6 @@ +# test the new time module + +import + times + +write(stdout, $getTime()) diff --git a/tests/accept/compile/ttuple1.nim b/tests/accept/compile/ttuple1.nim new file mode 100644 index 000000000..5787cc309 --- /dev/null +++ b/tests/accept/compile/ttuple1.nim @@ -0,0 +1,16 @@ +const romanNumbers = [ + ("M", 1000), ("D", 500), ("C", 100), + ("L", 50), ("X", 10), ("V", 5), ("I", 1) ] + +var c = 0 +for key, val in items(romanNumbers): + inc(c) + stdout.write(key & "=" & $val) + if c < romanNumbers.len: stdout.write(", ") else: echo"" +#echo"" + +proc PrintBiTuple(t: tuple[k: string, v: int]): int = + stdout.write(t.k & "=" & $t.v & ", ") + return 0 + + diff --git a/tests/accept/compile/tvarious.nim b/tests/accept/compile/tvarious.nim new file mode 100644 index 000000000..52dd46184 --- /dev/null +++ b/tests/accept/compile/tvarious.nim @@ -0,0 +1,43 @@ +# Test various aspects + +import + mvarious + +type + PA = ref TA + PB = ref TB + + TB = object + a: PA + + TA = object + b: TB + x: int + +proc getPA(): PA = + var + b: bool + b = not false + return nil + +var + global: int + +var + s: string + i: int + r: TA + +r.b.a.x = 0 +global = global + 1 +exportme() +write(stdout, "Hallo wie heißt du? ") +write(stdout, getPA().x) +s = readLine(stdin) +i = 0 +while i < s.len: + if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") + i = i + 1 + +write(stdout, "Du heißt " & s) + diff --git a/tests/accept/compile/twalker.nim b/tests/accept/compile/twalker.nim new file mode 100644 index 000000000..ba89ee7c6 --- /dev/null +++ b/tests/accept/compile/twalker.nim @@ -0,0 +1,13 @@ +# iterate over all files with a given filter: + +import + os, times + +proc main(filter: string) = + for filename in walkFiles(filter): + writeln(stdout, filename) + + for key, val in iterOverEnvironment(): + writeln(stdout, key & '=' & val) + +main("*.nim") diff --git a/tests/accept/compile/typalias.nim b/tests/accept/compile/typalias.nim new file mode 100644 index 000000000..ba9f38ed9 --- /dev/null +++ b/tests/accept/compile/typalias.nim @@ -0,0 +1,15 @@ + +type + TMyObj = TYourObj + TYourObj = object of TObject + x, y: int + +proc init: TYourObj = + result.x = 0 + result.y = -1 + +proc f(x: var TYourObj) = + nil + +var m: TMyObj = init() +f(m) diff --git a/tests/accept/run/tack.nim b/tests/accept/run/tack.nim new file mode 100644 index 000000000..59535e547 --- /dev/null +++ b/tests/accept/run/tack.nim @@ -0,0 +1,15 @@ +# the Ackermann function + +proc ack(x, y: int): int = + if x != 0: + if y != 0: + return ack(x-1, ack(x, y-1)) + return ack(x-1, 1) + else: + return y + 1 +# if x == 0: return y + 1 +# elif y == 0: return ack(x-1, 1) +# else: return ack(x-1, ack(x, y-1)) + +# echo(ack(0, 0)) +write(stdout, ack(3, 4)) #OUT 125 diff --git a/tests/accept/run/tambsym2.nim b/tests/accept/run/tambsym2.nim new file mode 100644 index 000000000..9178182aa --- /dev/null +++ b/tests/accept/run/tambsym2.nim @@ -0,0 +1,18 @@ +# Test overloading of procs with locals + +type + TMyType = object + len: int + data: string + +proc len(x: TMyType): int {.inline.} = return x.len + +proc x(s: TMyType, len: int) = + writeln(stdout, len(s)) + +var + m: TMyType +m.len = 7 +m.data = "1234" + +x(m, 5) #OUT 7 diff --git a/tests/accept/run/tambsys.nim b/tests/accept/run/tambsys.nim new file mode 100644 index 000000000..bb2622824 --- /dev/null +++ b/tests/accept/run/tambsys.nim @@ -0,0 +1,7 @@ +# Test ambiguous symbols + +import mambsys1, mambsys2 + +var + v: mambsys1.TExport +mambsys2.foo(3) #OUT diff --git a/tests/accept/run/tarray.nim b/tests/accept/run/tarray.nim new file mode 100644 index 000000000..252cbd991 --- /dev/null +++ b/tests/accept/run/tarray.nim @@ -0,0 +1,27 @@ +# simple check for one dimensional arrays + +type + TMyArray = array[0..2, int] + TMyRecord = tuple[x, y: int] + +proc sum(a: TMyarray): int = + result = 0 + var i = 0 + while i < len(a): + inc(result, a[i]) + inc(i) + +proc sum(a: openarray[int]): int = + result = 0 + var i = 0 + while i < len(a): + inc(result, a[i]) + inc(i) + +proc getPos(r: TMyRecord): int = + result = r.x + r.y + +write(stdout, sum([1, 2, 3, 4])) +write(stdout, sum([])) +write(stdout, getPos( (x: 5, y: 7) )) +#OUT 10012 diff --git a/tests/accept/run/tarray2.nim b/tests/accept/run/tarray2.nim new file mode 100644 index 000000000..eb0b75692 --- /dev/null +++ b/tests/accept/run/tarray2.nim @@ -0,0 +1,18 @@ +# simple check for one dimensional arrays + +type + TMyArray = array[0..2, int] + +proc mul(a, b: TMyarray): TMyArray = + result = a + for i in 0..len(a)-1: + result[i] = a[i] * b[i] + +var + x, y, z: TMyArray + +x = [ 4, 5, 6 ] +y = x +echo repr(mul(x, y)) + +#OUT [16, 25, 36] diff --git a/tests/accept/run/tassert.nim b/tests/accept/run/tassert.nim new file mode 100644 index 000000000..9fd18e9bd --- /dev/null +++ b/tests/accept/run/tassert.nim @@ -0,0 +1,16 @@ +# test assert and exception handling + +proc callB() = assert(False) +proc callA() = callB() +proc callC() = callA() + +try: + callC() +except EAssertionFailed: + write(stdout, "assertion failure!") +except: + write(stdout, "unknown exception!") +finally: + system.write(stdout, "this shall be always written") + +assert(false) #OUT assertion failure!this shall be always written diff --git a/tests/accept/run/tbind1.nim b/tests/accept/run/tbind1.nim new file mode 100644 index 000000000..e7eed3e4f --- /dev/null +++ b/tests/accept/run/tbind1.nim @@ -0,0 +1,14 @@ +# Test the new ``bind`` keyword for templates + +proc p1(x: int8, y: int): int = return x + y + +template tempBind(x, y: expr): expr = + bind p1(x, y) + +proc p1(x: int, y: int8): int = return x - y + +# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6, +# because it is not ambiguous there. But it is ambiguous after line 8. + +echo tempBind(1'i8, 2'i8) #OUT 3 + diff --git a/tests/accept/run/tbind3.nim b/tests/accept/run/tbind3.nim new file mode 100644 index 000000000..f7fb4865b --- /dev/null +++ b/tests/accept/run/tbind3.nim @@ -0,0 +1,5 @@ +# Module B +import mbind3 + +echo genId() #OUT 1 + diff --git a/tests/accept/run/tbintre2.nim b/tests/accept/run/tbintre2.nim new file mode 100644 index 000000000..dedc87705 --- /dev/null +++ b/tests/accept/run/tbintre2.nim @@ -0,0 +1,25 @@ +# Same test, but check module boundaries + +import tbintree + +var + root: PBinaryTree[string] + x = newNode("hallo") +add(root, x) +add(root, "world") +if find(root, "world"): + for str in items(root): + stdout.write(str) +else: + stdout.writeln("BUG") + +var + r2: PBinaryTree[int] +add(r2, newNode(110)) +add(r2, 223) +add(r2, 99) +for y in items(r2): + stdout.write(y) + +#OUT halloworld99110223 + diff --git a/tests/accept/run/tbintree.nim b/tests/accept/run/tbintree.nim new file mode 100644 index 000000000..89126eaa5 --- /dev/null +++ b/tests/accept/run/tbintree.nim @@ -0,0 +1,101 @@ +type + TBinaryTree[T] = object # TBinaryTree is a generic type with + # with generic param ``T`` + le, ri: ref TBinaryTree[T] # left and right subtrees; may be nil + data: T # the data stored in a node + PBinaryTree*[A] = ref TBinaryTree[A] # type that is exported + +proc newNode*[T](data: T): PBinaryTree[T] = + # constructor for a node + new(result) + result.data = data + +proc add*[Ty](root: var PBinaryTree[Ty], n: PBinaryTree[Ty]) = + # insert a node into the tree + if root == nil: + root = n + else: + var it = root + while it != nil: + # compare the data items; uses the generic ``cmp`` proc that works for + # any type that has a ``==`` and ``<`` operator + var c = cmp(n.data, it.data) + if c < 0: + if it.le == nil: + it.le = n + return + it = it.le + else: + if it.ri == nil: + it.ri = n + return + it = it.ri + +proc add*[Ty](root: var PBinaryTree[Ty], data: Ty) = + # convenience proc: + add(root, newNode(data)) + +proc find*[Ty2](b: PBinaryTree[Ty2], data: Ty2): bool = + # for testing this needs to be recursive, so that the + # instantiated type is checked for proper tyGenericInst envelopes + if b == nil: + result = false + else: + var c = cmp(data, b.data) + if c < 0: result = find(b.le, data) + elif c > 0: result = find(b.ri, data) + else: result = true + +iterator preorder*[T](root: PBinaryTree[T]): T = + # Preorder traversal of a binary tree. + # Since recursive iterators are not yet implemented, + # this uses an explicit stack: + var stack: seq[PBinaryTree[T]] = @[root] + while stack.len > 0: + var n = stack.pop() + while n != nil: + yield n.data + add(stack, n.ri) # push right subtree onto the stack + n = n.le # and follow the left pointer + +iterator items*[T](root: PBinaryTree[T]): T = + ## Inorder traversal of the binary tree. + var stack: seq[PBinaryTree[T]] = @[] + var n = root + while true: + while n != nil: + add(stack, n) + n = n.le + if stack.len > 0: + n = stack.pop() + yield n.data + n = n.ri + if stack.len == 0 and n == nil: break + +proc debug[T](a: PBinaryTree[T]) = + if a != nil: + debug(a.le) + echo a.data + debug(a.ri) + +when isMainModule: + var + root: PBinaryTree[string] + x = newNode("hallo") + add(root, x) + add(root, "world") + if find(root, "world"): + for str in items(root): + stdout.write(str) + else: + stdout.writeln("BUG") + + var + r2: PBinaryTree[int] + add(r2, newNode(110)) + add(r2, 223) + add(r2, 99) + for y in items(r2): + stdout.write(y) + +#OUT halloworld99110223 diff --git a/tests/accept/run/tcasestm.nim b/tests/accept/run/tcasestm.nim new file mode 100644 index 000000000..277b0bab1 --- /dev/null +++ b/tests/accept/run/tcasestm.nim @@ -0,0 +1,32 @@ +# Test the case statement + +type + tenum = enum eA, eB, eC + +var + x: string = "yyy" + y: Tenum = eA + i: int + +case y +of eA: write(stdout, "a") +of eB, eC: write(stdout, "b or c") + +case x +of "Andreas", "Rumpf": write(stdout, "Hallo Meister!") +of "aa", "bb": write(stdout, "Du bist nicht mein Meister") +of "cc", "hash", "when": nil +of "will", "it", "finally", "be", "generated": nil + +case i +of 1..5, 8, 9: nil +of 6, 7: nil +elif x == "Ha": + nil +elif x == "yyy": + write(stdout, x) +else: + nil + +#OUT ayyy + diff --git a/tests/accept/run/tclosure.nim b/tests/accept/run/tclosure.nim new file mode 100644 index 000000000..761e9a8f3 --- /dev/null +++ b/tests/accept/run/tclosure.nim @@ -0,0 +1,26 @@ +# Test the closure implementation + +proc map(n: var openarray[int], fn: proc (x: int): int {.closure}) = + for i in 0..n.len-1: n[i] = fn(n[i]) + +proc foldr(n: openarray[int], fn: proc (x, y: int): int {.closure}): int = + for i in 0..n.len-1: + result = fn(result, n[i]) + +var + myData: array[0..4, int] = [0, 1, 2, 3, 4] + +proc testA() = + var p = 0 + map(myData, proc (x: int): int = + result = x + 1 shl (proc (y: int): int = + return y + p + )(0) + inc(p)) + +testA() +for x in items(myData): + write(stout, x) +#OUT 2 4 6 8 10 + + diff --git a/tests/accept/run/tcnstseq.nim b/tests/accept/run/tcnstseq.nim new file mode 100644 index 000000000..4f389bb3b --- /dev/null +++ b/tests/accept/run/tcnstseq.nim @@ -0,0 +1,11 @@ +# Test the new implicit conversion from sequences to arrays in a constant +# context. + +import strutils + +const + myWords = "Angelika Anne Anna Anka Anja".split() + +for x in items(myWords): + write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja + diff --git a/tests/accept/run/tconstr2.nim b/tests/accept/run/tconstr2.nim new file mode 100644 index 000000000..7687a416c --- /dev/null +++ b/tests/accept/run/tconstr2.nim @@ -0,0 +1,20 @@ +# Test array, record constructors + +type + TComplexRecord = tuple[ + s: string, + x, y: int, + z: float, + chars: set[char]] + +const + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {})] + otherThings = [ # the same + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] + +write(stdout, things[0].x) +#OUT 69 + diff --git a/tests/accept/run/tcopy.nim b/tests/accept/run/tcopy.nim new file mode 100644 index 000000000..6cb2ec14c --- /dev/null +++ b/tests/accept/run/tcopy.nim @@ -0,0 +1,19 @@ +# tests the copy proc + +import + strutils + +proc main() = + const + example = r"TEMP=C:\Programs\xyz\bin" + var + a, b: string + p: int + p = find(example, "=") + a = copy(example, 0, p-1) + b = copy(example, p+1) + writeln(stdout, a & '=' & b) + #writeln(stdout, b) + +main() +#OUT TEMP=C:\Programs\xyz\bin diff --git a/tests/accept/run/tcurrncy.nim b/tests/accept/run/tcurrncy.nim new file mode 100644 index 000000000..fa08d620b --- /dev/null +++ b/tests/accept/run/tcurrncy.nim @@ -0,0 +1,32 @@ +template Additive(typ: typeDesc): stmt = + proc `+` *(x, y: typ): typ {.borrow.} + proc `-` *(x, y: typ): typ {.borrow.} + + # unary operators: + proc `+` *(x: typ): typ {.borrow.} + proc `-` *(x: typ): typ {.borrow.} + +template Multiplicative(typ, base: typeDesc): stmt = + proc `*` *(x: typ, y: base): typ {.borrow.} + proc `*` *(x: base, y: typ): typ {.borrow.} + proc `div` *(x: typ, y: base): typ {.borrow.} + proc `mod` *(x: typ, y: base): typ {.borrow.} + +template Comparable(typ: typeDesc): stmt = + proc `<` * (x, y: typ): bool {.borrow.} + proc `<=` * (x, y: typ): bool {.borrow.} + proc `==` * (x, y: typ): bool {.borrow.} + +template DefineCurrency(typ, base: expr): stmt = + type + typ* = distinct base + Additive(typ) + Multiplicative(typ, base) + Comparable(typ) + + proc `$` * (t: typ): string {.borrow.} + +DefineCurrency(TDollar, int) +DefineCurrency(TEuro, int) +echo($( 12.TDollar + 13.TDollar )) #OUT 25 + diff --git a/tests/accept/run/tfinally.nim b/tests/accept/run/tfinally.nim new file mode 100644 index 000000000..df6397125 --- /dev/null +++ b/tests/accept/run/tfinally.nim @@ -0,0 +1,10 @@ +# Test return in try statement: + +proc main: int = + try: + return 1 + finally: + echo "came here" + +discard main() #OUT came here + diff --git a/tests/accept/run/tfloat1.nim b/tests/accept/run/tfloat1.nim new file mode 100644 index 000000000..89911dd61 --- /dev/null +++ b/tests/accept/run/tfloat1.nim @@ -0,0 +1,8 @@ +# Test new floating point exceptions + +{.floatChecks: on.} + +var x = 0.8 +var y = 0.0 + +echo x / y #OUT Error: unhandled exception: FPU operation caused an overflow [EFloatOverflow] diff --git a/tests/accept/run/tfloat2.nim b/tests/accept/run/tfloat2.nim new file mode 100644 index 000000000..92421d446 --- /dev/null +++ b/tests/accept/run/tfloat2.nim @@ -0,0 +1,8 @@ +# Test new floating point exceptions + +{.floatChecks: on.} + +var x = 0.0 +var y = 0.0 + +echo x / y #OUT Error: unhandled exception: FPU operation caused a NaN result [EFloatInvalidOp] diff --git a/tests/accept/run/tformat.nim b/tests/accept/run/tformat.nim new file mode 100644 index 000000000..aba35504b --- /dev/null +++ b/tests/accept/run/tformat.nim @@ -0,0 +1,6 @@ +# Tests the new format proc (including the & and &= operators) + +import strutils + +echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"]) +#OUT Hi Andreas! How do you feel, Rumpf? diff --git a/tests/accept/run/thintoff.nim b/tests/accept/run/thintoff.nim new file mode 100644 index 000000000..7aff283d6 --- /dev/null +++ b/tests/accept/run/thintoff.nim @@ -0,0 +1,6 @@ + +{.hint[XDeclaredButNotUsed]: off.} +var + x: int + +echo x #OUT 0 diff --git a/tests/accept/run/tinit.nim b/tests/accept/run/tinit.nim new file mode 100644 index 000000000..85475ce94 --- /dev/null +++ b/tests/accept/run/tinit.nim @@ -0,0 +1,6 @@ +# Test the new init section in modules + +import minit + +write(stdout, "Hallo from main module!\n") +#OUT Hallo from module! Hallo from main module! diff --git a/tests/accept/run/tints.nim b/tests/accept/run/tints.nim new file mode 100644 index 000000000..f2b52c134 --- /dev/null +++ b/tests/accept/run/tints.nim @@ -0,0 +1,41 @@ +# Test the different integer operations + +var testNumber = 0 + +template test(opr, a, b, c: expr): stmt = + # test the expression at compile and runtime + block: + const constExpr = opr(a, b) + when constExpr != c: + {.error: "Test failed " & $constExpr & " " & $c.} + inc(testNumber) + #Echo("Test: " & $testNumber) + var aa = a + var bb = b + var varExpr = opr(aa, bb) + assert(varExpr == c) + +test(`+`, 12'i8, -13'i16, -1'i16) +test(`shl`, 0b11, 0b100, 0b110000) +test(`shl`, 0b11'i32, 0b100'i64, 0b110000'i64) +test(`shl`, 0b11'i32, 0b100'i32, 0b110000'i32) + +test(`or`, 0xf0f0'i16, 0x0d0d'i16, 0xfdfd'i16) +test(`and`, 0xf0f0'i16, 0xfdfd'i16, 0xf0f0'i16) + +test(`shr`, 0xffffffffffffffff'i64, 0x4'i64, 0x0fffffffffffffff'i64) +test(`shr`, 0xffff'i16, 0x4'i16, 0x0fff'i16) +test(`shr`, 0xff'i8, 0x4'i8, 0x0f'i8) + +test(`shr`, 0xffffffff'i64, 0x4'i64, 0x0fffffff'i64) +test(`shr`, 0xffffffff'i32, 0x4'i32, 0x0fffffff'i32) + +test(`shl`, 0xffffffffffffffff'i64, 0x4'i64, 0xfffffffffffffff0'i64) +test(`shl`, 0xffff'i16, 0x4'i16, 0xfff0'i16) +test(`shl`, 0xff'i8, 0x4'i8, 0xf0'i8) + +test(`shl`, 0xffffffff'i64, 0x4'i64, 0xffffffff0'i64) +test(`shl`, 0xffffffff'i32, 0x4'i32, 0xfffffff0'i32) + +Echo("Success") #OUT Success + diff --git a/tests/accept/run/tisopr.nim b/tests/accept/run/tisopr.nim new file mode 100644 index 000000000..d52859b09 --- /dev/null +++ b/tests/accept/run/tisopr.nim @@ -0,0 +1,20 @@ +# Test is operator + +type + TMyType = object + len: int + data: string + + TOtherType = object of TMyType + +proc p(x: TMyType): bool = + return x is TOtherType + +var + m: TMyType + n: TOtherType + +write(stdout, p(m)) +write(stdout, p(n)) + +#OUT falsetrue diff --git a/tests/accept/run/titer2.nim b/tests/accept/run/titer2.nim new file mode 100644 index 000000000..b9cdb53fe --- /dev/null +++ b/tests/accept/run/titer2.nim @@ -0,0 +1,10 @@ +# Try to break the transformation pass: +iterator iterAndZero(a: var openArray[int]): int = + for i in 0..len(a)-1: + yield a[i] + a[i] = 0 + +var x = [[1, 2, 3], [4, 5, 6]] +for y in iterAndZero(x[0]): write(stdout, $y) +#OUT 123 + diff --git a/tests/accept/run/titer3.nim b/tests/accept/run/titer3.nim new file mode 100644 index 000000000..d0e121445 --- /dev/null +++ b/tests/accept/run/titer3.nim @@ -0,0 +1,17 @@ + +iterator count1_3: int = + yield 1 + yield 2 + yield 3 + +for x in count1_3(): + write(stdout, $x) + +# yield inside an iterator, but not in a loop: +iterator iter1(a: openArray[int]): int = + yield a[0] + +var x = [[1, 2, 3], [4, 5, 6]] +for y in iter1(x[0]): write(stdout, $y) + +#OUT 1231 \ No newline at end of file diff --git a/tests/accept/run/titer5.nim b/tests/accept/run/titer5.nim new file mode 100644 index 000000000..1ac37ba66 --- /dev/null +++ b/tests/accept/run/titer5.nim @@ -0,0 +1,10 @@ +# Test method call syntax for iterators: +import strutils + +const lines = """abc xyz""" + +for x in lines.split(): + stdout.write(x) + +#OUT abcxyz + diff --git a/tests/accept/run/tlowhigh.nim b/tests/accept/run/tlowhigh.nim new file mode 100644 index 000000000..79f5c5b95 --- /dev/null +++ b/tests/accept/run/tlowhigh.nim @@ -0,0 +1,18 @@ +# Test the magic low() and high() procs + +type + myEnum = enum e1, e2, e3, e4, e5 + +var + a: array [myEnum, int] + +for i in low(a) .. high(a): + a[i] = 0 + +proc sum(a: openarray[int]): int = + result = 0 + for i in low(a)..high(a): + inc(result, a[i]) + +write(stdout, sum([1, 2, 3, 4])) +#OUT 10 diff --git a/tests/accept/run/tmatrix.nim b/tests/accept/run/tmatrix.nim new file mode 100644 index 000000000..a162d0f10 --- /dev/null +++ b/tests/accept/run/tmatrix.nim @@ -0,0 +1,60 @@ +# Test overloading of [] with multiple indices + +type + TMatrix* = object + data: seq[float] + fWidth, fHeight: int + +template `|`(x, y: int): expr = y * m.fWidth + x + +proc createMatrix*(width, height: int): TMatrix = + result.fWidth = width + result.fHeight = height + newSeq(result.data, width*height) + +proc width*(m: TMatrix): int {.inline.} = return m.fWidth +proc height*(m: TMatrix): int {.inline.} = return m.fHeight + +proc `[,]`*(m: TMatrix, x, y: int): float {.inline.} = + result = m.data[x|y] + +proc `[,]=`*(m: var TMatrix, x, y: int, val: float) {.inline.} = + m.data[x|y] = val + +proc `[$ .. $, $ .. $]`*(m: TMatrix, a, b, c, d: int): TMatrix = + result = createMatrix(b-a+1, d-c+1) + for x in a..b: + for y in c..d: + result[x-a, y-c] = m[x, y] + +proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: float) = + for x in a..b: + for y in c..d: + m[x, y] = val + +proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: TMatrix) = + assert val.width == b-a+1 + assert val.height == d-c+1 + for x in a..b: + for y in c..d: + m[x, y] = val[x-a, y-c] + +proc `-|`*(m: TMatrix): TMatrix = + ## transposes a matrix + result = createMatrix(m.height, m.width) + for x in 0..m.width-1: + for y in 0..m.height-1: result[y,x] = m[x,y] + +#m.row(0, 2) # select row +#m.col(0, 89) # select column + +const + w = 3 + h = 20 + +var m = createMatrix(w, h) +for i in 0..w-1: + m[i, i] = 1.0 + +for i in 0..w-1: + stdout.write(m[i,i]) #OUT 111 diff --git a/tests/accept/run/tmultim1.nim b/tests/accept/run/tmultim1.nim new file mode 100644 index 000000000..5d807e4c9 --- /dev/null +++ b/tests/accept/run/tmultim1.nim @@ -0,0 +1,23 @@ +# Test multi methods + +type + TExpr = object + TLiteral = object of TExpr + x: int + TPlusExpr = object of TExpr + a, b: ref TExpr + +method eval(e: ref TExpr): int = quit "to override!" +method eval(e: ref TLiteral): int = return e.x +method eval(e: ref TPlusExpr): int = return eval(e.a) + eval(e.b) + +proc newLit(x: int): ref TLiteral = + new(result) + result.x = x + +proc newPlus(a, b: ref TExpr): ref TPlusExpr = + new(result) + result.a = a + result.b = b + +echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7 diff --git a/tests/accept/run/tmultim2.nim b/tests/accept/run/tmultim2.nim new file mode 100644 index 000000000..bf3b5fd6e --- /dev/null +++ b/tests/accept/run/tmultim2.nim @@ -0,0 +1,30 @@ +# Test multi methods + +type + TThing = object + TUnit = object of TThing + x: int + TParticle = object of TThing + a, b: int + +method collide(a, b: TThing) {.inline.} = + quit "to override!" + +method collide(a: TThing, b: TUnit) {.inline.} = + write stdout, "collide: thing, unit " + +method collide(a: TUnit, b: TThing) {.inline.} = + write stdout, "collide: unit, thing " + +proc test(a, b: TThing) {.inline.} = + collide(a, b) + +var + a: TThing + b, c: TUnit +collide(b, c) # ambiguous unit, thing or thing, unit? -> prefer unit, thing! +test(b, c) +collide(a, b) +#OUT collide: unit, thing collide: unit, thing collide: thing, unit + + diff --git a/tests/accept/run/tnestif.nim b/tests/accept/run/tnestif.nim new file mode 100644 index 000000000..558fe8d07 --- /dev/null +++ b/tests/accept/run/tnestif.nim @@ -0,0 +1,18 @@ +# test nested ifs + +var + x, y: int +x = 2 +if x == 0: + write(stdout, "i == 0") + if y == 0: + write(stdout, x) + else: + write(stdout, y) +elif x == 1: + write(stdout, "i == 1") +elif x == 2: + write(stdout, "i == 2") +else: + write(stdout, "looks like Python") +#OUT i == 2 diff --git a/tests/accept/run/tnestprc.nim b/tests/accept/run/tnestprc.nim new file mode 100644 index 000000000..b7326e032 --- /dev/null +++ b/tests/accept/run/tnestprc.nim @@ -0,0 +1,10 @@ +# Test nested procs without closures + +proc Add3(x: int): int = + proc add(x, y: int): int {.noconv.} = + result = x + y + + result = add(x, 3) + +echo Add3(7) #OUT 10 + diff --git a/tests/accept/run/toop1.nim b/tests/accept/run/toop1.nim new file mode 100644 index 000000000..8bae002e7 --- /dev/null +++ b/tests/accept/run/toop1.nim @@ -0,0 +1,82 @@ +# Test the stuff in the tutorial +import macros + +type + TFigure = object of TObject # abstract base class: + draw: proc (my: var TFigure) # concrete classes implement this proc + +proc init(f: var TFigure) = + f.draw = nil + +type + TCircle = object of TFigure + radius: int + +proc drawCircle(my: var TCircle) = stdout.writeln("o " & $my.radius) + +proc init(my: var TCircle) = + init(TFigure(my)) # call base constructor + my.radius = 5 + my.draw = drawCircle + +type + TRectangle = object of TFigure + width, height: int + +proc drawRectangle(my: var TRectangle) = stdout.write("[]") + +proc init(my: var TRectangle) = + init(TFigure(my)) # call base constructor + my.width = 5 + my.height = 10 + my.draw = drawRectangle + +macro `!` (n: expr): stmt = + result = newNimNode(nnkCall, n) + var dot = newNimNode(nnkDotExpr, n) + dot.add(n[1]) # obj + if n[2].kind == nnkCall: + # transforms ``obj!method(arg1, arg2, ...)`` to + # ``(obj.method)(obj, arg1, arg2, ...)`` + dot.add(n[2][0]) # method + result.add(dot) + result.add(n[1]) # obj + for i in 1..n[2].len-1: + result.add(n[2][i]) + else: + # transforms ``obj!method`` to + # ``(obj.method)(obj)`` + dot.add(n[2]) # method + result.add(dot) + result.add(n[1]) # obj + +type + TSocket* = object of TObject + FHost: int # cannot be accessed from the outside of the module + # the `F` prefix is a convention to avoid clashes since + # the accessors are named `host` + +proc `host=`*(s: var TSocket, value: int) {.inline.} = + ## setter of hostAddr + s.FHost = value + +proc host*(s: TSocket): int {.inline.} = + ## getter of hostAddr + return s.FHost + +var + s: TSocket +s.host = 34 # same as `host=`(s, 34) +stdout.write(s.host) + +# now use these classes: +var + r: TRectangle + c: TCircle +init(r) +init(c) +r!draw +c!draw() + +#OUT 34[]o 5 + diff --git a/tests/accept/run/topenarrayrepr.nim b/tests/accept/run/topenarrayrepr.nim new file mode 100644 index 000000000..7e976540f --- /dev/null +++ b/tests/accept/run/topenarrayrepr.nim @@ -0,0 +1,11 @@ +type + TProc = proc (n: int, m: openarray[int64]) + +proc Foo(x: int, P: TProc) = + P(x, [ 1'i64 ]) + +proc Bar(n: int, m: openarray[int64]) = + echo($n & " - " & repr(m)) + +Foo(5, Bar) #OUT 5 - [1] + diff --git a/tests/accept/run/topenlen.nim b/tests/accept/run/topenlen.nim new file mode 100644 index 000000000..b9d7fbc2d --- /dev/null +++ b/tests/accept/run/topenlen.nim @@ -0,0 +1,12 @@ +# Tests a special bug + +proc choose(b: openArray[string]): string = return b[0] + +proc p(a, b: openarray[string]): int = + result = a.len + b.len - 1 + for j in 0 .. a.len: inc(result) + discard choose(a) + discard choose(b) + +discard choose(["sh", "-c", $p([""], ["a"])]) +echo($p(["", "ha", "abc"], ["xyz"])) #OUT 7 diff --git a/tests/accept/run/toverflw.nim b/tests/accept/run/toverflw.nim new file mode 100644 index 000000000..c8f194e68 --- /dev/null +++ b/tests/accept/run/toverflw.nim @@ -0,0 +1,15 @@ +# Tests emc's ability to detect overflows + +{.push overflowChecks: on.} + +var + a, b: int +a = high(int) +b = -2 +try: + writeln(stdout, b - a) +except EOverflow: + writeln(stdout, "the computation overflowed") + +{.pop.} # overflow check +#OUT the computation overflowed diff --git a/tests/accept/run/toverl2.nim b/tests/accept/run/toverl2.nim new file mode 100644 index 000000000..2d1225c6f --- /dev/null +++ b/tests/accept/run/toverl2.nim @@ -0,0 +1,21 @@ +# Test new overloading resolution rules + +import strutils + +proc toverl2(x: int): string = return $x +proc toverl2(x: bool): string = return $x + +iterator toverl2(x: int): int = + var res = 0 + while res < x: + yield res + inc(res) + +var + pp: proc (x: bool): string = toverl2 +stdout.write(pp(true)) +for x in toverl2(3): + stdout.write(toverl2(x)) +stdout.write("\n") +#OUT true012 + diff --git a/tests/accept/run/toverlop.nim b/tests/accept/run/toverlop.nim new file mode 100644 index 000000000..f11275644 --- /dev/null +++ b/tests/accept/run/toverlop.nim @@ -0,0 +1,10 @@ +# Test operator overloading + +proc `%` (a, b: int): int = + return a mod b + +var x, y: int +x = 15 +y = 6 +write(stdout, x % y) +#OUT 3 diff --git a/tests/accept/run/toverwr.nim b/tests/accept/run/toverwr.nim new file mode 100644 index 000000000..f2b42df15 --- /dev/null +++ b/tests/accept/run/toverwr.nim @@ -0,0 +1,7 @@ +# Test the overloading resolution in connection with a qualifier + +proc write(t: TFile, s: string) = + nil # a nop + +system.write(stdout, "hallo") +#OUT hallo diff --git a/tests/accept/run/tovfint.nim b/tests/accept/run/tovfint.nim new file mode 100644 index 000000000..91eda8d0b --- /dev/null +++ b/tests/accept/run/tovfint.nim @@ -0,0 +1,17 @@ +# this tests the new overflow literals + +var + i: int +i = int(0xffffffff) +when defined(cpu64): + if i == 4294967295: + write(stdout, "works!\n") + else: + write(stdout, "broken!\n") +else: + if i == -1: + write(stdout, "works!\n") + else: + write(stdout, "broken!\n") + +#OUT works! diff --git a/tests/accept/run/tpos.nim b/tests/accept/run/tpos.nim new file mode 100644 index 000000000..114d39c05 --- /dev/null +++ b/tests/accept/run/tpos.nim @@ -0,0 +1,29 @@ +# test this particular function + +proc mypos(sub, s: string, start: int = 0): int = + var + i, j, M, N: int + M = sub.len + N = s.len + i = start + j = 0 + if i >= N: + result = -1 + else: + while True: + if s[i] == sub[j]: + Inc(i) + Inc(j) + else: + i = i - j + 1 + j = 0 + if (j >= M) or (i >= N): break + if j >= M: + result = i - M + else: + result = -1 + +var sub = "hallo" +var s = "world hallo" +write(stdout, mypos(sub, s)) +#OUT 6 diff --git a/tests/accept/run/tprintf.nim b/tests/accept/run/tprintf.nim new file mode 100644 index 000000000..14687a937 --- /dev/null +++ b/tests/accept/run/tprintf.nim @@ -0,0 +1,10 @@ +# Test a printf proc + +proc printf(file: TFile, args: openarray[string]) = + var i = 0 + while i < args.len: + write(file, args[i]) + inc(i) + +printf(stdout, ["Andreas ", "Rumpf\n"]) +#OUT Andreas Rumpf diff --git a/tests/accept/run/tprocvar.nim b/tests/accept/run/tprocvar.nim new file mode 100644 index 000000000..f51543dfa --- /dev/null +++ b/tests/accept/run/tprocvar.nim @@ -0,0 +1,26 @@ +# test variables of type proc + +proc pa() {.cdecl.} = write(stdout, "pa") +proc pb() {.cdecl.} = write(stdout, "pb") +proc pc() {.cdecl.} = write(stdout, "pc") +proc pd() {.cdecl.} = write(stdout, "pd") +proc pe() {.cdecl.} = write(stdout, "pe") + +const + algos = [pa, pb, pc, pd, pe] + +var + x: proc (a, b: int): int {.cdecl.} + +proc ha(c, d: int): int {.cdecl.} = + echo(c + d) + result = c + d + +for a in items(algos): + a() + +x = ha +discard x(3, 4) + +#OUT papbpcpdpe7 + diff --git a/tests/accept/run/tquotewords.nim b/tests/accept/run/tquotewords.nim new file mode 100644 index 000000000..462293b40 --- /dev/null +++ b/tests/accept/run/tquotewords.nim @@ -0,0 +1,19 @@ +# Test an idea I recently had: + +import macros + +macro quoteWords(n: expr): expr = + result = newNimNode(nnkBracket, n) + for i in 1..n.len-1: + expectKind(n[i], nnkIdent) + result.add(toStrLit(n[i])) + +const + myWordList = quoteWords(this, an, example) + +var s = "" +for w in items(myWordList): + s.add(w) + +echo s #OUT thisanexample + diff --git a/tests/accept/run/tregex.nim b/tests/accept/run/tregex.nim new file mode 100644 index 000000000..d9d22d603 --- /dev/null +++ b/tests/accept/run/tregex.nim @@ -0,0 +1,19 @@ +# Test the new regular expression module +# which is based on the PCRE library + +import + regexprs + +if "keyA = valueA" =~ r"\s*(\w+)\s*\=\s*(\w+)": + write(stdout, "key: ", matches[1]) +elif "# comment!" =~ r"\s*(\#.*)": + echo("comment: ", matches[1]) +else: + echo("Bug!") + +if "Username".match("[A-Za-z]+"): + echo("Yes!") +else: + echo("Bug!") + +#OUT key: keyAYes! diff --git a/tests/accept/run/treguse.nim b/tests/accept/run/treguse.nim new file mode 100644 index 000000000..dc805fc70 --- /dev/null +++ b/tests/accept/run/treguse.nim @@ -0,0 +1,21 @@ +# Test the register usage of the virtual machine and +# the blocks in var statements + +proc main(a, b: int) = + var x = 0 + write(stdout, x) + if x == 0: + var y = 55 + write(stdout, y) + write(stdout, "this should be the case") + var input = "" + if input == "Andreas": + write(stdout, "wow") + else: + write(stdout, "hugh") + else: + var z = 66 + write(stdout, z) # "bug!") + +main(45, 1000) +#OUT 055this should be the casehugh diff --git a/tests/accept/run/tromans.nim b/tests/accept/run/tromans.nim new file mode 100644 index 000000000..12deca1ea --- /dev/null +++ b/tests/accept/run/tromans.nim @@ -0,0 +1,65 @@ +import + strutils + +## Convert an integer to a Roman numeral +# See http://en.wikipedia.org/wiki/Roman_numerals for reference + +proc raiseInvalidValue(msg: string) {.noreturn.} = + # Yes, we really need a shorthand for this code... + var e: ref EInvalidValue + new(e) + e.msg = msg + raise e + +# I should use a class, perhaps. +# --> No. Why introduce additional state into such a simple and nice +# interface? State is evil. :D + +proc RomanToDecimal(romanVal: string): int = + result = 0 + var prevVal = 0 + for i in countdown(romanVal.len - 1, 0): + var val = 0 + case romanVal[i] + of 'I', 'i': val = 1 + of 'V', 'v': val = 5 + of 'X', 'x': val = 10 + of 'L', 'l': val = 50 + of 'C', 'c': val = 100 + of 'D', 'd': val = 500 + of 'M', 'm': val = 1000 + else: raiseInvalidValue("Incorrect character in roman numeral! (" & + $romanVal[i] & ")") + if val >= prevVal: + inc(result, val) + else: + dec(result, val) + prevVal = val + +proc DecimalToRoman(decValParam: int): string = + # Apparently numbers cannot be above 4000 + # Well, they can be (using overbar or parenthesis notation) + # but I see little interest (beside coding challenge) in coding them as + # we rarely use huge Roman numeral. + const romanComposites = [ + ("M", 1000), ("CM", 900), + ("D", 500), ("CD", 400), ("C", 100), + ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), + ("V", 5), ("IV", 4), ("I", 1)] + if decValParam < 1 or decValParam > 3999: + raiseInvalidValue("number not representable") + result = "" + var decVal = decValParam + for key, val in items(romanComposites): + while decVal >= val: + dec(decVal, val) + result.add(key) + +for i in 1..100: + if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG" + +for i in items([1238, 1777, 3830, 2401, 379, 33, 940, 3973]): + if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG" + +echo "success" #OUT success + diff --git a/tests/accept/run/tseqcon.nim b/tests/accept/run/tseqcon.nim new file mode 100644 index 000000000..935da86b5 --- /dev/null +++ b/tests/accept/run/tseqcon.nim @@ -0,0 +1,45 @@ +# Test the add proc for sequences and strings + +const + nestedFixed = true + +type + TRec {.final.} = object + x, y: int + s: string + seq: seq[string] + TRecSeq = seq[TRec] + +proc test() = + var s, b: seq[string] + s = @[] + add(s, "Hi") + add(s, "there, ") + add(s, "what's your name?") + + b = s # deep copying here! + b[0][1] = 'a' + + for i in 0 .. len(s)-1: + write(stdout, s[i]) + for i in 0 .. len(b)-1: + write(stdout, b[i]) + + +when nestedFixed: + proc nested() = + var + s: seq[seq[string]] + for i in 0..10_000: # test if the garbage collector + # now works with sequences + s = @[ + @["A", "B", "C", "D"], + @["E", "F", "G", "H"], + @["I", "J", "K", "L"], + @["M", "N", "O", "P"]] + +test() +when nestedFixed: + nested() + +#OUT Hithere, what's your name?Hathere, what's your name? diff --git a/tests/accept/run/tsets.nim b/tests/accept/run/tsets.nim new file mode 100644 index 000000000..08ab3e54b --- /dev/null +++ b/tests/accept/run/tsets.nim @@ -0,0 +1,58 @@ +# Test the handling of sets + +import + strutils + +proc testSets(s: var set[char]) = + s = {'A', 'B', 'C', 'E'..'G'} + {'Z'} + s + +# test sets if the first element is different from 0: +type + TAZ = range['a'..'z'] + TAZset = set[TAZ] + + TTokType* = enum + tkInvalid, tkEof, + tkSymbol, + tkAddr, tkAnd, tkAs, tkAsm, tkBlock, tkBreak, tkCase, tkCast, tkConst, + tkContinue, tkConverter, tkDiscard, tkDiv, tkElif, tkElse, tkEnd, tkEnum, + tkExcept, tkException, tkFinally, tkFor, tkFrom, tkGeneric, tkIf, tkImplies, + tkImport, tkIn, tkInclude, tkIs, tkIsnot, tkIterator, tkLambda, tkMacro, + tkMethod, tkMod, tkNil, tkNot, tkNotin, tkObject, tkOf, tkOr, tkOut, tkProc, + tkPtr, tkRaise, tkRecord, tkRef, tkReturn, tkShl, tkShr, tkTemplate, tkTry, + tkType, tkVar, tkWhen, tkWhere, tkWhile, tkWith, tkWithout, tkXor, tkYield, + tkIntLit, tkInt8Lit, tkInt16Lit, tkInt32Lit, tkInt64Lit, tkFloatLit, + tkFloat32Lit, tkFloat64Lit, tkStrLit, tkRStrLit, tkTripleStrLit, tkCharLit, + tkRCharLit, tkParLe, tkParRi, tkBracketLe, tkBracketRi, tkCurlyLe, + tkCurlyRi, tkBracketDotLe, tkBracketDotRi, + tkCurlyDotLe, tkCurlyDotRi, + tkParDotLe, tkParDotRi, + tkComma, tkSemiColon, tkColon, tkEquals, tkDot, tkDotDot, tkHat, tkOpr, + tkComment, tkAccent, tkInd, tkSad, tkDed, + tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr + TTokTypeRange = range[tkSymbol..tkDed] + TTokTypes* = set[TTokTypeRange] + +const + toktypes: TTokTypes = {TTokTypeRange(tkSymbol)..pred(tkIntLit), + tkStrLit..tkTripleStrLit} + +var + s: set[char] + a: TAZset +s = {'0'..'9'} +testSets(s) +if 'F' in s: write(stdout, "Ha ein F ist in s!\n") +else: write(stdout, "BUG: F ist nicht in s!\n") +a = {} #{'a'..'z'} +for x in low(TAZ) .. high(TAZ): + incl(a, x) + if x in a: nil + else: write(stdout, "BUG: something not in a!\n") + +for x in low(TTokTypeRange) .. high(TTokTypeRange): + if x in tokTypes: + nil + #writeln(stdout, "the token '$1' is in the set" % repr(x)) + +#OUT Ha ein F ist in s! diff --git a/tests/accept/run/tsidee2.nim b/tests/accept/run/tsidee2.nim new file mode 100644 index 000000000..2eaec01d7 --- /dev/null +++ b/tests/accept/run/tsidee2.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int = return x + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) #OUT 5 + diff --git a/tests/accept/run/tsidee3.nim b/tests/accept/run/tsidee3.nim new file mode 100644 index 000000000..be94192e7 --- /dev/null +++ b/tests/accept/run/tsidee3.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int {.noSideEffect.} = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #OUT 5 + diff --git a/tests/accept/run/tsimmeth.nim b/tests/accept/run/tsimmeth.nim new file mode 100644 index 000000000..3f5f810e6 --- /dev/null +++ b/tests/accept/run/tsimmeth.nim @@ -0,0 +1,8 @@ +# Test method simulation + +import strutils + +var x = "hallo world!".toLower.toUpper +x.echo() +#OUT HALLO WORLD! + diff --git a/tests/accept/run/tsplit.nim b/tests/accept/run/tsplit.nim new file mode 100644 index 000000000..711696b9e --- /dev/null +++ b/tests/accept/run/tsplit.nim @@ -0,0 +1,14 @@ +import strutils + +var s = "" +for w in split("|abc|xy|z", {'|'}): + s.add("#") + s.add(w) + +if s == "#abc#xy#z": + echo "true" +else: + echo "false" + +#OUT true + diff --git a/tests/accept/run/tstrange.nim b/tests/accept/run/tstrange.nim new file mode 100644 index 000000000..13aab2302 --- /dev/null +++ b/tests/accept/run/tstrange.nim @@ -0,0 +1,17 @@ +# test for extremely strange bug + +proc ack(x: int, y: int): int = + if x != 0: + if y != 5: + return y + return x + return x+y + +proc gen[T](a: T) = + write(stdout, a) + + +gen("hallo") +write(stdout, ack(5, 4)) +#OUT hallo4 + diff --git a/tests/accept/run/tstrlits.nim b/tests/accept/run/tstrlits.nim new file mode 100644 index 000000000..48ae08212 --- /dev/null +++ b/tests/accept/run/tstrlits.nim @@ -0,0 +1,14 @@ +# Test the new different string literals + +const + tripleEmpty = """"long string"""""""" # "long string """"" + + rawQuote = r"a""" + + raw = r"abc""def" + +stdout.write(rawQuote) +stdout.write(tripleEmpty) +stdout.write(raw) +#OUT a""long string"""""abc"def + diff --git a/tests/accept/run/tstrutil.nim b/tests/accept/run/tstrutil.nim new file mode 100644 index 000000000..0468dfa0c --- /dev/null +++ b/tests/accept/run/tstrutil.nim @@ -0,0 +1,24 @@ +# test the new strutils module + +import + strutils + +proc testStrip() = + write(stdout, strip(" ha ")) + +proc main() = + testStrip() + for p in split("/home/a1:xyz:/usr/bin", {':'}): + write(stdout, p) + + +assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0) +assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1) +assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5) +assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3) +assert(editDistance("prefix__hallo_suffix", "prefix") == 14) +assert(editDistance("prefix__hallo_suffix", "suffix") == 14) +assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2) + +main() +#OUT ha/home/a1xyz/usr/bin diff --git a/tests/accept/run/tvardecl.nim b/tests/accept/run/tvardecl.nim new file mode 100644 index 000000000..496601e3a --- /dev/null +++ b/tests/accept/run/tvardecl.nim @@ -0,0 +1,9 @@ +# Test the new variable declaration syntax + +var + x = 0 + s = "Hallo" + a, b: int = 4 + +write(stdout, a) +write(stdout, b) #OUT 44 diff --git a/tests/accept/run/tvarnums.nim b/tests/accept/run/tvarnums.nim new file mode 100644 index 000000000..1b683ad94 --- /dev/null +++ b/tests/accept/run/tvarnums.nim @@ -0,0 +1,136 @@ +# Test variable length binary integers + +import + strutils + +type + TBuffer = array [0..10, int8] + +proc toVarNum(x: int32, b: var TBuffer) = + # encoding: first bit indicates end of number (0 if at end) + # second bit of the first byte denotes the sign (1 --> negative) + var a = x + if x != low(x): + # low(int) is a special case, + # because abs() does not work here! + # we leave x as it is and use the check >% instead of > + # for low(int) this is needed and positive numbers are not affected + # anyway + a = abs(x) + # first 6 bits: + b[0] = toU8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63)) + a = a shr 6'i32 # skip first 6 bits + var i = 1 + while a != 0'i32: + b[i] = toU8(ord(a >% 127'i32) shl 7 or (int(a) and 127)) + inc(i) + a = a shr 7'i32 + +proc toVarNum64(x: int64, b: var TBuffer) = + # encoding: first bit indicates end of number (0 if at end) + # second bit of the first byte denotes the sign (1 --> negative) + var a = x + if x != low(x): + # low(int) is a special case, + # because abs() does not work here! + # we leave x as it is and use the check >% instead of > + # for low(int) this is needed and positive numbers are not affected + # anyway + a = abs(x) + # first 6 bits: + b[0] = toU8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63)) + a = a shr 6 # skip first 6 bits + var i = 1 + while a != 0'i64: + b[i] = toU8(ord(a >% 127'i64) shl 7 or int(a and 127)) + inc(i) + a = a shr 7 + +proc toNum64(b: TBuffer): int64 = + # treat first byte different: + result = ze64(b[0]) and 63 + var + i = 0 + Shift = 6'i64 + while (ze(b[i]) and 128) != 0: + inc(i) + result = result or ((ze64(b[i]) and 127) shl Shift) + inc(Shift, 7) + if (ze(b[0]) and 64) != 0: # sign bit set? + result = not result +% 1 + # this is the same as ``- result`` + # but gives no overflow error for low(int) + +proc toNum(b: TBuffer): int32 = + # treat first byte different: + result = ze(b[0]) and 63 + var + i = 0 + Shift = 6'i32 + while (ze(b[i]) and 128) != 0: + inc(i) + result = result or ((int32(ze(b[i])) and 127'i32) shl Shift) + Shift = shift + 7'i32 + if (ze(b[0]) and (1 shl 6)) != 0: # sign bit set? + result = (not result) +% 1'i32 + # this is the same as ``- result`` + # but gives no overflow error for low(int) + +proc toBinary(x: int64): string = + result = newString(64) + for i in 0..63: + result[63-i] = chr((int(x shr i) and 1) + ord('0')) + +proc t64(i: int64) = + var + b: TBuffer + toVarNum64(i, b) + var x = toNum64(b) + if x != i: + writeln(stdout, $i) + writeln(stdout, toBinary(i)) + writeln(stdout, toBinary(x)) + +proc t32(i: int32) = + var + b: TBuffer + toVarNum(i, b) + var x = toNum(b) + if x != i: + writeln(stdout, toBinary(i)) + writeln(stdout, toBinary(x)) + +proc tm(i: int32) = + var + b: TBuffer + toVarNum64(i, b) + var x = toNum(b) + if x != i: + writeln(stdout, toBinary(i)) + writeln(stdout, toBinary(x)) + +t32(0) +t32(1) +t32(-1) +t32(-100_000) +t32(100_000) +t32(low(int32)) +t32(high(int32)) + +t64(low(int64)) +t64(high(int64)) +t64(0) +t64(-1) +t64(1) +t64(1000_000) +t64(-1000_000) + +tm(0) +tm(1) +tm(-1) +tm(-100_000) +tm(100_000) +tm(low(int32)) +tm(high(int32)) + +writeln(stdout, "Success!") #OUT Success! diff --git a/tests/accept/run/tvartup.nim b/tests/accept/run/tvartup.nim new file mode 100644 index 000000000..05b00b207 --- /dev/null +++ b/tests/accept/run/tvartup.nim @@ -0,0 +1,11 @@ +# Test the new tuple unpacking + +proc divmod(a, b: int): tuple[di, mo: int] = + return (a div b, a mod b) + +var (x, y) = divmod(15, 6) +stdout.write(x) +stdout.write(" ") +stdout.write(y) + +#OUT 2 3 diff --git a/tests/gc/gcbench.nim b/tests/gc/gcbench.nim new file mode 100644 index 000000000..d9e152326 --- /dev/null +++ b/tests/gc/gcbench.nim @@ -0,0 +1,163 @@ +# This is adapted from a benchmark written by John Ellis and Pete Kovac +# of Post Communications. +# It was modified by Hans Boehm of Silicon Graphics. +# +# This is no substitute for real applications. No actual application +# is likely to behave in exactly this way. However, this benchmark was +# designed to be more representative of real applications than other +# Java GC benchmarks of which we are aware. +# It attempts to model those properties of allocation requests that +# are important to current GC techniques. +# It is designed to be used either to obtain a single overall performance +# number, or to give a more detailed estimate of how collector +# performance varies with object lifetimes. It prints the time +# required to allocate and collect balanced binary trees of various +# sizes. Smaller trees result in shorter object lifetimes. Each cycle +# allocates roughly the same amount of memory. +# Two data structures are kept around during the entire process, so +# that the measured performance is representative of applications +# that maintain some live in-memory data. One of these is a tree +# containing many pointers. The other is a large array containing +# double precision floating point numbers. Both should be of comparable +# size. +# +# The results are only really meaningful together with a specification +# of how much memory was used. It is possible to trade memory for +# better time performance. This benchmark should be run in a 32 MB +# heap, though we don't currently know how to enforce that uniformly. +# +# Unlike the original Ellis and Kovac benchmark, we do not attempt +# measure pause times. This facility should eventually be added back +# in. There are several reasons for omitting it for now. The original +# implementation depended on assumptions about the thread scheduler +# that don't hold uniformly. The results really measure both the +# scheduler and GC. Pause time measurements tend to not fit well with +# current benchmark suites. As far as we know, none of the current +# commercial Java implementations seriously attempt to minimize GC pause +# times. +# +# Known deficiencies: +# - No way to check on memory use +# - No cyclic data structures +# - No attempt to measure variation with object size +# - Results are sensitive to locking cost, but we dont +# check for proper locking +# + +import + strutils, times + +type + PNode = ref TNode + TNode {.final.} = object + left, right: PNode + i, j: int + +proc newNode(L, r: PNode): PNode = + new(result) + result.left = L + result.right = r + +const + kStretchTreeDepth = 18 # about 16Mb + kLongLivedTreeDepth = 16 # about 4Mb + kArraySize = 500000 # about 4Mb + kMinTreeDepth = 4 + kMaxTreeDepth = 16 + +# Nodes used by a tree of a given size +proc TreeSize(i: int): int = return ((1 shl (i + 1)) - 1) + +# Number of iterations to use for a given tree depth +proc NumIters(i: int): int = + return 2 * TreeSize(kStretchTreeDepth) div TreeSize(i) + +# Build tree top down, assigning to older objects. +proc Populate(iDepth: int, thisNode: PNode) = + if iDepth <= 0: + return + else: + new(thisNode.left) + new(thisNode.right) + Populate(iDepth-1, thisNode.left) + Populate(iDepth-1, thisNode.right) + +# Build tree bottom-up +proc MakeTree(iDepth: int): PNode = + if iDepth <= 0: + new(result) + else: + return newNode(MakeTree(iDepth-1), MakeTree(iDepth-1)) + +proc PrintDiagnostics() = + echo("Total memory available: " & $getTotalMem() & " bytes") + echo("Free memory: " & $getFreeMem() & " bytes") + +proc TimeConstruction(depth: int) = + var + root, tempTree: PNode + t: int + iNumIters: int + + iNumIters = NumIters(depth) + + echo("Creating " & $iNumIters & " trees of depth " & $depth) + t = getStartMilsecs() + for i in 0..iNumIters-1: + new(tempTree) + Populate(depth, tempTree) + tempTree = nil + echo("\tTop down construction took " & $(getStartMilsecs() - t) & "msecs") + t = getStartMilsecs() + for i in 0..iNumIters-1: + tempTree = MakeTree(depth) + tempTree = nil + echo("\tBottom up construction took " & $(getStartMilsecs() - t) & "msecs") + +type + tMyArray = seq[float] + +proc main() = + var + root, longLivedTree, tempTree: PNode + t: int + myarray: tMyArray + + echo("Garbage Collector Test") + echo(" Stretching memory with a binary tree of depth " & $kStretchTreeDepth) + PrintDiagnostics() + t = getStartMilsecs() + + # Stretch the memory space quickly + tempTree = MakeTree(kStretchTreeDepth) + tempTree = nil + + # Create a long lived object + echo(" Creating a long-lived binary tree of depth " & + $kLongLivedTreeDepth) + new(longLivedTree) + Populate(kLongLivedTreeDepth, longLivedTree) + + # Create long-lived array, filling half of it + echo(" Creating a long-lived array of " & $kArraySize & " doubles") + newSeq(myarray, kArraySize) + for i in 0..kArraySize div 2 -1: + myarray[i] = 1.0 / toFloat(i) + + PrintDiagnostics() + + var d = kMinTreeDepth + while d <= kMaxTreeDepth: + TimeConstruction(d) + inc(d, 2) + + if longLivedTree == nil or myarray[1000] != 1.0/1000.0: + echo("Failed") + # fake reference to LongLivedTree + # and array to keep them from being optimized away + + var elapsed = getStartMilsecs() - t + PrintDiagnostics() + echo("Completed in " & $elapsed & "ms.") + +main() diff --git a/tests/gc/gctest.nim b/tests/gc/gctest.nim new file mode 100644 index 000000000..f58dc3217 --- /dev/null +++ b/tests/gc/gctest.nim @@ -0,0 +1,197 @@ +# Test the garbage collector: +# This file is not in the test suite because it takes too much time. + +import + strutils + +type + PNode = ref TNode + TNode {.final.} = object + le, ri: PNode + data: string + + TTable {.final.} = object + counter, max: int + data: seq[string] + + TBNode {.final.} = object + other: PNode # a completely different tree + data: string + sons: seq[TBNode] # directly embedded! + t: TTable + + TCaseKind = enum nkStr, nkWhole, nkList + PCaseNode = ref TCaseNode + TCaseNode {.final.} = object + case kind: TCaseKind + of nkStr: data: string + of nkList: sons: seq[PCaseNode] + else: unused: seq[string] + + TIdObj* = object of TObject + id*: int # unique id; use this for comparisons and not the pointers + + PIdObj* = ref TIdObj + PIdent* = ref TIdent + TIdent*{.acyclic.} = object of TIdObj + s*: string + next*: PIdent # for hash-table chaining + h*: int # hash value of s + +var + flip: int + +proc newCaseNode(data: string): PCaseNode = + new(result) + if flip == 0: + result.kind = nkStr + result.data = data + else: + result.kind = nkWhole + result.unused = @["", "abc", "abdc"] + flip = 1 - flip + +proc newCaseNode(a, b: PCaseNode): PCaseNode = + new(result) + result.kind = nkList + result.sons = @[a, b] + +proc caseTree(lvl: int = 0): PCaseNode = + if lvl == 3: result = newCaseNode("data item") + else: result = newCaseNode(caseTree(lvl+1), caseTree(lvl+1)) + +proc finalizeBNode(n: TBNode) = writeln(stdout, n.data) +proc finalizeNode(n: PNode) = + assert(n != nil) + write(stdout, "finalizing: ") + if isNil(n.data): writeln(stdout, "nil!") + else: writeln(stdout, n.data) + +var + id: int = 1 + +proc buildTree(depth = 1): PNode = + if depth == 7: return nil + new(result, finalizeNode) + result.le = buildTree(depth+1) + result.ri = buildTree(depth+1) + result.data = $id + inc(id) + +proc returnTree(): PNode = + writeln(stdout, "creating id: " & $id) + new(result, finalizeNode) + result.data = $id + new(result.le, finalizeNode) + result.le.data = $id & ".1" + new(result.ri, finalizeNode) + result.ri.data = $id & ".2" + inc(id) + + # now create a cycle: + writeln(stdout, "creating id (cyclic): " & $id) + var cycle: PNode + new(cycle, finalizeNode) + cycle.data = $id + cycle.le = cycle + cycle.ri = cycle + inc(id) + #writeln(stdout, "refcount: " & $refcount(cycle)) + #writeln(stdout, "refcount le: " & $refcount(cycle.le)) + #writeln(stdout, "refcount ri: " & $refcount(cycle.ri)) + +proc printTree(t: PNode) = + if t == nil: return + writeln(stdout, "printing") + writeln(stdout, t.data) + printTree(t.le) + printTree(t.ri) + +proc unsureNew(result: var PNode) = + writeln(stdout, "creating unsure id: " & $id) + new(result, finalizeNode) + result.data = $id + new(result.le, finalizeNode) + result.le.data = $id & ".a" + new(result.ri, finalizeNode) + result.ri.data = $id & ".b" + inc(id) + +proc setSons(n: var TBNode) = + n.sons = @[] # free memory of the sons + n.t.data = @[] + var + m: seq[string] + m = @[] + setLen(m, len(n.t.data) * 2) + for i in 0..high(m): + m[i] = "..." + n.t.data = m + +proc buildBTree(father: var TBNode) = + father.data = "father" + father.other = nil + father.sons = @[] + for i in 1..10: + write(stdout, "next iteration!\n") + var n: TBNode + n.other = returnTree() + n.data = "B node: " & $i + if i mod 2 == 0: n.sons = @[] # nil and [] need to be handled correctly! + add father.sons, n + father.t.counter = 0 + father.t.max = 3 + father.t.data = @["ha", "lets", "stress", "it"] + setSons(father) + +proc getIdent(identifier: cstring, length: int, h: int): PIdent = + new(result) + result.h = h + result.s = newString(length) + +proc main() = + discard getIdent("addr", 4, 0) + discard getIdent("hall", 4, 0) + discard getIdent("echo", 4, 0) + discard getIdent("huch", 4, 0) + + var + father: TBNode + for i in 1..1_00: + buildBTree(father) + + for i in 1..1_00: + var t = returnTree() + var t2: PNode + unsureNew(t2) + write(stdout, "now building bigger trees: ") + var t2: PNode + for i in 1..100: + t2 = buildTree() + printTree(t2) + write(stdout, "now test sequences of strings:") + var s: seq[string] = @[] + for i in 1..100: + add s, "hohoho" # test reallocation + writeln(stdout, s[89]) + write(stdout, "done!\n") + +var + father: TBNode + s: string +s = "" +s = "" +writeln(stdout, repr(caseTree())) +father.t.data = @["ha", "lets", "stress", "it"] +father.t.data = @["ha", "lets", "stress", "it"] +var t = buildTree() +write(stdout, repr(t^)) +buildBTree(father) +write(stdout, repr(father)) + +write(stdout, "starting main...\n") +main() +write(stdout, "finished\n") +GC_fullCollect() +GC_fullCollect() +writeln(stdout, GC_getStatistics()) diff --git a/tests/gcbench.nim b/tests/gcbench.nim deleted file mode 100644 index 72daad210..000000000 --- a/tests/gcbench.nim +++ /dev/null @@ -1,171 +0,0 @@ -# This is adapted from a benchmark written by John Ellis and Pete Kovac -# of Post Communications. -# It was modified by Hans Boehm of Silicon Graphics. -# -# This is no substitute for real applications. No actual application -# is likely to behave in exactly this way. However, this benchmark was -# designed to be more representative of real applications than other -# Java GC benchmarks of which we are aware. -# It attempts to model those properties of allocation requests that -# are important to current GC techniques. -# It is designed to be used either to obtain a single overall performance -# number, or to give a more detailed estimate of how collector -# performance varies with object lifetimes. It prints the time -# required to allocate and collect balanced binary trees of various -# sizes. Smaller trees result in shorter object lifetimes. Each cycle -# allocates roughly the same amount of memory. -# Two data structures are kept around during the entire process, so -# that the measured performance is representative of applications -# that maintain some live in-memory data. One of these is a tree -# containing many pointers. The other is a large array containing -# double precision floating point numbers. Both should be of comparable -# size. -# -# The results are only really meaningful together with a specification -# of how much memory was used. It is possible to trade memory for -# better time performance. This benchmark should be run in a 32 MB -# heap, though we don't currently know how to enforce that uniformly. -# -# Unlike the original Ellis and Kovac benchmark, we do not attempt -# measure pause times. This facility should eventually be added back -# in. There are several reasons for omitting it for now. The original -# implementation depended on assumptions about the thread scheduler -# that don't hold uniformly. The results really measure both the -# scheduler and GC. Pause time measurements tend to not fit well with -# current benchmark suites. As far as we know, none of the current -# commercial Java implementations seriously attempt to minimize GC pause -# times. -# -# Known deficiencies: -# - No way to check on memory use -# - No cyclic data structures -# - No attempt to measure variation with object size -# - Results are sensitive to locking cost, but we dont -# check for proper locking -# - -import - strutils, times - -type - PNode = ref TNode - TNode {.final.} = object - left, right: PNode - i, j: int - -proc newNode(l, r: PNode): PNode = - new(result) - result.left = l - result.right = r - -const - kStretchTreeDepth = 18 # about 16Mb - kLongLivedTreeDepth = 16 # about 4Mb - kArraySize = 500000 # about 4Mb - kMinTreeDepth = 4 - kMaxTreeDepth = 16 - -# Nodes used by a tree of a given size -proc TreeSize(i: int): int = return ((1 shl (i + 1)) - 1) - -# Number of iterations to use for a given tree depth -proc NumIters(i: int): int = - return 2 * TreeSize(kStretchTreeDepth) div TreeSize(i) - -# Build tree top down, assigning to older objects. -proc Populate(iDepth: int, thisNode: PNode) = - if iDepth <= 0: - return - else: - new(thisNode.left) - new(thisNode.right) - Populate(iDepth-1, thisNode.left) - Populate(iDepth-1, thisNode.right) - -# Build tree bottom-up -proc MakeTree(iDepth: int): PNode = - if iDepth <= 0: - new(result) - else: - return newNode(MakeTree(iDepth-1), - MakeTree(iDepth-1)) - -proc PrintDiagnostics() = - var - FreeMemory = getFreeMem() - TotalMemory = getTotalMem() - - echo("Total memory available: " & $TotalMemory & " bytes") - echo("Free memory: " & $FreeMemory & " bytes") - -proc TimeConstruction(depth: int) = - var - root, tempTree: PNode - t: int - iNumIters: int - - iNumIters = NumIters(depth) - - echo("Creating " & $iNumIters & " trees of depth " & $depth) - t = getStartMilsecs() - for i in 0..iNumIters-1: - new(tempTree) - Populate(depth, tempTree) - tempTree = nil - echo("\tTop down construction took " & - $(getStartMilsecs() - t) & "msecs") - t = getStartMilsecs() - for i in 0..iNumIters-1: - tempTree = MakeTree(depth) - tempTree = nil - echo("\tBottom up construction took " & - $(getStartMilsecs() - t) & "msecs") - -type - tMyArray = seq[float] - -proc main() = - var - root, longLivedTree, tempTree: PNode - t: int - myarray: tMyArray - - echo("Garbage Collector Test") - echo(" Stretching memory with a binary tree of depth " & - $kStretchTreeDepth) - PrintDiagnostics() - t = getStartMilsecs() - - # Stretch the memory space quickly - tempTree = MakeTree(kStretchTreeDepth) - tempTree = nil - - # Create a long lived object - echo(" Creating a long-lived binary tree of depth " & - $kLongLivedTreeDepth) - new(longLivedTree) - Populate(kLongLivedTreeDepth, longLivedTree) - - # Create long-lived array, filling half of it - echo(" Creating a long-lived array of " & $kArraySize & " doubles") - newSeq(myarray, kArraySize) - for i in 0..kArraySize div 2 -1: - myarray[i] = 1.0 / toFloat(i) - - PrintDiagnostics() - - var d = kMinTreeDepth - while d <= kMaxTreeDepth: - TimeConstruction(d) - inc(d, 2) - - if longLivedTree == nil or myarray[1000] != 1.0/1000.0: - echo("Failed") - # fake reference to LongLivedTree - # and array to keep them from being optimized away - - var elapsed = getStartMilsecs() - t - PrintDiagnostics() - echo("Completed in " & $elapsed & "ms.") - -main() diff --git a/tests/gctest.nim b/tests/gctest.nim deleted file mode 100644 index f58dc3217..000000000 --- a/tests/gctest.nim +++ /dev/null @@ -1,197 +0,0 @@ -# Test the garbage collector: -# This file is not in the test suite because it takes too much time. - -import - strutils - -type - PNode = ref TNode - TNode {.final.} = object - le, ri: PNode - data: string - - TTable {.final.} = object - counter, max: int - data: seq[string] - - TBNode {.final.} = object - other: PNode # a completely different tree - data: string - sons: seq[TBNode] # directly embedded! - t: TTable - - TCaseKind = enum nkStr, nkWhole, nkList - PCaseNode = ref TCaseNode - TCaseNode {.final.} = object - case kind: TCaseKind - of nkStr: data: string - of nkList: sons: seq[PCaseNode] - else: unused: seq[string] - - TIdObj* = object of TObject - id*: int # unique id; use this for comparisons and not the pointers - - PIdObj* = ref TIdObj - PIdent* = ref TIdent - TIdent*{.acyclic.} = object of TIdObj - s*: string - next*: PIdent # for hash-table chaining - h*: int # hash value of s - -var - flip: int - -proc newCaseNode(data: string): PCaseNode = - new(result) - if flip == 0: - result.kind = nkStr - result.data = data - else: - result.kind = nkWhole - result.unused = @["", "abc", "abdc"] - flip = 1 - flip - -proc newCaseNode(a, b: PCaseNode): PCaseNode = - new(result) - result.kind = nkList - result.sons = @[a, b] - -proc caseTree(lvl: int = 0): PCaseNode = - if lvl == 3: result = newCaseNode("data item") - else: result = newCaseNode(caseTree(lvl+1), caseTree(lvl+1)) - -proc finalizeBNode(n: TBNode) = writeln(stdout, n.data) -proc finalizeNode(n: PNode) = - assert(n != nil) - write(stdout, "finalizing: ") - if isNil(n.data): writeln(stdout, "nil!") - else: writeln(stdout, n.data) - -var - id: int = 1 - -proc buildTree(depth = 1): PNode = - if depth == 7: return nil - new(result, finalizeNode) - result.le = buildTree(depth+1) - result.ri = buildTree(depth+1) - result.data = $id - inc(id) - -proc returnTree(): PNode = - writeln(stdout, "creating id: " & $id) - new(result, finalizeNode) - result.data = $id - new(result.le, finalizeNode) - result.le.data = $id & ".1" - new(result.ri, finalizeNode) - result.ri.data = $id & ".2" - inc(id) - - # now create a cycle: - writeln(stdout, "creating id (cyclic): " & $id) - var cycle: PNode - new(cycle, finalizeNode) - cycle.data = $id - cycle.le = cycle - cycle.ri = cycle - inc(id) - #writeln(stdout, "refcount: " & $refcount(cycle)) - #writeln(stdout, "refcount le: " & $refcount(cycle.le)) - #writeln(stdout, "refcount ri: " & $refcount(cycle.ri)) - -proc printTree(t: PNode) = - if t == nil: return - writeln(stdout, "printing") - writeln(stdout, t.data) - printTree(t.le) - printTree(t.ri) - -proc unsureNew(result: var PNode) = - writeln(stdout, "creating unsure id: " & $id) - new(result, finalizeNode) - result.data = $id - new(result.le, finalizeNode) - result.le.data = $id & ".a" - new(result.ri, finalizeNode) - result.ri.data = $id & ".b" - inc(id) - -proc setSons(n: var TBNode) = - n.sons = @[] # free memory of the sons - n.t.data = @[] - var - m: seq[string] - m = @[] - setLen(m, len(n.t.data) * 2) - for i in 0..high(m): - m[i] = "..." - n.t.data = m - -proc buildBTree(father: var TBNode) = - father.data = "father" - father.other = nil - father.sons = @[] - for i in 1..10: - write(stdout, "next iteration!\n") - var n: TBNode - n.other = returnTree() - n.data = "B node: " & $i - if i mod 2 == 0: n.sons = @[] # nil and [] need to be handled correctly! - add father.sons, n - father.t.counter = 0 - father.t.max = 3 - father.t.data = @["ha", "lets", "stress", "it"] - setSons(father) - -proc getIdent(identifier: cstring, length: int, h: int): PIdent = - new(result) - result.h = h - result.s = newString(length) - -proc main() = - discard getIdent("addr", 4, 0) - discard getIdent("hall", 4, 0) - discard getIdent("echo", 4, 0) - discard getIdent("huch", 4, 0) - - var - father: TBNode - for i in 1..1_00: - buildBTree(father) - - for i in 1..1_00: - var t = returnTree() - var t2: PNode - unsureNew(t2) - write(stdout, "now building bigger trees: ") - var t2: PNode - for i in 1..100: - t2 = buildTree() - printTree(t2) - write(stdout, "now test sequences of strings:") - var s: seq[string] = @[] - for i in 1..100: - add s, "hohoho" # test reallocation - writeln(stdout, s[89]) - write(stdout, "done!\n") - -var - father: TBNode - s: string -s = "" -s = "" -writeln(stdout, repr(caseTree())) -father.t.data = @["ha", "lets", "stress", "it"] -father.t.data = @["ha", "lets", "stress", "it"] -var t = buildTree() -write(stdout, repr(t^)) -buildBTree(father) -write(stdout, repr(father)) - -write(stdout, "starting main...\n") -main() -write(stdout, "finished\n") -GC_fullCollect() -GC_fullCollect() -writeln(stdout, GC_getStatistics()) diff --git a/tests/mbind3.nim b/tests/mbind3.nim deleted file mode 100644 index 586222eb8..000000000 --- a/tests/mbind3.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Module A -var - lastId = 0 - -template genId*: expr = - inc(bind lastId) - lastId - - diff --git a/tests/mbind4.nim b/tests/mbind4.nim deleted file mode 100644 index 53b8331cd..000000000 --- a/tests/mbind4.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Module A -var - lastId = 0 - -template genId*: expr = - inc(lastId) - lastId - - diff --git a/tests/mvarious.nim b/tests/mvarious.nim deleted file mode 100644 index 333b34d33..000000000 --- a/tests/mvarious.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test a submodule - -#type -# TStringArr = array [0.. *] of string - -proc exportme* = nil diff --git a/tests/reject/99bottles.nim b/tests/reject/99bottles.nim new file mode 100644 index 000000000..14904ac0f --- /dev/null +++ b/tests/reject/99bottles.nim @@ -0,0 +1 @@ +# Test if the compiler detects invalid module names diff --git a/tests/reject/t99bott.nim b/tests/reject/t99bott.nim new file mode 100644 index 000000000..4dfb11701 --- /dev/null +++ b/tests/reject/t99bott.nim @@ -0,0 +1,28 @@ +## 99 Bottles of Beer +## http://www.99-bottles-of-beer.net/ +## Nimrod version + +## Author: Philippe Lhoste http://Phi.Lho.free.fr +# 2009-11-25 +# Loosely based on my old Lua version... Updated to current official lyrics. + +proc GetBottleNumber(n: int): string = + var bs: string + if n == 0: + bs = "No more bottles" + elif n == 1: + bs = "1 bottle" + else: + bs = $n & " bottles" + return bs & " of beer" + +for bn in countdown(99, 1): + const cur = GetBottleNumber(bn) #ERROR_MSG constant expression expected + echo(cur, " on the wall, ", cur, ".") + echo("Take one down and pass it around, ", GetBottleNumber(bn-1), + " on the wall.\n") + +echo "No more bottles of beer on the wall, no more bottles of beer." +echo "Go to the store and buy some more, 99 bottles of beer on the wall." + + diff --git a/tests/reject/tadrdisc.nim b/tests/reject/tadrdisc.nim new file mode 100644 index 000000000..a7118455f --- /dev/null +++ b/tests/reject/tadrdisc.nim @@ -0,0 +1,16 @@ +# Test that the address of a dicriminants cannot be taken + +type + TKind = enum ka, kb, kc + TA = object + case k: TKind + of ka: x, y: int + of kb: a, b: string + of kc: c, d: float + +proc setKind(k: var TKind) = + k = kc + +var a: TA +setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed + diff --git a/tests/reject/tambsym.nim b/tests/reject/tambsym.nim new file mode 100644 index 000000000..b8eae3ba3 --- /dev/null +++ b/tests/reject/tambsym.nim @@ -0,0 +1,8 @@ +# Test ambiguous symbols + +import mambsym1, mambsym2 + +var + v: TExport #ERROR_MSG ambiguous identifier + +v = y diff --git a/tests/reject/tambsym3.nim b/tests/reject/tambsym3.nim new file mode 100644 index 000000000..96a5098c9 --- /dev/null +++ b/tests/reject/tambsym3.nim @@ -0,0 +1,8 @@ +# Test ambiguous symbols + +import mambsym1, times + +var + v = mDec #ERROR_MSG ambiguous identifier + +writeln(stdout, ord(v)) diff --git a/tests/reject/tbind2.nim b/tests/reject/tbind2.nim new file mode 100644 index 000000000..41711083f --- /dev/null +++ b/tests/reject/tbind2.nim @@ -0,0 +1,10 @@ +# Test the new ``bind`` keyword for templates + +proc p1(x: int8, y: int): int = return x + y +proc p1(x: int, y: int8): int = return x - y + +template tempBind(x, y: expr): expr = + bind p1(x, y) #ERROR_MSG ambiguous call + +echo tempBind(1'i8, 2'i8) + diff --git a/tests/reject/tbind4.nim b/tests/reject/tbind4.nim new file mode 100644 index 000000000..d0b5fc062 --- /dev/null +++ b/tests/reject/tbind4.nim @@ -0,0 +1,6 @@ +# Module B +import mbind4 + +echo genId() #ERROR_MSG instantiation from here + + diff --git a/tests/reject/tblock1.nim b/tests/reject/tblock1.nim new file mode 100644 index 000000000..0bea7ae7f --- /dev/null +++ b/tests/reject/tblock1.nim @@ -0,0 +1,11 @@ +# check for forward label and +# for failure when label is not declared + +proc main = + block endLess: + write(stdout, "Muaahh!\N") + break endLess + + break ha #ERROR + +main() diff --git a/tests/reject/tconstr1.nim b/tests/reject/tconstr1.nim new file mode 100644 index 000000000..488170350 --- /dev/null +++ b/tests/reject/tconstr1.nim @@ -0,0 +1,23 @@ +# Test array, record constructors + +type + TComplexRecord = tuple[ + s: string, + x, y: int, + z: float, + chars: set[Char]] + +proc testSem = + var + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})] + write(stdout, things[0].x) + +const + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0)] #ERROR + otherThings = [ # the same + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] diff --git a/tests/reject/tillrec.nim b/tests/reject/tillrec.nim new file mode 100644 index 000000000..21ce19889 --- /dev/null +++ b/tests/reject/tillrec.nim @@ -0,0 +1,10 @@ +# test illegal recursive types + +type + TLegal {.final.} = object + x: int + kids: seq[TLegal] + + TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal' + y: Int + x: array[0..3, TIllegal] diff --git a/tests/reject/tinout.nim b/tests/reject/tinout.nim new file mode 100644 index 000000000..b4fe2fb10 --- /dev/null +++ b/tests/reject/tinout.nim @@ -0,0 +1,9 @@ +# Test in out checking for parameters + +proc abc(x: var int) = + x = 0 + +proc b() = + abc(3) #ERROR + +b() diff --git a/tests/reject/tinvalidnewseq.nim b/tests/reject/tinvalidnewseq.nim new file mode 100644 index 000000000..e2a3736c3 --- /dev/null +++ b/tests/reject/tinvalidnewseq.nim @@ -0,0 +1,20 @@ +import regexprs, strutils + +type + TURL = tuple[protocol, subdomain, domain, port: string, path: seq[string]] + +proc parseURL(url: string): TURL = + #([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)? + var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?" + var m: array[0..6, string] #Array with the matches + newSeq(m, 7) #ERROR + discard regexprs.match(url, pattern, m) + + result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4], + port: m[5], path: m[6].split('/')) + +var r: TUrl + +r = parseUrl(r"http://google.com/search?var=bleahdhsad") +echo(r.domain) + diff --git a/tests/reject/tinvwhen.nim b/tests/reject/tinvwhen.nim new file mode 100644 index 000000000..8dc8cbf50 --- /dev/null +++ b/tests/reject/tinvwhen.nim @@ -0,0 +1,8 @@ +# This was parsed even though it should not! + +proc chdir(path: CString): cint {.importc: "chdir", header: "dirHeader".} + +proc getcwd(buf: CString, buflen: cint): CString + when defined(unix): {.importc: "getcwd", header: "".} #ERROR_MSG invalid indentation + elif defined(windows): {.importc: "getcwd", header: ""} + else: {.error: "os library not ported to your OS. Please help!".} diff --git a/tests/reject/titer4.nim b/tests/reject/titer4.nim new file mode 100644 index 000000000..376522482 --- /dev/null +++ b/tests/reject/titer4.nim @@ -0,0 +1,3 @@ + +for x in {'a'..'z'}: #ERROR_MSG iterator within for loop context expected + nil diff --git a/tests/reject/tnamspc.nim b/tests/reject/tnamspc.nim new file mode 100644 index 000000000..eddaacfd8 --- /dev/null +++ b/tests/reject/tnamspc.nim @@ -0,0 +1,5 @@ +# Test17 - test correct handling of namespaces + +import mnamspc1 + +global = 9 #ERROR diff --git a/tests/reject/tnoop.nim b/tests/reject/tnoop.nim new file mode 100644 index 000000000..d097553e8 --- /dev/null +++ b/tests/reject/tnoop.nim @@ -0,0 +1,6 @@ +# Tests the new check in the semantic pass + +var + a: int + +a() #ERROR_MSG expression 'a()' cannot be called diff --git a/tests/reject/tnot.nim b/tests/reject/tnot.nim new file mode 100644 index 000000000..cda551654 --- /dev/null +++ b/tests/reject/tnot.nim @@ -0,0 +1,15 @@ +# BUG: following compiles, but should not: + +proc nodeOfDegree(x: Int): bool = + result = false + +proc main = + for j in 0..2: + for i in 0..10: + if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch + Echo "Yes" + else: + Echo "No" + +main() + diff --git a/tests/reject/topaque.nim b/tests/reject/topaque.nim new file mode 100644 index 000000000..7553a749e --- /dev/null +++ b/tests/reject/topaque.nim @@ -0,0 +1,11 @@ +# Test the new opaque types + +import + mopaque + +var + L: TLexer + +L.filename = "ha" +L.line = 34 +L.buffer[0] = '\0' #ERROR_MSG undeclared field: 'buffer' diff --git a/tests/reject/topena1.nim b/tests/reject/topena1.nim new file mode 100644 index 000000000..7351edf55 --- /dev/null +++ b/tests/reject/topena1.nim @@ -0,0 +1,5 @@ +# Tests a special bug + +var + x: ref openarray[string] #ERROR_MSG invalid type + diff --git a/tests/reject/toverl.nim b/tests/reject/toverl.nim new file mode 100644 index 000000000..94f251cac --- /dev/null +++ b/tests/reject/toverl.nim @@ -0,0 +1,6 @@ +# Test for overloading + +type + TNone {.exportc: "_NONE", final.} = object + +proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone' diff --git a/tests/reject/trawstr.nim b/tests/reject/trawstr.nim new file mode 100644 index 000000000..7b2db0335 --- /dev/null +++ b/tests/reject/trawstr.nim @@ -0,0 +1,5 @@ +# Test the new raw strings: + +const + xxx = r"This is a raw string!" + yyy = "This not\" #ERROR diff --git a/tests/reject/trecinca.nim b/tests/reject/trecinca.nim new file mode 100644 index 000000000..d78fee233 --- /dev/null +++ b/tests/reject/trecinca.nim @@ -0,0 +1,5 @@ +# Test recursive includes + +include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' + +echo "trecina" diff --git a/tests/reject/trecincb.nim b/tests/reject/trecincb.nim new file mode 100644 index 000000000..6191671a1 --- /dev/null +++ b/tests/reject/trecincb.nim @@ -0,0 +1,6 @@ +# Test recursive includes + + +include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' + +echo "trecinb" diff --git a/tests/reject/treciter.nim b/tests/reject/treciter.nim new file mode 100644 index 000000000..662239285 --- /dev/null +++ b/tests/reject/treciter.nim @@ -0,0 +1,7 @@ +# Test that an error message occurs for a recursive iterator + +iterator myrec(n: int): int = + for x in myrec(n-1): #ERROR_MSG recursive dependency: 'myrec' + yield x + +for x in myrec(10): echo x diff --git a/tests/reject/trectype.nim b/tests/reject/trectype.nim new file mode 100644 index 000000000..a7a6f56e0 --- /dev/null +++ b/tests/reject/trectype.nim @@ -0,0 +1,21 @@ +# Test recursive type descriptions +# (mainly for the C code generator) + +type + PA = ref TA + TA = array [0..2, PA] + + PRec = ref TRec + TRec {.final.} = object + a, b: TA + + P1 = ref T1 + PB = ref TB + TB = array [0..3, P1] + T1 = array [0..6, PB] + +var + x: PA +new(x) +#ERROR_MSG internal error: cannot generate C type for: PA + diff --git a/tests/reject/trefs.nim b/tests/reject/trefs.nim new file mode 100644 index 000000000..ab3934088 --- /dev/null +++ b/tests/reject/trefs.nim @@ -0,0 +1,16 @@ +# test for ref types (including refs to procs) + +type + TProc = proc (a, b: int): int {.stdcall.} + +proc foo(c, d: int): int {.stdcall.} = + return 0 + +proc wrongfoo(c, e: int): int {.inline.} = + return 0 + +var p: TProc +p = foo +write(stdout, "success!") +p = wrongfoo #ERROR_MSG type mismatch + diff --git a/tests/reject/tsidee1.nim b/tests/reject/tsidee1.nim new file mode 100644 index 000000000..3bd520680 --- /dev/null +++ b/tests/reject/tsidee1.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int = return x + global + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) + diff --git a/tests/reject/tsidee4.nim b/tests/reject/tsidee4.nim new file mode 100644 index 000000000..55c474d10 --- /dev/null +++ b/tests/reject/tsidee4.nim @@ -0,0 +1,10 @@ + +var + global: int + +proc dontcare(x: int): int = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch diff --git a/tests/reject/tsimtych.nim b/tests/reject/tsimtych.nim new file mode 100644 index 000000000..b100c62e3 --- /dev/null +++ b/tests/reject/tsimtych.nim @@ -0,0 +1,5 @@ +# Test 2 +# Simple type checking + +var a: string +a = false #ERROR diff --git a/tests/reject/tstatret.nim b/tests/reject/tstatret.nim new file mode 100644 index 000000000..ac93ac532 --- /dev/null +++ b/tests/reject/tstatret.nim @@ -0,0 +1,5 @@ +# no statement after return +proc main() = + return + echo("huch?") #ERROR_MSG statement not allowed after + diff --git a/tests/reject/tstmtexp.nim b/tests/reject/tstmtexp.nim new file mode 100644 index 000000000..f4d83e83f --- /dev/null +++ b/tests/reject/tstmtexp.nim @@ -0,0 +1,3 @@ +# Test 3 + +1+4 #ERROR_MSG value returned by statement has to be discarded diff --git a/tests/reject/ttempl2.nim b/tests/reject/ttempl2.nim new file mode 100644 index 000000000..fba6bd0cb --- /dev/null +++ b/tests/reject/ttempl2.nim @@ -0,0 +1,14 @@ +template declareInScope(x: expr, t: typeDesc): stmt = + var x: t + +template declareInNewScope(x: expr, t: typeDesc): stmt = + # open a new scope: + block: + var x: t + +declareInScope(a, int) +a = 42 # works, `a` is known here + +declareInNewScope(b, int) +b = 42 #ERROR_MSG undeclared identifier: 'b' + diff --git a/tests/reject/tunderscores.nim b/tests/reject/tunderscores.nim new file mode 100644 index 000000000..459cfda30 --- /dev/null +++ b/tests/reject/tunderscores.nim @@ -0,0 +1,7 @@ +# Bug #502670 + +var ef_ = 3 #ERROR_MSG invalid token: _ +var a__b = 1 +var c___d = 2 +echo(ab, cd, ef_) + diff --git a/tests/reject/typredef.nim b/tests/reject/typredef.nim new file mode 100644 index 000000000..a77d91f40 --- /dev/null +++ b/tests/reject/typredef.nim @@ -0,0 +1,3 @@ +type + Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8' + diff --git a/tests/scantest.nim b/tests/scantest.nim deleted file mode 100644 index c9779c762..000000000 --- a/tests/scantest.nim +++ /dev/null @@ -1,62 +0,0 @@ -# We start with a comment -# This is the same comment - -# This is a new one! - -# This should not be allowed! - -export -main - -import - lexbase, os, strutils - -type - TMyRec {.final.} = object - x, y: int # coordinates - c: char # a character - a: int32 # an integer - - PMyRec = ref TMyRec # a reference to `TMyRec` - -proc splitText(txt: string): seq[string] # splits a text into several lines - # the comment continues here - # this is not easy to parse! - -proc anotherSplit(txt: string): list[string] = - # the comment should belong to `anotherSplit`! - # another problem: comments are statements! - -const - x = 0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64 # x ~~ 1.72826e35 - myNan = 0B01111111100000101100000000001000'f32 # NAN - y = """ - a rather long text. - Over many - lines. - """ - s = "\xff" - a = {0..234} - b = {0..high(int)} - v = 0'i32 - z = 6767566'f32 - -# small test program for lexbase - -proc main*(infile: string, a, b: int, someverylongnamewithtype = 0, - anotherlongthingie = 3) = - var - myInt: int = 0 - a b = 9 - s: sequence[string] - # this should be an error! - if initBaseLexer(L, infile, 30): nil - else: - writeln(stdout, "could not open: " & infile) - writeln(stdout, "Success!") - call(3, # we use 3 - 12, # we use 12 - 43 # we use 43 - ) - -main(ParamStr(1)) diff --git a/tests/t99bott.nim b/tests/t99bott.nim deleted file mode 100644 index 4dfb11701..000000000 --- a/tests/t99bott.nim +++ /dev/null @@ -1,28 +0,0 @@ -## 99 Bottles of Beer -## http://www.99-bottles-of-beer.net/ -## Nimrod version - -## Author: Philippe Lhoste http://Phi.Lho.free.fr -# 2009-11-25 -# Loosely based on my old Lua version... Updated to current official lyrics. - -proc GetBottleNumber(n: int): string = - var bs: string - if n == 0: - bs = "No more bottles" - elif n == 1: - bs = "1 bottle" - else: - bs = $n & " bottles" - return bs & " of beer" - -for bn in countdown(99, 1): - const cur = GetBottleNumber(bn) #ERROR_MSG constant expression expected - echo(cur, " on the wall, ", cur, ".") - echo("Take one down and pass it around, ", GetBottleNumber(bn-1), - " on the wall.\n") - -echo "No more bottles of beer on the wall, no more bottles of beer." -echo "Go to the store and buy some more, 99 bottles of beer on the wall." - - diff --git a/tests/tack.nim b/tests/tack.nim deleted file mode 100644 index 59535e547..000000000 --- a/tests/tack.nim +++ /dev/null @@ -1,15 +0,0 @@ -# the Ackermann function - -proc ack(x, y: int): int = - if x != 0: - if y != 0: - return ack(x-1, ack(x, y-1)) - return ack(x-1, 1) - else: - return y + 1 -# if x == 0: return y + 1 -# elif y == 0: return ack(x-1, 1) -# else: return ack(x-1, ack(x, y-1)) - -# echo(ack(0, 0)) -write(stdout, ack(3, 4)) #OUT 125 diff --git a/tests/tadrdisc.nim b/tests/tadrdisc.nim deleted file mode 100644 index a7118455f..000000000 --- a/tests/tadrdisc.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test that the address of a dicriminants cannot be taken - -type - TKind = enum ka, kb, kc - TA = object - case k: TKind - of ka: x, y: int - of kb: a, b: string - of kc: c, d: float - -proc setKind(k: var TKind) = - k = kc - -var a: TA -setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed - diff --git a/tests/tambsym.nim b/tests/tambsym.nim deleted file mode 100644 index b8eae3ba3..000000000 --- a/tests/tambsym.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test ambiguous symbols - -import mambsym1, mambsym2 - -var - v: TExport #ERROR_MSG ambiguous identifier - -v = y diff --git a/tests/tambsym2.nim b/tests/tambsym2.nim deleted file mode 100644 index 9178182aa..000000000 --- a/tests/tambsym2.nim +++ /dev/null @@ -1,18 +0,0 @@ -# Test overloading of procs with locals - -type - TMyType = object - len: int - data: string - -proc len(x: TMyType): int {.inline.} = return x.len - -proc x(s: TMyType, len: int) = - writeln(stdout, len(s)) - -var - m: TMyType -m.len = 7 -m.data = "1234" - -x(m, 5) #OUT 7 diff --git a/tests/tambsym3.nim b/tests/tambsym3.nim deleted file mode 100644 index 96a5098c9..000000000 --- a/tests/tambsym3.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test ambiguous symbols - -import mambsym1, times - -var - v = mDec #ERROR_MSG ambiguous identifier - -writeln(stdout, ord(v)) diff --git a/tests/tambsys.nim b/tests/tambsys.nim deleted file mode 100644 index bb2622824..000000000 --- a/tests/tambsys.nim +++ /dev/null @@ -1,7 +0,0 @@ -# Test ambiguous symbols - -import mambsys1, mambsys2 - -var - v: mambsys1.TExport -mambsys2.foo(3) #OUT diff --git a/tests/tarray.nim b/tests/tarray.nim deleted file mode 100644 index 252cbd991..000000000 --- a/tests/tarray.nim +++ /dev/null @@ -1,27 +0,0 @@ -# simple check for one dimensional arrays - -type - TMyArray = array[0..2, int] - TMyRecord = tuple[x, y: int] - -proc sum(a: TMyarray): int = - result = 0 - var i = 0 - while i < len(a): - inc(result, a[i]) - inc(i) - -proc sum(a: openarray[int]): int = - result = 0 - var i = 0 - while i < len(a): - inc(result, a[i]) - inc(i) - -proc getPos(r: TMyRecord): int = - result = r.x + r.y - -write(stdout, sum([1, 2, 3, 4])) -write(stdout, sum([])) -write(stdout, getPos( (x: 5, y: 7) )) -#OUT 10012 diff --git a/tests/tarray2.nim b/tests/tarray2.nim deleted file mode 100644 index eb0b75692..000000000 --- a/tests/tarray2.nim +++ /dev/null @@ -1,18 +0,0 @@ -# simple check for one dimensional arrays - -type - TMyArray = array[0..2, int] - -proc mul(a, b: TMyarray): TMyArray = - result = a - for i in 0..len(a)-1: - result[i] = a[i] * b[i] - -var - x, y, z: TMyArray - -x = [ 4, 5, 6 ] -y = x -echo repr(mul(x, y)) - -#OUT [16, 25, 36] diff --git a/tests/tarrindx.nim b/tests/tarrindx.nim deleted file mode 100644 index 13919cc2c..000000000 --- a/tests/tarrindx.nim +++ /dev/null @@ -1,13 +0,0 @@ -# test another strange bug ... (I hate this compiler; it is much too buggy!) - -proc putEnv(key, val: string) = - # XXX: we have to leak memory here, as we cannot - # free it before the program ends (says Borland's - # documentation) - var - env: ptr array[0..500000, char] - env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2)) - for i in 0..len(key)-1: env[i] = key[i] - env[len(key)] = '=' - for i in 0..len(val)-1: - env[len(key)+1+i] = val[i] diff --git a/tests/tassert.nim b/tests/tassert.nim deleted file mode 100644 index 9fd18e9bd..000000000 --- a/tests/tassert.nim +++ /dev/null @@ -1,16 +0,0 @@ -# test assert and exception handling - -proc callB() = assert(False) -proc callA() = callB() -proc callC() = callA() - -try: - callC() -except EAssertionFailed: - write(stdout, "assertion failure!") -except: - write(stdout, "unknown exception!") -finally: - system.write(stdout, "this shall be always written") - -assert(false) #OUT assertion failure!this shall be always written diff --git a/tests/tassign.nim b/tests/tassign.nim deleted file mode 100644 index f51c20783..000000000 --- a/tests/tassign.nim +++ /dev/null @@ -1,31 +0,0 @@ -# Test the assignment operator for complex types which need RTTI - -type - TRec = object - x, y: int - s: string - seq: seq[string] - arr: seq[seq[array[0..3, string]]] - TRecSeq = seq[TRec] - -proc test() = - var - a, b: TRec - a.x = 1 - a.y = 2 - a.s = "Hallo!" - a.seq = @["abc", "def", "ghi", "jkl"] - a.arr = @[] - setLen(a.arr, 4) - a.arr[0] = @[] - a.arr[1] = @[] - - b = a # perform a deep copy here! - b.seq = @["xyz", "huch", "was", "soll"] - writeln(stdout, len(a.seq)) - writeln(stdout, a.seq[3]) - writeln(stdout, len(b.seq)) - writeln(stdout, b.seq[3]) - writeln(stdout, b.y) - -test() diff --git a/tests/tbind1.nim b/tests/tbind1.nim deleted file mode 100644 index e7eed3e4f..000000000 --- a/tests/tbind1.nim +++ /dev/null @@ -1,14 +0,0 @@ -# Test the new ``bind`` keyword for templates - -proc p1(x: int8, y: int): int = return x + y - -template tempBind(x, y: expr): expr = - bind p1(x, y) - -proc p1(x: int, y: int8): int = return x - y - -# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6, -# because it is not ambiguous there. But it is ambiguous after line 8. - -echo tempBind(1'i8, 2'i8) #OUT 3 - diff --git a/tests/tbind2.nim b/tests/tbind2.nim deleted file mode 100644 index 41711083f..000000000 --- a/tests/tbind2.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test the new ``bind`` keyword for templates - -proc p1(x: int8, y: int): int = return x + y -proc p1(x: int, y: int8): int = return x - y - -template tempBind(x, y: expr): expr = - bind p1(x, y) #ERROR_MSG ambiguous call - -echo tempBind(1'i8, 2'i8) - diff --git a/tests/tbind3.nim b/tests/tbind3.nim deleted file mode 100644 index f7fb4865b..000000000 --- a/tests/tbind3.nim +++ /dev/null @@ -1,5 +0,0 @@ -# Module B -import mbind3 - -echo genId() #OUT 1 - diff --git a/tests/tbind4.nim b/tests/tbind4.nim deleted file mode 100644 index d0b5fc062..000000000 --- a/tests/tbind4.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Module B -import mbind4 - -echo genId() #ERROR_MSG instantiation from here - - diff --git a/tests/tbintre2.nim b/tests/tbintre2.nim deleted file mode 100644 index dedc87705..000000000 --- a/tests/tbintre2.nim +++ /dev/null @@ -1,25 +0,0 @@ -# Same test, but check module boundaries - -import tbintree - -var - root: PBinaryTree[string] - x = newNode("hallo") -add(root, x) -add(root, "world") -if find(root, "world"): - for str in items(root): - stdout.write(str) -else: - stdout.writeln("BUG") - -var - r2: PBinaryTree[int] -add(r2, newNode(110)) -add(r2, 223) -add(r2, 99) -for y in items(r2): - stdout.write(y) - -#OUT halloworld99110223 - diff --git a/tests/tbintree.nim b/tests/tbintree.nim deleted file mode 100644 index 89126eaa5..000000000 --- a/tests/tbintree.nim +++ /dev/null @@ -1,101 +0,0 @@ -type - TBinaryTree[T] = object # TBinaryTree is a generic type with - # with generic param ``T`` - le, ri: ref TBinaryTree[T] # left and right subtrees; may be nil - data: T # the data stored in a node - PBinaryTree*[A] = ref TBinaryTree[A] # type that is exported - -proc newNode*[T](data: T): PBinaryTree[T] = - # constructor for a node - new(result) - result.data = data - -proc add*[Ty](root: var PBinaryTree[Ty], n: PBinaryTree[Ty]) = - # insert a node into the tree - if root == nil: - root = n - else: - var it = root - while it != nil: - # compare the data items; uses the generic ``cmp`` proc that works for - # any type that has a ``==`` and ``<`` operator - var c = cmp(n.data, it.data) - if c < 0: - if it.le == nil: - it.le = n - return - it = it.le - else: - if it.ri == nil: - it.ri = n - return - it = it.ri - -proc add*[Ty](root: var PBinaryTree[Ty], data: Ty) = - # convenience proc: - add(root, newNode(data)) - -proc find*[Ty2](b: PBinaryTree[Ty2], data: Ty2): bool = - # for testing this needs to be recursive, so that the - # instantiated type is checked for proper tyGenericInst envelopes - if b == nil: - result = false - else: - var c = cmp(data, b.data) - if c < 0: result = find(b.le, data) - elif c > 0: result = find(b.ri, data) - else: result = true - -iterator preorder*[T](root: PBinaryTree[T]): T = - # Preorder traversal of a binary tree. - # Since recursive iterators are not yet implemented, - # this uses an explicit stack: - var stack: seq[PBinaryTree[T]] = @[root] - while stack.len > 0: - var n = stack.pop() - while n != nil: - yield n.data - add(stack, n.ri) # push right subtree onto the stack - n = n.le # and follow the left pointer - -iterator items*[T](root: PBinaryTree[T]): T = - ## Inorder traversal of the binary tree. - var stack: seq[PBinaryTree[T]] = @[] - var n = root - while true: - while n != nil: - add(stack, n) - n = n.le - if stack.len > 0: - n = stack.pop() - yield n.data - n = n.ri - if stack.len == 0 and n == nil: break - -proc debug[T](a: PBinaryTree[T]) = - if a != nil: - debug(a.le) - echo a.data - debug(a.ri) - -when isMainModule: - var - root: PBinaryTree[string] - x = newNode("hallo") - add(root, x) - add(root, "world") - if find(root, "world"): - for str in items(root): - stdout.write(str) - else: - stdout.writeln("BUG") - - var - r2: PBinaryTree[int] - add(r2, newNode(110)) - add(r2, 223) - add(r2, 99) - for y in items(r2): - stdout.write(y) - -#OUT halloworld99110223 diff --git a/tests/tblock1.nim b/tests/tblock1.nim deleted file mode 100644 index 0bea7ae7f..000000000 --- a/tests/tblock1.nim +++ /dev/null @@ -1,11 +0,0 @@ -# check for forward label and -# for failure when label is not declared - -proc main = - block endLess: - write(stdout, "Muaahh!\N") - break endLess - - break ha #ERROR - -main() diff --git a/tests/tcasestm.nim b/tests/tcasestm.nim deleted file mode 100644 index 277b0bab1..000000000 --- a/tests/tcasestm.nim +++ /dev/null @@ -1,32 +0,0 @@ -# Test the case statement - -type - tenum = enum eA, eB, eC - -var - x: string = "yyy" - y: Tenum = eA - i: int - -case y -of eA: write(stdout, "a") -of eB, eC: write(stdout, "b or c") - -case x -of "Andreas", "Rumpf": write(stdout, "Hallo Meister!") -of "aa", "bb": write(stdout, "Du bist nicht mein Meister") -of "cc", "hash", "when": nil -of "will", "it", "finally", "be", "generated": nil - -case i -of 1..5, 8, 9: nil -of 6, 7: nil -elif x == "Ha": - nil -elif x == "yyy": - write(stdout, x) -else: - nil - -#OUT ayyy - diff --git a/tests/tclosure.nim b/tests/tclosure.nim deleted file mode 100644 index 761e9a8f3..000000000 --- a/tests/tclosure.nim +++ /dev/null @@ -1,26 +0,0 @@ -# Test the closure implementation - -proc map(n: var openarray[int], fn: proc (x: int): int {.closure}) = - for i in 0..n.len-1: n[i] = fn(n[i]) - -proc foldr(n: openarray[int], fn: proc (x, y: int): int {.closure}): int = - for i in 0..n.len-1: - result = fn(result, n[i]) - -var - myData: array[0..4, int] = [0, 1, 2, 3, 4] - -proc testA() = - var p = 0 - map(myData, proc (x: int): int = - result = x + 1 shl (proc (y: int): int = - return y + p - )(0) - inc(p)) - -testA() -for x in items(myData): - write(stout, x) -#OUT 2 4 6 8 10 - - diff --git a/tests/tcmdline.nim b/tests/tcmdline.nim deleted file mode 100644 index f43aecafa..000000000 --- a/tests/tcmdline.nim +++ /dev/null @@ -1,14 +0,0 @@ -# Test the command line - -import - os, strutils - -var - i: int - params = paramCount() -i = 0 -writeln(stdout, "This exe: " & getApplicationFilename()) -writeln(stdout, "Number of parameters: " & $params) -while i <= params: - writeln(stdout, paramStr(i)) - i = i + 1 diff --git a/tests/tcnstseq.nim b/tests/tcnstseq.nim deleted file mode 100644 index 4f389bb3b..000000000 --- a/tests/tcnstseq.nim +++ /dev/null @@ -1,11 +0,0 @@ -# Test the new implicit conversion from sequences to arrays in a constant -# context. - -import strutils - -const - myWords = "Angelika Anne Anna Anka Anja".split() - -for x in items(myWords): - write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja - diff --git a/tests/tcolors.nim b/tests/tcolors.nim deleted file mode 100644 index 9d1034405..000000000 --- a/tests/tcolors.nim +++ /dev/null @@ -1,39 +0,0 @@ -import strutils - -type - TColor = distinct int32 - -proc rgb(r, g, b: range[0..255]): TColor = - result = TColor(r or g shl 8 or b shl 16) - -proc `$`(c: TColor): string = - result = "#" & toHex(int32(c), 6) - -echo rgb(34, 55, 255) - -when false: - type - TColor = distinct int32 - TColorComponent = distinct int8 - - proc red(a: TColor): TColorComponent = - result = TColorComponent(int32(a) and 0xff'i32) - - proc green(a: TColor): TColorComponent = - result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32) - - proc blue(a: TColor): TColorComponent = - result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32) - - proc rgb(r, g, b: range[0..255]): TColor = - result = TColor(r or g shl 8 or b shl 8) - - proc `+!` (a, b: TColorComponent): TColorComponent = - ## saturated arithmetic: - result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255)) - - proc `+` (a, b: TColor): TColor = - ## saturated arithmetic for colors makes sense, I think: - return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b)) - - rgb(34, 55, 255) diff --git a/tests/tconsteval.nim b/tests/tconsteval.nim deleted file mode 100644 index ce90d7c27..000000000 --- a/tests/tconsteval.nim +++ /dev/null @@ -1,28 +0,0 @@ -import strutils - -const - HelpText = """ -+-----------------------------------------------------------------+ -| Maintenance program for Nimrod | -| Version $1| -| (c) 2009 Andreas Rumpf | -+-----------------------------------------------------------------+ -Compiled at: $2, $3 - -Usage: - koch [options] command [options for command] -Options: - --force, -f, -B, -b forces rebuild - --help, -h shows this help and quits -Possible Commands: - boot [options] bootstraps with given command line options - clean cleans Nimrod project; removes generated files - web generates the website - csource [options] builds the C sources for installation - zip builds the installation ZIP package - inno builds the Inno Setup installer -""" % [NimrodVersion & repeatChar(44-len(NimrodVersion)), - CompileDate, CompileTime] - -echo helpText - diff --git a/tests/tconstr1.nim b/tests/tconstr1.nim deleted file mode 100644 index 488170350..000000000 --- a/tests/tconstr1.nim +++ /dev/null @@ -1,23 +0,0 @@ -# Test array, record constructors - -type - TComplexRecord = tuple[ - s: string, - x, y: int, - z: float, - chars: set[Char]] - -proc testSem = - var - things: array [0..1, TComplexRecord] = [ - (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), - (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})] - write(stdout, things[0].x) - -const - things: array [0..1, TComplexRecord] = [ - (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), - (s: "hi", x: 69, y: 45, z: 1.0)] #ERROR - otherThings = [ # the same - (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), - (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] diff --git a/tests/tconstr2.nim b/tests/tconstr2.nim deleted file mode 100644 index 7687a416c..000000000 --- a/tests/tconstr2.nim +++ /dev/null @@ -1,20 +0,0 @@ -# Test array, record constructors - -type - TComplexRecord = tuple[ - s: string, - x, y: int, - z: float, - chars: set[char]] - -const - things: array [0..1, TComplexRecord] = [ - (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), - (s: "hi", x: 69, y: 45, z: 1.0, chars: {})] - otherThings = [ # the same - (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), - (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] - -write(stdout, things[0].x) -#OUT 69 - diff --git a/tests/tconvert.nim b/tests/tconvert.nim deleted file mode 100644 index b23afde74..000000000 --- a/tests/tconvert.nim +++ /dev/null @@ -1,38 +0,0 @@ -import - Cairo - -converter FloatConversion64(x: int): float64 = return toFloat(x) -converter FloatConversion32(x: int): float32 = return toFloat(x) -converter FloatConversionPlain(x: int): float = return toFloat(x) - -const width = 500 -const height = 500 -const outFile = "CairoTest.png" - -var surface = Cairo_ImageSurfaceCreate(CAIRO_FORMAT_RGB24, width, height) -var ç = Cairo_Create(surface) - -ç.Cairo_SetSourceRGB(1, 1, 1) -ç.Cairo_Paint() - -ç.Cairo_SetLineWidth(10) -ç.Cairo_SetLineCap(CAIRO_LINE_CAP_ROUND) - -const count = 12 -var winc = width / count -var hinc = width / count -for i in 1 .. count-1: - var amount = i / count - ç.Cairo_SetSourceRGB(0, 1 - amount, amount) - ç.Cairo_MoveTo(i * winc, hinc) - ç.Cairo_LineTo(width - i * winc, height - hinc) - ç.Cairo_Stroke() - - ç.Cairo_SetSourceRGB(1 - amount, 0, amount) - ç.Cairo_MoveTo(winc, i * hinc) - ç.Cairo_LineTo(width - winc, height - i * hinc) - ç.Cairo_Stroke() - -echo(surface.Cairo_SurfaceWriteToPNG(outFile)) -surface.Cairo_SurfaceDestroy() - diff --git a/tests/tcopy.nim b/tests/tcopy.nim deleted file mode 100644 index 6cb2ec14c..000000000 --- a/tests/tcopy.nim +++ /dev/null @@ -1,19 +0,0 @@ -# tests the copy proc - -import - strutils - -proc main() = - const - example = r"TEMP=C:\Programs\xyz\bin" - var - a, b: string - p: int - p = find(example, "=") - a = copy(example, 0, p-1) - b = copy(example, p+1) - writeln(stdout, a & '=' & b) - #writeln(stdout, b) - -main() -#OUT TEMP=C:\Programs\xyz\bin diff --git a/tests/tcurrncy.nim b/tests/tcurrncy.nim deleted file mode 100644 index fa08d620b..000000000 --- a/tests/tcurrncy.nim +++ /dev/null @@ -1,32 +0,0 @@ -template Additive(typ: typeDesc): stmt = - proc `+` *(x, y: typ): typ {.borrow.} - proc `-` *(x, y: typ): typ {.borrow.} - - # unary operators: - proc `+` *(x: typ): typ {.borrow.} - proc `-` *(x: typ): typ {.borrow.} - -template Multiplicative(typ, base: typeDesc): stmt = - proc `*` *(x: typ, y: base): typ {.borrow.} - proc `*` *(x: base, y: typ): typ {.borrow.} - proc `div` *(x: typ, y: base): typ {.borrow.} - proc `mod` *(x: typ, y: base): typ {.borrow.} - -template Comparable(typ: typeDesc): stmt = - proc `<` * (x, y: typ): bool {.borrow.} - proc `<=` * (x, y: typ): bool {.borrow.} - proc `==` * (x, y: typ): bool {.borrow.} - -template DefineCurrency(typ, base: expr): stmt = - type - typ* = distinct base - Additive(typ) - Multiplicative(typ, base) - Comparable(typ) - - proc `$` * (t: typ): string {.borrow.} - -DefineCurrency(TDollar, int) -DefineCurrency(TEuro, int) -echo($( 12.TDollar + 13.TDollar )) #OUT 25 - diff --git a/tests/tdeprecated.nim b/tests/tdeprecated.nim deleted file mode 100644 index e287da3f9..000000000 --- a/tests/tdeprecated.nim +++ /dev/null @@ -1,6 +0,0 @@ -var - a {.deprecated.}: array[0..11, int] - -a[8] = 1 - - diff --git a/tests/tdialogs.nim b/tests/tdialogs.nim deleted file mode 100644 index 90f241cdf..000000000 --- a/tests/tdialogs.nim +++ /dev/null @@ -1,17 +0,0 @@ -# Test the dialogs module - -import dialogs, gtk2 - -gtk_nimrod_init() - -var x = ChooseFilesToOpen(nil) -for a in items(x): - writeln(stdout, a) - -info(nil, "start with an info box") -warning(nil, "now a warning ...") -error(nil, "... and an error!") - -writeln(stdout, ChooseFileToOpen(nil)) -writeln(stdout, ChooseFileToSave(nil)) -writeln(stdout, ChooseDir(nil)) diff --git a/tests/tdllvar.nim b/tests/tdllvar.nim deleted file mode 100644 index ab767770c..000000000 --- a/tests/tdllvar.nim +++ /dev/null @@ -1,16 +0,0 @@ -import os - -proc getDllName: string = - result = "mylib.dll" - if ExistsFile(result): return - result = "mylib2.dll" - if ExistsFile(result): return - quit("could not load dynamic library") - -proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().} -proc myImport2(s: int) {.cdecl, importc, dynlib: getDllName().} - -myImport("test2") -myImport2(12) - - diff --git a/tests/tdumpast.nim b/tests/tdumpast.nim deleted file mode 100644 index fb31af0ec..000000000 --- a/tests/tdumpast.nim +++ /dev/null @@ -1,35 +0,0 @@ -# Dump the contents of a PNimrodNode - -import macros - -proc dumpit(n: PNimrodNode): string {.compileTime.} = - if n == nil: return "nil" - result = $n.kind - add(result, "(") - case n.kind - of nnkEmpty: nil # same as nil node in this representation - of nnkNilLit: add(result, "nil") - of nnkCharLit..nnkInt64Lit: add(result, $n.intVal) - of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal) - of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal) - of nnkIdent: add(result, $n.ident) - of nnkSym, nnkNone: assert false - else: - add(result, dumpit(n[0])) - for j in 1..n.len-1: - add(result, ", ") - add(result, dumpit(n[j])) - add(result, ")") - -macro dumpAST(n: stmt): stmt = - # dump AST as a side-effect and return the inner node - echo dumpit(n) - result = n[1] - -dumpAST: - proc add(x, y: int): int = - return x + y - - proc sub(x, y: int): int = return x - y - - diff --git a/tests/techo.nim b/tests/techo.nim deleted file mode 100644 index beb21fa16..000000000 --- a/tests/techo.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Simplest Nimrod program - -echo "Hallo, World!" diff --git a/tests/tendian.nim b/tests/tendian.nim deleted file mode 100644 index 256e2653c..000000000 --- a/tests/tendian.nim +++ /dev/null @@ -1,3 +0,0 @@ -# test the new endian magic - -writeln(stdout, repr(system.cpuEndian)) diff --git a/tests/tenum.nim b/tests/tenum.nim deleted file mode 100644 index 6e53b9c08..000000000 --- a/tests/tenum.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test enums - -type - E = enum a, b, c, x, y, z - -var - en: E -en = a diff --git a/tests/tester.nim b/tests/tester.nim index 25a6dd428..bd1b56188 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -1,7 +1,7 @@ # # # Nimrod Tester -# (c) Copyright 2009 Andreas Rumpf +# (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -14,7 +14,7 @@ ## directive.) ## The format for '#ERROR_IN' is: ## #ERROR_IN filename linenumber -## One can omit the extension of the filename ('.nim' is then assumed). +## One can omit the extension of the filename ('.nim' is then used). ## Tests which contain none of the two directives should compile. Thus they ## are executed after successful compilation and their output is verified ## against the results specified with the '#OUT' directive. diff --git a/tests/tfinally.nim b/tests/tfinally.nim deleted file mode 100644 index df6397125..000000000 --- a/tests/tfinally.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test return in try statement: - -proc main: int = - try: - return 1 - finally: - echo "came here" - -discard main() #OUT came here - diff --git a/tests/tfloat1.nim b/tests/tfloat1.nim deleted file mode 100644 index 89911dd61..000000000 --- a/tests/tfloat1.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test new floating point exceptions - -{.floatChecks: on.} - -var x = 0.8 -var y = 0.0 - -echo x / y #OUT Error: unhandled exception: FPU operation caused an overflow [EFloatOverflow] diff --git a/tests/tfloat2.nim b/tests/tfloat2.nim deleted file mode 100644 index 92421d446..000000000 --- a/tests/tfloat2.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test new floating point exceptions - -{.floatChecks: on.} - -var x = 0.0 -var y = 0.0 - -echo x / y #OUT Error: unhandled exception: FPU operation caused a NaN result [EFloatInvalidOp] diff --git a/tests/tformat.nim b/tests/tformat.nim deleted file mode 100644 index aba35504b..000000000 --- a/tests/tformat.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Tests the new format proc (including the & and &= operators) - -import strutils - -echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"]) -#OUT Hi Andreas! How do you feel, Rumpf? diff --git a/tests/tforwty.nim b/tests/tforwty.nim deleted file mode 100644 index 0f1d3697f..000000000 --- a/tests/tforwty.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Test 13: forward types - -type - PSym = ref TSym - - TSym = object - next: PSym - -var s: PSym diff --git a/tests/tforwty2.nim b/tests/tforwty2.nim deleted file mode 100644 index 5d15e112a..000000000 --- a/tests/tforwty2.nim +++ /dev/null @@ -1,22 +0,0 @@ -# Test for a hard to fix internal error -# occured in the SDL library - -{.push dynlib: "SDL.dll", callconv: cdecl.} - -type - PSDL_semaphore = ptr TSDL_semaphore - TSDL_semaphore {.final.} = object - sem: Pointer #PSem_t; - when not defined(USE_NAMED_SEMAPHORES): - sem_data: int - when defined(BROKEN_SEMGETVALUE): - # This is a little hack for MacOS X - - # It's not thread-safe, but it's better than nothing - sem_value: cint - -type - PSDL_Sem = ptr TSDL_Sem - TSDL_Sem = TSDL_Semaphore - -proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {. - importc: "SDL_CreateSemaphore".} diff --git a/tests/tgtk.nim b/tests/tgtk.nim deleted file mode 100644 index cd9254e4f..000000000 --- a/tests/tgtk.nim +++ /dev/null @@ -1,61 +0,0 @@ - -import - gtk2, glib2, atk, gdk2, gdk2pixbuf, libglade2, pango, - pangoutils - -proc hello(widget: PGtkWidget, data: pointer) {.cdecl.} = - write(stdout, "Hello World\n") - -proc delete_event(widget: PGtkWidget, event: PGdkEvent, - data: pointer): bool {.cdecl.} = - # If you return FALSE in the "delete_event" signal handler, - # GTK will emit the "destroy" signal. Returning TRUE means - # you don't want the window to be destroyed. - # This is useful for popping up 'are you sure you want to quit?' - # type dialogs. - write(stdout, "delete event occurred\n") - # Change TRUE to FALSE and the main window will be destroyed with - # a "delete_event". - return false - -# Another callback -proc destroy(widget: PGtkWidget, data: pointer) {.cdecl.} = - gtk_main_quit() - -proc main() = - # GtkWidget is the storage type for widgets - var - window: PGtkWindow - button: PGtkButton - - gtk_nimrod_init() - window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)) - discard g_signal_connect(window, "delete_event", - Gcallback(delete_event), nil) - discard g_signal_connect(window, "destroy", Gcallback(destroy), nil) - # Sets the border width of the window. - gtk_container_set_border_width(window, 10) - - # Creates a new button with the label "Hello World". - button = GTK_BUTTON(gtk_button_new_with_label("Hello World")) - - discard g_signal_connect(button, "clicked", Gcallback(hello), nil) - - # This will cause the window to be destroyed by calling - # gtk_widget_destroy(window) when "clicked". Again, the destroy - # signal could come from here, or the window manager. - discard g_signal_connect_swapped(button, "clicked", - Gcallback(gtk_widget_destroy), window) - - # This packs the button into the window (a gtk container). - gtk_container_add(window, button) - - # The final step is to display this newly created widget. - gtk_widget_show(button) - - # and the window - gtk_widget_show(window) - - gtk_main() - -main() diff --git a/tests/thallo.nim b/tests/thallo.nim deleted file mode 100644 index f1cae5897..000000000 --- a/tests/thallo.nim +++ /dev/null @@ -1,83 +0,0 @@ -# Hallo - -import - os, strutils, macros - -type - TMyEnum = enum - meA, meB, meC, meD - -when isMainModule: - {.hint: "this is the main file".} - -proc fac[T](x: T): T = - # test recursive generic procs - if x <= 1: return 1 - else: return x.`*`(fac(x-1)) - -macro macrotest(n: expr): stmt = - expectKind(n, nnkCall) - expectMinLen(n, 2) - result = newNimNode(nnkStmtList, n) - for i in 2..n.len-1: - result.add(newCall("write", n[1], n[i])) - result.add(newCall("writeln", n[1], newStrLitNode(""))) - -macro debug(n: expr): stmt = - result = newNimNode(nnkStmtList, n) - for i in 1..n.len-1: - result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i]))) - result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": "))) - result.add(newCall("writeln", newIdentNode("stdout"), n[i])) - -macrotest(stdout, "finally", 4, 5, "variable", "argument lists") -macrotest(stdout) - -#GC_disable() - -echo("This was compiled by Nimrod version " & system.nimrodVersion) -writeln(stdout, "Hallo", " World", "!") - -echo(["a", "b", "c", "d"].len) -for x in items(["What's", "your", "name", "?", ]): - echo(x) -var `name` = readLine(stdin) -{.breakpoint.} -echo("Hi " & thallo.name & "!\n") -debug(name) - -var testseq: seq[string] = @[ - "a", "b", "c", "d", "e" -] -echo(repr(testseq)) - -var dummy = "hallo" -echo(copy(dummy, 2, 3)) - -echo($meC) - -# test tuples: -for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]): - echo x - echo y - -proc simpleConst(): int = return 34 - -# test constant evaluation: -const - constEval3 = simpleConst() - constEval = "abc".contains('b') - constEval2 = fac(7) - -echo(constEval3) -echo(constEval) -echo(constEval2) -echo(1.`+`(2)) - -for i in 2..6: - for j in countdown(i+4, 2): - echo(fac(i * j)) - -when isMainModule: - {.hint: "this is the main file".} - diff --git a/tests/thintoff.nim b/tests/thintoff.nim deleted file mode 100644 index 7aff283d6..000000000 --- a/tests/thintoff.nim +++ /dev/null @@ -1,6 +0,0 @@ - -{.hint[XDeclaredButNotUsed]: off.} -var - x: int - -echo x #OUT 0 diff --git a/tests/tident.nim b/tests/tident.nim deleted file mode 100644 index 1ed9894c6..000000000 --- a/tests/tident.nim +++ /dev/null @@ -1,22 +0,0 @@ - -type - TIdObj* = object of TObject - id*: int # unique id; use this for comparisons and not the pointers - - PIdObj* = ref TIdObj - PIdent* = ref TIdent - TIdent*{.acyclic.} = object - s*: string - -proc myNewString(L: int): string {.inline.} = - result = newString(L) - if result.len == L: echo("Length correct") - else: echo("bug") - for i in 0..L-1: - if result[i] == '\0': - echo("Correct") - else: - echo("Wrong") - -var s = myNewString(8) - diff --git a/tests/tillrec.nim b/tests/tillrec.nim deleted file mode 100644 index 21ce19889..000000000 --- a/tests/tillrec.nim +++ /dev/null @@ -1,10 +0,0 @@ -# test illegal recursive types - -type - TLegal {.final.} = object - x: int - kids: seq[TLegal] - - TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal' - y: Int - x: array[0..3, TIllegal] diff --git a/tests/tindent1.nim b/tests/tindent1.nim deleted file mode 100644 index 0527b6e57..000000000 --- a/tests/tindent1.nim +++ /dev/null @@ -1,24 +0,0 @@ - -const romanNumbers1 = - [ - ("M", 1000), ("D", 500), ("C", 100), - ("L", 50), ("X", 10), ("V", 5), ("I", 1) ] - -const romanNumbers2 = - [ - ("M", 1000), ("D", 500), ("C", 100), - ("L", 50), ("X", 10), ("V", 5), ("I", 1) - ] - -const romanNumbers3 = - [ - ("M", 1000), ("D", 500), ("C", 100), - ("L", 50), ("X", 10), ("V", 5), ("I", 1) - ] - -const romanNumbers4 = [ - ("M", 1000), ("D", 500), ("C", 100), - ("L", 50), ("X", 10), ("V", 5), ("I", 1) - ] - - diff --git a/tests/tinit.nim b/tests/tinit.nim deleted file mode 100644 index 85475ce94..000000000 --- a/tests/tinit.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test the new init section in modules - -import minit - -write(stdout, "Hallo from main module!\n") -#OUT Hallo from module! Hallo from main module! diff --git a/tests/tinout.nim b/tests/tinout.nim deleted file mode 100644 index b4fe2fb10..000000000 --- a/tests/tinout.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Test in out checking for parameters - -proc abc(x: var int) = - x = 0 - -proc b() = - abc(3) #ERROR - -b() diff --git a/tests/tints.nim b/tests/tints.nim deleted file mode 100644 index f2b52c134..000000000 --- a/tests/tints.nim +++ /dev/null @@ -1,41 +0,0 @@ -# Test the different integer operations - -var testNumber = 0 - -template test(opr, a, b, c: expr): stmt = - # test the expression at compile and runtime - block: - const constExpr = opr(a, b) - when constExpr != c: - {.error: "Test failed " & $constExpr & " " & $c.} - inc(testNumber) - #Echo("Test: " & $testNumber) - var aa = a - var bb = b - var varExpr = opr(aa, bb) - assert(varExpr == c) - -test(`+`, 12'i8, -13'i16, -1'i16) -test(`shl`, 0b11, 0b100, 0b110000) -test(`shl`, 0b11'i32, 0b100'i64, 0b110000'i64) -test(`shl`, 0b11'i32, 0b100'i32, 0b110000'i32) - -test(`or`, 0xf0f0'i16, 0x0d0d'i16, 0xfdfd'i16) -test(`and`, 0xf0f0'i16, 0xfdfd'i16, 0xf0f0'i16) - -test(`shr`, 0xffffffffffffffff'i64, 0x4'i64, 0x0fffffffffffffff'i64) -test(`shr`, 0xffff'i16, 0x4'i16, 0x0fff'i16) -test(`shr`, 0xff'i8, 0x4'i8, 0x0f'i8) - -test(`shr`, 0xffffffff'i64, 0x4'i64, 0x0fffffff'i64) -test(`shr`, 0xffffffff'i32, 0x4'i32, 0x0fffffff'i32) - -test(`shl`, 0xffffffffffffffff'i64, 0x4'i64, 0xfffffffffffffff0'i64) -test(`shl`, 0xffff'i16, 0x4'i16, 0xfff0'i16) -test(`shl`, 0xff'i8, 0x4'i8, 0xf0'i8) - -test(`shl`, 0xffffffff'i64, 0x4'i64, 0xffffffff0'i64) -test(`shl`, 0xffffffff'i32, 0x4'i32, 0xfffffff0'i32) - -Echo("Success") #OUT Success - diff --git a/tests/tinvalidnewseq.nim b/tests/tinvalidnewseq.nim deleted file mode 100644 index e2a3736c3..000000000 --- a/tests/tinvalidnewseq.nim +++ /dev/null @@ -1,20 +0,0 @@ -import regexprs, strutils - -type - TURL = tuple[protocol, subdomain, domain, port: string, path: seq[string]] - -proc parseURL(url: string): TURL = - #([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)? - var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?" - var m: array[0..6, string] #Array with the matches - newSeq(m, 7) #ERROR - discard regexprs.match(url, pattern, m) - - result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4], - port: m[5], path: m[6].split('/')) - -var r: TUrl - -r = parseUrl(r"http://google.com/search?var=bleahdhsad") -echo(r.domain) - diff --git a/tests/tinvwhen.nim b/tests/tinvwhen.nim deleted file mode 100644 index 8dc8cbf50..000000000 --- a/tests/tinvwhen.nim +++ /dev/null @@ -1,8 +0,0 @@ -# This was parsed even though it should not! - -proc chdir(path: CString): cint {.importc: "chdir", header: "dirHeader".} - -proc getcwd(buf: CString, buflen: cint): CString - when defined(unix): {.importc: "getcwd", header: "".} #ERROR_MSG invalid indentation - elif defined(windows): {.importc: "getcwd", header: ""} - else: {.error: "os library not ported to your OS. Please help!".} diff --git a/tests/tio.nim b/tests/tio.nim deleted file mode 100644 index 014c32d9f..000000000 --- a/tests/tio.nim +++ /dev/null @@ -1,7 +0,0 @@ -# test the file-IO - -proc main() = - for line in lines("thallo.nim"): - writeln(stdout, line) - -main() diff --git a/tests/tisopr.nim b/tests/tisopr.nim deleted file mode 100644 index d52859b09..000000000 --- a/tests/tisopr.nim +++ /dev/null @@ -1,20 +0,0 @@ -# Test is operator - -type - TMyType = object - len: int - data: string - - TOtherType = object of TMyType - -proc p(x: TMyType): bool = - return x is TOtherType - -var - m: TMyType - n: TOtherType - -write(stdout, p(m)) -write(stdout, p(n)) - -#OUT falsetrue diff --git a/tests/titer.nim b/tests/titer.nim deleted file mode 100644 index 19a11dc4e..000000000 --- a/tests/titer.nim +++ /dev/null @@ -1,44 +0,0 @@ -# Test the new iterators - -iterator xrange(fromm, to: int, step = 1): int = - var a = fromm - while a <= to: - yield a - inc(a, step) - -iterator interval[T](a, b: T): T = - var x = a - while x <= b: - yield x - inc(x) - -# -#iterator lines(filename: string): (line: string) = -# var -# f: tTextfile -# shouldClose = open(f, filename) -# if shouldClose: -# setSpace(line, 256) -# while readTextLine(f, line): -# yield line -# finally: -# if shouldClose: close(f) -# - -for i in xrange(0, 5): - for k in xrange(1, 7): - write(stdout, "test") - -for j in interval(45, 45): - write(stdout, "test2!") - write(stdout, "test3?") - -for x in items(["hi", "what's", "your", "name"]): - echo(x) - -const - stringArray = ["hi", "what's", "your", "name"] - -for i in 0..len(stringArray)-1: - echo(stringArray[i]) - diff --git a/tests/titer2.nim b/tests/titer2.nim deleted file mode 100644 index b9cdb53fe..000000000 --- a/tests/titer2.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Try to break the transformation pass: -iterator iterAndZero(a: var openArray[int]): int = - for i in 0..len(a)-1: - yield a[i] - a[i] = 0 - -var x = [[1, 2, 3], [4, 5, 6]] -for y in iterAndZero(x[0]): write(stdout, $y) -#OUT 123 - diff --git a/tests/titer3.nim b/tests/titer3.nim deleted file mode 100644 index d0e121445..000000000 --- a/tests/titer3.nim +++ /dev/null @@ -1,17 +0,0 @@ - -iterator count1_3: int = - yield 1 - yield 2 - yield 3 - -for x in count1_3(): - write(stdout, $x) - -# yield inside an iterator, but not in a loop: -iterator iter1(a: openArray[int]): int = - yield a[0] - -var x = [[1, 2, 3], [4, 5, 6]] -for y in iter1(x[0]): write(stdout, $y) - -#OUT 1231 \ No newline at end of file diff --git a/tests/titer4.nim b/tests/titer4.nim deleted file mode 100644 index 376522482..000000000 --- a/tests/titer4.nim +++ /dev/null @@ -1,3 +0,0 @@ - -for x in {'a'..'z'}: #ERROR_MSG iterator within for loop context expected - nil diff --git a/tests/titer5.nim b/tests/titer5.nim deleted file mode 100644 index 1ac37ba66..000000000 --- a/tests/titer5.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test method call syntax for iterators: -import strutils - -const lines = """abc xyz""" - -for x in lines.split(): - stdout.write(x) - -#OUT abcxyz - diff --git a/tests/tlastmod.nim b/tests/tlastmod.nim deleted file mode 100644 index 75b047fc8..000000000 --- a/tests/tlastmod.nim +++ /dev/null @@ -1,18 +0,0 @@ -# test the new LastModificationTime() proc - -import - os, times, strutils - -proc main() = - var - a, b: TTime - a = getLastModificationTime(ParamStr(1)) - b = getLastModificationTime(ParamStr(2)) - writeln(stdout, $a) - writeln(stdout, $b) - if a < b: - Write(stdout, "$2 is newer than $1\n" % [ParamStr(1), ParamStr(2)]) - else: - Write(stdout, "$1 is newer than $2\n" % [ParamStr(1), ParamStr(2)]) - -main() diff --git a/tests/tlibs.nim b/tests/tlibs.nim deleted file mode 100644 index e3b6bd4c3..000000000 --- a/tests/tlibs.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Test wether the bindings at least compile... - -import - unicode, cgi, terminal, libcurl, web, - parsexml, parseopt, parsecfg, - osproc, - sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf, - sdl_image, sdl_mixer_nosmpeg, - cursorfont, xatom, xf86vmode, xkb, xrandr, xshm, xvlib, keysym, xcms, xi, - xkblib, xrender, xutil, x, xf86dga, xinerama, xlib, xresource, xv, - gtk2, glib2, pango, gdk2, - cairowin32, cairoxlib, - odbcsql, - gl, glut, glu, glx, glext, wingl, - lua, lualib, lauxlib, mysql, sqlite3, python, tcl - -when defined(linux): - import - zlib, zipfiles - -writeln(stdout, "test compilation of binding modules") diff --git a/tests/tloops.nim b/tests/tloops.nim deleted file mode 100644 index 3d03256ad..000000000 --- a/tests/tloops.nim +++ /dev/null @@ -1,64 +0,0 @@ -# Test nested loops and some other things - -proc andTest() = - var a = 0 == 5 and 6 == 6 - -proc incx(x: var int) = # is built-in proc - x = x + 1 - -proc decx(x: var int) = - x = x - 1 - -proc First(y: var int) = - var x: int - i_ncx(x) - if x == 10: - y = 0 - else: - if x == 0: - incx(x) - else: - x=11 - -proc TestLoops() = - var i, j: int - while i >= 0: - if i mod 3 == 0: - break - i = i + 1 - while j == 13: - j = 13 - break - break - - while True: - break - - -proc Foo(n: int): int = - var - a, old: int - b, c: bool - F_irst(a) - if a == 10: - a = 30 - elif a == 11: - a = 22 - elif a == 12: - a = 23 - elif b: - old = 12 - else: - a = 40 - - # - b = false or 2 == 0 and 3 == 9 - a = 0 + 3 * 5 + 6 + 7 + +8 # 36 - while b: - a = a + 3 - a = a + 5 - write(stdout, "Hallo!") - - -# We should come till here :-) -discard Foo(345) diff --git a/tests/tlowhigh.nim b/tests/tlowhigh.nim deleted file mode 100644 index 79f5c5b95..000000000 --- a/tests/tlowhigh.nim +++ /dev/null @@ -1,18 +0,0 @@ -# Test the magic low() and high() procs - -type - myEnum = enum e1, e2, e3, e4, e5 - -var - a: array [myEnum, int] - -for i in low(a) .. high(a): - a[i] = 0 - -proc sum(a: openarray[int]): int = - result = 0 - for i in low(a)..high(a): - inc(result, a[i]) - -write(stdout, sum([1, 2, 3, 4])) -#OUT 10 diff --git a/tests/tmath.nim b/tests/tmath.nim deleted file mode 100644 index 6a1dae54d..000000000 --- a/tests/tmath.nim +++ /dev/null @@ -1,85 +0,0 @@ -# tests for the interpreter - -proc loops(a: var int) = - nil - #var - # b: int - #b = glob - #while b != 0: - # b = b + 1 - #a = b - -proc mymax(a, b: int): int = - #loops(result) - result = a - if b > a: result = b - -proc test(a, b: int) = - var - x, y: int - x = 0 - y = 7 - if x == a + b * 3 - 7 or - x == 8 or - x == y and y > -56 and y < 699: - y = 0 - elif y == 78 and x == 0: - y = 1 - elif y == 0 and x == 0: - y = 2 - else: - y = 3 - -type - TTokType = enum - tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf, - tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto - -proc testCase(t: TTokType): int = - case t - of tkNil, tkType, tkConst: result = 0 - of tkVar: result = 1 - of tkSymbol: result = 2 - of tkIf..tkFor: result = 3 - of tkLoop: result = 56 - else: result = -1 - test(0, 9) # test the call - -proc TestLoops() = - var - i, j: int - - while i >= 0: - if i mod 3 == 0: - break - i = i + 1 - while j == 13: - j = 13 - break - break - - while True: - break - - -var - glob: int - a: array [0..5, int] - -proc main() = - #glob = 0 - #loops( glob ) - var - res: int - s: string - #write(stdout, mymax(23, 45)) - write(stdout, "Hallo! Wie heißt du? ") - s = readLine(stdin) - # test the case statement - case s - of "Andreas": write(stdout, "Du bist mein Meister!\n") - of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n") - else: write(stdout, "ich kenne dich nicht!\n") - write(stdout, "Du heisst " & s & "\n") - -main() diff --git a/tests/tmatrix.nim b/tests/tmatrix.nim deleted file mode 100644 index a162d0f10..000000000 --- a/tests/tmatrix.nim +++ /dev/null @@ -1,60 +0,0 @@ -# Test overloading of [] with multiple indices - -type - TMatrix* = object - data: seq[float] - fWidth, fHeight: int - -template `|`(x, y: int): expr = y * m.fWidth + x - -proc createMatrix*(width, height: int): TMatrix = - result.fWidth = width - result.fHeight = height - newSeq(result.data, width*height) - -proc width*(m: TMatrix): int {.inline.} = return m.fWidth -proc height*(m: TMatrix): int {.inline.} = return m.fHeight - -proc `[,]`*(m: TMatrix, x, y: int): float {.inline.} = - result = m.data[x|y] - -proc `[,]=`*(m: var TMatrix, x, y: int, val: float) {.inline.} = - m.data[x|y] = val - -proc `[$ .. $, $ .. $]`*(m: TMatrix, a, b, c, d: int): TMatrix = - result = createMatrix(b-a+1, d-c+1) - for x in a..b: - for y in c..d: - result[x-a, y-c] = m[x, y] - -proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: float) = - for x in a..b: - for y in c..d: - m[x, y] = val - -proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: TMatrix) = - assert val.width == b-a+1 - assert val.height == d-c+1 - for x in a..b: - for y in c..d: - m[x, y] = val[x-a, y-c] - -proc `-|`*(m: TMatrix): TMatrix = - ## transposes a matrix - result = createMatrix(m.height, m.width) - for x in 0..m.width-1: - for y in 0..m.height-1: result[y,x] = m[x,y] - -#m.row(0, 2) # select row -#m.col(0, 89) # select column - -const - w = 3 - h = 20 - -var m = createMatrix(w, h) -for i in 0..w-1: - m[i, i] = 1.0 - -for i in 0..w-1: - stdout.write(m[i,i]) #OUT 111 diff --git a/tests/tmultim1.nim b/tests/tmultim1.nim deleted file mode 100644 index 5d807e4c9..000000000 --- a/tests/tmultim1.nim +++ /dev/null @@ -1,23 +0,0 @@ -# Test multi methods - -type - TExpr = object - TLiteral = object of TExpr - x: int - TPlusExpr = object of TExpr - a, b: ref TExpr - -method eval(e: ref TExpr): int = quit "to override!" -method eval(e: ref TLiteral): int = return e.x -method eval(e: ref TPlusExpr): int = return eval(e.a) + eval(e.b) - -proc newLit(x: int): ref TLiteral = - new(result) - result.x = x - -proc newPlus(a, b: ref TExpr): ref TPlusExpr = - new(result) - result.a = a - result.b = b - -echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7 diff --git a/tests/tmultim2.nim b/tests/tmultim2.nim deleted file mode 100644 index bf3b5fd6e..000000000 --- a/tests/tmultim2.nim +++ /dev/null @@ -1,30 +0,0 @@ -# Test multi methods - -type - TThing = object - TUnit = object of TThing - x: int - TParticle = object of TThing - a, b: int - -method collide(a, b: TThing) {.inline.} = - quit "to override!" - -method collide(a: TThing, b: TUnit) {.inline.} = - write stdout, "collide: thing, unit " - -method collide(a: TUnit, b: TThing) {.inline.} = - write stdout, "collide: unit, thing " - -proc test(a, b: TThing) {.inline.} = - collide(a, b) - -var - a: TThing - b, c: TUnit -collide(b, c) # ambiguous unit, thing or thing, unit? -> prefer unit, thing! -test(b, c) -collide(a, b) -#OUT collide: unit, thing collide: unit, thing collide: thing, unit - - diff --git a/tests/tnamspc.nim b/tests/tnamspc.nim deleted file mode 100644 index eddaacfd8..000000000 --- a/tests/tnamspc.nim +++ /dev/null @@ -1,5 +0,0 @@ -# Test17 - test correct handling of namespaces - -import mnamspc1 - -global = 9 #ERROR diff --git a/tests/tnestif.nim b/tests/tnestif.nim deleted file mode 100644 index 558fe8d07..000000000 --- a/tests/tnestif.nim +++ /dev/null @@ -1,18 +0,0 @@ -# test nested ifs - -var - x, y: int -x = 2 -if x == 0: - write(stdout, "i == 0") - if y == 0: - write(stdout, x) - else: - write(stdout, y) -elif x == 1: - write(stdout, "i == 1") -elif x == 2: - write(stdout, "i == 2") -else: - write(stdout, "looks like Python") -#OUT i == 2 diff --git a/tests/tnestprc.nim b/tests/tnestprc.nim deleted file mode 100644 index b7326e032..000000000 --- a/tests/tnestprc.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test nested procs without closures - -proc Add3(x: int): int = - proc add(x, y: int): int {.noconv.} = - result = x + y - - result = add(x, 3) - -echo Add3(7) #OUT 10 - diff --git a/tests/tnew.nim b/tests/tnew.nim deleted file mode 100644 index 6527541a2..000000000 --- a/tests/tnew.nim +++ /dev/null @@ -1,49 +0,0 @@ -# Test the implementation of the new operator -# and the code generation for gc walkers -# (and the garbage collector): - -type - PNode = ref TNode - TNode = object - data: int - str: string - le, ri: PNode - - TStressTest = ref array [0..45, array [1..45, TNode]] - -proc finalizer(n: PNode) = - write(stdout, n.data) - write(stdout, " is now freed\n") - -proc newNode(data: int, le, ri: PNode): PNode = - new(result, finalizer) - result.le = le - result.ri = ri - result.data = data - -# now loop and build a tree -proc main() = - var - i = 0 - p: TStressTest - while i < 1000: - var n: PNode - - n = newNode(i, nil, newNode(i + 10000, nil, nil)) - inc(i) - new(p) - - write(stdout, "Simple tree node allocation worked!\n") - i = 0 - while i < 1000: - var m = newNode(i + 20000, nil, nil) - var k = newNode(i + 30000, nil, nil) - m.le = m - m.ri = k - k.le = m - k.ri = k - inc(i) - - write(stdout, "Simple cycle allocation worked!\n") - -main() diff --git a/tests/tnewlibs.nim b/tests/tnewlibs.nim deleted file mode 100644 index aca2e3c30..000000000 --- a/tests/tnewlibs.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test wether the bindings at least compile... - -import - tcl, - sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf, - sdl_image, sdl_mixer_nosmpeg, - gtk2, glib2, pango, gdk2, - unicode, cgi, terminal, libcurl, - parsexml, parseopt, parsecfg, - osproc, - cairowin32, cairoxlib, - gl, glut, glu, glx, glext, wingl, - lua, lualib, lauxlib, mysql, sqlite3, - - -writeln(stdout, "test compilation of binding modules") diff --git a/tests/tnewsets.nim b/tests/tnewsets.nim deleted file mode 100644 index 415fe8f7e..000000000 --- a/tests/tnewsets.nim +++ /dev/null @@ -1,6 +0,0 @@ -# new test for sets: - -const elem = ' ' - -var s: set[char] = {elem} -assert(elem in s and 'a' not_in s and 'c' not_in s ) diff --git a/tests/tnewuns.nim b/tests/tnewuns.nim deleted file mode 100644 index 5181e467c..000000000 --- a/tests/tnewuns.nim +++ /dev/null @@ -1,12 +0,0 @@ -# test the new unsigned operations: - -import - strutils - -var - x, y: int - -x = 1 -y = high(int) - -writeln(stdout, $ ( x +% y ) ) diff --git a/tests/tnoop.nim b/tests/tnoop.nim deleted file mode 100644 index d097553e8..000000000 --- a/tests/tnoop.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Tests the new check in the semantic pass - -var - a: int - -a() #ERROR_MSG expression 'a()' cannot be called diff --git a/tests/tnot.nim b/tests/tnot.nim deleted file mode 100644 index cda551654..000000000 --- a/tests/tnot.nim +++ /dev/null @@ -1,15 +0,0 @@ -# BUG: following compiles, but should not: - -proc nodeOfDegree(x: Int): bool = - result = false - -proc main = - for j in 0..2: - for i in 0..10: - if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch - Echo "Yes" - else: - Echo "No" - -main() - diff --git a/tests/tobjcov.nim b/tests/tobjcov.nim deleted file mode 100644 index da34fcb60..000000000 --- a/tests/tobjcov.nim +++ /dev/null @@ -1,17 +0,0 @@ -# Covariance is not type safe: - -type - TA = object - a: int - TB = object of TA - b: array[0..5000_000, int] - -proc ap(x: var TA) = x.a = -1 -proc bp(x: var TB) = x.b[high(x.b)] = -1 - -# in Nimrod proc (x: TB) is compatible to proc (x: TA), -# but this is not type safe: -var f: proc (x: var TA) = bp -var a: TA -f(a) # bp expects a TB, but gets a TA - diff --git a/tests/tobject2.nim b/tests/tobject2.nim deleted file mode 100644 index 8f69a6bac..000000000 --- a/tests/tobject2.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Tests the object implementation - -type - TPoint2d = object - x, y: int - - TPoint3d = object of TPoint2d - z: int # added a field - -proc getPoint( p: var TPoint2d) = - {.breakpoint.} - writeln(stdout, p.x) - -var - p: TPoint3d - -TPoint2d(p).x = 34 -p.y = 98 -p.z = 343 - -getPoint(p) diff --git a/tests/tobjects.nim b/tests/tobjects.nim deleted file mode 100644 index 8305e2838..000000000 --- a/tests/tobjects.nim +++ /dev/null @@ -1,42 +0,0 @@ -type - TBase = object - x, y: int - - TSubclassKind = enum ka, kb, kc, kd, ke, kf - TSubclass = object of TBase - case c: TSubclassKind - of ka, kb, kc, kd: - a, b: int - of ke: - d, e, f: char - else: nil - n: bool - -var - global: int - -var - s: string - r: float = 0.0 - i: int = 500 + 400 - -case i -of 500..999: write(stdout, "ha!\n") -of 1000..3000, 12: write(stdout, "ganz schön groß\n") -of 1, 2, 3: write(stdout, "1 2 oder 3\n") -else: write(stdout, "sollte nicht passieren\n") - -case readLine(stdin) -of "Rumpf": write(stdout, "Hallo Meister!\n") -of "Andreas": write(stdout, "Hallo Meister!\n") -else: write(stdout, "Nicht mein Meister!\n") - -global = global + 1 -write(stdout, "Hallo wie heißt du? \n") -s = readLine(stdin) -i = 0 -while i < len(s): - if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") - i = i + 1 - -write(stdout, "Du heißt " & s) diff --git a/tests/toop1.nim b/tests/toop1.nim deleted file mode 100644 index 8bae002e7..000000000 --- a/tests/toop1.nim +++ /dev/null @@ -1,82 +0,0 @@ -# Test the stuff in the tutorial -import macros - -type - TFigure = object of TObject # abstract base class: - draw: proc (my: var TFigure) # concrete classes implement this proc - -proc init(f: var TFigure) = - f.draw = nil - -type - TCircle = object of TFigure - radius: int - -proc drawCircle(my: var TCircle) = stdout.writeln("o " & $my.radius) - -proc init(my: var TCircle) = - init(TFigure(my)) # call base constructor - my.radius = 5 - my.draw = drawCircle - -type - TRectangle = object of TFigure - width, height: int - -proc drawRectangle(my: var TRectangle) = stdout.write("[]") - -proc init(my: var TRectangle) = - init(TFigure(my)) # call base constructor - my.width = 5 - my.height = 10 - my.draw = drawRectangle - -macro `!` (n: expr): stmt = - result = newNimNode(nnkCall, n) - var dot = newNimNode(nnkDotExpr, n) - dot.add(n[1]) # obj - if n[2].kind == nnkCall: - # transforms ``obj!method(arg1, arg2, ...)`` to - # ``(obj.method)(obj, arg1, arg2, ...)`` - dot.add(n[2][0]) # method - result.add(dot) - result.add(n[1]) # obj - for i in 1..n[2].len-1: - result.add(n[2][i]) - else: - # transforms ``obj!method`` to - # ``(obj.method)(obj)`` - dot.add(n[2]) # method - result.add(dot) - result.add(n[1]) # obj - -type - TSocket* = object of TObject - FHost: int # cannot be accessed from the outside of the module - # the `F` prefix is a convention to avoid clashes since - # the accessors are named `host` - -proc `host=`*(s: var TSocket, value: int) {.inline.} = - ## setter of hostAddr - s.FHost = value - -proc host*(s: TSocket): int {.inline.} = - ## getter of hostAddr - return s.FHost - -var - s: TSocket -s.host = 34 # same as `host=`(s, 34) -stdout.write(s.host) - -# now use these classes: -var - r: TRectangle - c: TCircle -init(r) -init(c) -r!draw -c!draw() - -#OUT 34[]o 5 - diff --git a/tests/topaque.nim b/tests/topaque.nim deleted file mode 100644 index 7553a749e..000000000 --- a/tests/topaque.nim +++ /dev/null @@ -1,11 +0,0 @@ -# Test the new opaque types - -import - mopaque - -var - L: TLexer - -L.filename = "ha" -L.line = 34 -L.buffer[0] = '\0' #ERROR_MSG undeclared field: 'buffer' diff --git a/tests/topena1.nim b/tests/topena1.nim deleted file mode 100644 index 7351edf55..000000000 --- a/tests/topena1.nim +++ /dev/null @@ -1,5 +0,0 @@ -# Tests a special bug - -var - x: ref openarray[string] #ERROR_MSG invalid type - diff --git a/tests/topenarrayrepr.nim b/tests/topenarrayrepr.nim deleted file mode 100644 index 7e976540f..000000000 --- a/tests/topenarrayrepr.nim +++ /dev/null @@ -1,11 +0,0 @@ -type - TProc = proc (n: int, m: openarray[int64]) - -proc Foo(x: int, P: TProc) = - P(x, [ 1'i64 ]) - -proc Bar(n: int, m: openarray[int64]) = - echo($n & " - " & repr(m)) - -Foo(5, Bar) #OUT 5 - [1] - diff --git a/tests/topenlen.nim b/tests/topenlen.nim deleted file mode 100644 index b9d7fbc2d..000000000 --- a/tests/topenlen.nim +++ /dev/null @@ -1,12 +0,0 @@ -# Tests a special bug - -proc choose(b: openArray[string]): string = return b[0] - -proc p(a, b: openarray[string]): int = - result = a.len + b.len - 1 - for j in 0 .. a.len: inc(result) - discard choose(a) - discard choose(b) - -discard choose(["sh", "-c", $p([""], ["a"])]) -echo($p(["", "ha", "abc"], ["xyz"])) #OUT 7 diff --git a/tests/toptions.nim b/tests/toptions.nim deleted file mode 100644 index 95bb5cfbc..000000000 --- a/tests/toptions.nim +++ /dev/null @@ -1,22 +0,0 @@ -# Converted by Pas2mor v1.54 -# Used command line arguments: -# -m -q -o bootstrap\options.mor options.pas -# - -type - # please make sure we have under 32 options (improves code efficiency!) - TOption = enum - optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck, - optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir, - optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly, - optSafeCode, # only allow safe code - optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib, - optGenGuiApp, optStackTrace - - TOptionset = set[TOption] - -var - gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck, - optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace} - compilerArgs: int - gExitcode: int8 diff --git a/tests/tos.nim b/tests/tos.nim deleted file mode 100644 index 9ab4295f8..000000000 --- a/tests/tos.nim +++ /dev/null @@ -1,12 +0,0 @@ -# test some things of the os module - -import os - -proc walkDirTree(root: string) = - for k, f in walkDir(root): - case k - of pcFile, pcLinkToFile: echo(f) - of pcDirectory: walkDirTree(f) - of pcLinkToDirectory: nil - -walkDirTree(".") diff --git a/tests/toverflw.nim b/tests/toverflw.nim deleted file mode 100644 index c8f194e68..000000000 --- a/tests/toverflw.nim +++ /dev/null @@ -1,15 +0,0 @@ -# Tests emc's ability to detect overflows - -{.push overflowChecks: on.} - -var - a, b: int -a = high(int) -b = -2 -try: - writeln(stdout, b - a) -except EOverflow: - writeln(stdout, "the computation overflowed") - -{.pop.} # overflow check -#OUT the computation overflowed diff --git a/tests/toverl.nim b/tests/toverl.nim deleted file mode 100644 index 94f251cac..000000000 --- a/tests/toverl.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test for overloading - -type - TNone {.exportc: "_NONE", final.} = object - -proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone' diff --git a/tests/toverl2.nim b/tests/toverl2.nim deleted file mode 100644 index 2d1225c6f..000000000 --- a/tests/toverl2.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Test new overloading resolution rules - -import strutils - -proc toverl2(x: int): string = return $x -proc toverl2(x: bool): string = return $x - -iterator toverl2(x: int): int = - var res = 0 - while res < x: - yield res - inc(res) - -var - pp: proc (x: bool): string = toverl2 -stdout.write(pp(true)) -for x in toverl2(3): - stdout.write(toverl2(x)) -stdout.write("\n") -#OUT true012 - diff --git a/tests/toverlop.nim b/tests/toverlop.nim deleted file mode 100644 index f11275644..000000000 --- a/tests/toverlop.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test operator overloading - -proc `%` (a, b: int): int = - return a mod b - -var x, y: int -x = 15 -y = 6 -write(stdout, x % y) -#OUT 3 diff --git a/tests/toverprc.nim b/tests/toverprc.nim deleted file mode 100644 index f35528ace..000000000 --- a/tests/toverprc.nim +++ /dev/null @@ -1,25 +0,0 @@ -# Test overloading of procs when used as function pointers - -import strutils - -proc parseInt(x: float): int = nil -proc parseInt(x: bool): int = nil -proc parseInt(x: float32): int = nil -proc parseInt(x: int8): int = nil -proc parseInt(x: TFile): int = nil -proc parseInt(x: char): int = nil -proc parseInt(x: int16): int = nil - -type - TParseInt = proc (x: string): int - -var - q = TParseInt(parseInt) - p: TParseInt = parseInt - -proc takeParseInt(x: proc (y: string): int): int = - result = x("123") - -echo "Give a list of numbers (separated by spaces): " -var x = stdin.readline.split.each(parseInt).max echo x, " is the maximum!" echo "another number: ", takeParseInt(parseInt) - diff --git a/tests/toverwr.nim b/tests/toverwr.nim deleted file mode 100644 index f2b42df15..000000000 --- a/tests/toverwr.nim +++ /dev/null @@ -1,7 +0,0 @@ -# Test the overloading resolution in connection with a qualifier - -proc write(t: TFile, s: string) = - nil # a nop - -system.write(stdout, "hallo") -#OUT hallo diff --git a/tests/tovfint.nim b/tests/tovfint.nim deleted file mode 100644 index 91eda8d0b..000000000 --- a/tests/tovfint.nim +++ /dev/null @@ -1,17 +0,0 @@ -# this tests the new overflow literals - -var - i: int -i = int(0xffffffff) -when defined(cpu64): - if i == 4294967295: - write(stdout, "works!\n") - else: - write(stdout, "broken!\n") -else: - if i == -1: - write(stdout, "works!\n") - else: - write(stdout, "broken!\n") - -#OUT works! diff --git a/tests/tparedef.nim b/tests/tparedef.nim deleted file mode 100644 index dedebf6b7..000000000 --- a/tests/tparedef.nim +++ /dev/null @@ -1,4 +0,0 @@ -# This test is now superfluous: - -proc a(a: int) = - return diff --git a/tests/tparscfg.nim b/tests/tparscfg.nim deleted file mode 100644 index 618ecadd6..000000000 --- a/tests/tparscfg.nim +++ /dev/null @@ -1,25 +0,0 @@ - -import - os, parsecfg, strutils, streams - -var f = newFileStream(paramStr(1), fmRead) -if f != nil: - var p: TCfgParser - open(p, f, paramStr(1)) - while true: - var e = next(p) - case e.kind - of cfgEof: - echo("EOF!") - break - of cfgSectionStart: ## a ``[section]`` has been parsed - echo("new section: " & e.section) - of cfgKeyValuePair: - echo("key-value-pair: " & e.key & ": " & e.value) - of cfgOption: - echo("command: " & e.key & ": " & e.value) - of cfgError: - echo(e.msg) - close(p) -else: - echo("cannot open: " & paramStr(1)) diff --git a/tests/tparsefloat.nim b/tests/tparsefloat.nim deleted file mode 100644 index 38ed2db6d..000000000 --- a/tests/tparsefloat.nim +++ /dev/null @@ -1,3 +0,0 @@ -import strutils - -echo ParseFloat("5000") / ParseFloat("10") diff --git a/tests/tparsopt.nim b/tests/tparsopt.nim deleted file mode 100644 index 2b2da7e51..000000000 --- a/tests/tparsopt.nim +++ /dev/null @@ -1,27 +0,0 @@ -# Test the new parseopt module - -import - parseopt - -proc writeHelp() = - writeln(stdout, "Usage: tparsopt [options] filename [options]") - -proc writeVersion() = - writeln(stdout, "Version: 1.0.0") - -var - filename = "" -for kind, key, val in getopt(): - case kind - of cmdArgument: - filename = key - of cmdLongOption, cmdShortOption: - case key - of "help", "h": writeHelp() - of "version", "v": writeVersion() - else: - writeln(stdout, "Unknown command line option: ", key, ": ", val) - of cmdEnd: assert(false) # cannot happen -if filename == "": - # no filename has been given, so we show the help: - writeHelp() diff --git a/tests/tpos.nim b/tests/tpos.nim deleted file mode 100644 index 114d39c05..000000000 --- a/tests/tpos.nim +++ /dev/null @@ -1,29 +0,0 @@ -# test this particular function - -proc mypos(sub, s: string, start: int = 0): int = - var - i, j, M, N: int - M = sub.len - N = s.len - i = start - j = 0 - if i >= N: - result = -1 - else: - while True: - if s[i] == sub[j]: - Inc(i) - Inc(j) - else: - i = i - j + 1 - j = 0 - if (j >= M) or (i >= N): break - if j >= M: - result = i - M - else: - result = -1 - -var sub = "hallo" -var s = "world hallo" -write(stdout, mypos(sub, s)) -#OUT 6 diff --git a/tests/tposix.nim b/tests/tposix.nim deleted file mode 100644 index bf0b49586..000000000 --- a/tests/tposix.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test Posix interface - -when not defined(windows): - - import posix - - var - u: Tutsname - - discard uname(u) - - writeln(stdout, u.sysname) - writeln(stdout, u.nodename) - writeln(stdout, u.release) - writeln(stdout, u.machine) - diff --git a/tests/tprep.nim b/tests/tprep.nim deleted file mode 100644 index 999b2f57f..000000000 --- a/tests/tprep.nim +++ /dev/null @@ -1,28 +0,0 @@ -# Test the features that used to belong to the preprocessor - -import - times - -{.warning: "This is only a test warning!".} - -{.define: case2.} -{.define: case3.} -when defined(case1): - {.hint: "Case 1".} - when defined(case3): - {.hint: "Case 1.3".} -elif defined(case2): - {.hint: "Case 2".} - when defined(case3): - {.hint: "Case 2.3".} -elif defined(case3): - {.hint: "Case 3".} -else: - {.hint: "unknown case".} - -var - s: string -write(stdout, "compiled at " & system.compileDate & - " " & compileTime & "\n") -echo getDateStr() -echo getClockStr() diff --git a/tests/tprintf.nim b/tests/tprintf.nim deleted file mode 100644 index 14687a937..000000000 --- a/tests/tprintf.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test a printf proc - -proc printf(file: TFile, args: openarray[string]) = - var i = 0 - while i < args.len: - write(file, args[i]) - inc(i) - -printf(stdout, ["Andreas ", "Rumpf\n"]) -#OUT Andreas Rumpf diff --git a/tests/tprocvar.nim b/tests/tprocvar.nim deleted file mode 100644 index f51543dfa..000000000 --- a/tests/tprocvar.nim +++ /dev/null @@ -1,26 +0,0 @@ -# test variables of type proc - -proc pa() {.cdecl.} = write(stdout, "pa") -proc pb() {.cdecl.} = write(stdout, "pb") -proc pc() {.cdecl.} = write(stdout, "pc") -proc pd() {.cdecl.} = write(stdout, "pd") -proc pe() {.cdecl.} = write(stdout, "pe") - -const - algos = [pa, pb, pc, pd, pe] - -var - x: proc (a, b: int): int {.cdecl.} - -proc ha(c, d: int): int {.cdecl.} = - echo(c + d) - result = c + d - -for a in items(algos): - a() - -x = ha -discard x(3, 4) - -#OUT papbpcpdpe7 - diff --git a/tests/tpush.nim b/tests/tpush.nim deleted file mode 100644 index 5fb411a79..000000000 --- a/tests/tpush.nim +++ /dev/null @@ -1,15 +0,0 @@ -# test the new pragmas - -{.push warnings: off, hints: off.} -proc noWarning() = - var - x: int - echo(x) - -{.pop.} - -proc WarnMe() = - var - x: int - echo(x) - diff --git a/tests/tquicksort.nim b/tests/tquicksort.nim deleted file mode 100644 index 421564ecd..000000000 --- a/tests/tquicksort.nim +++ /dev/null @@ -1,24 +0,0 @@ -proc QuickSort(list: seq[int]): seq[int] = - if len(list) == 0: - return @[] - var pivot = list[0] - var left: seq[int] = @[] - var right: seq[int] = @[] - for i in low(list)..high(list): - if list[i] < pivot: - left.add(list[i]) - elif list[i] > pivot: - right.add(list[i]) - result = QuickSort(left) & pivot & QuickSort(right) - -proc echoSeq(a: seq[int]) = - for i in low(a)..high(a): - echo(a[i]) - -var - list: seq[int] - -list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3]) -echoSeq(list) - - diff --git a/tests/tquit.nim b/tests/tquit.nim deleted file mode 100644 index d4dc1522d..000000000 --- a/tests/tquit.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test the new beforeQuit variable: - -proc myExit() {.noconv.} = - write(stdout, "just exiting...\n") - -addQuitProc(myExit) diff --git a/tests/tquotewords.nim b/tests/tquotewords.nim deleted file mode 100644 index 462293b40..000000000 --- a/tests/tquotewords.nim +++ /dev/null @@ -1,19 +0,0 @@ -# Test an idea I recently had: - -import macros - -macro quoteWords(n: expr): expr = - result = newNimNode(nnkBracket, n) - for i in 1..n.len-1: - expectKind(n[i], nnkIdent) - result.add(toStrLit(n[i])) - -const - myWordList = quoteWords(this, an, example) - -var s = "" -for w in items(myWordList): - s.add(w) - -echo s #OUT thisanexample - diff --git a/tests/tradix.nim b/tests/tradix.nim deleted file mode 100644 index e7ca210e4..000000000 --- a/tests/tradix.nim +++ /dev/null @@ -1,319 +0,0 @@ -# implements and tests an efficient radix tree - -## another method to store an efficient array of pointers: -## We use a radix tree with node compression. -## There are two node kinds: - -const bitsPerUnit = 8*sizeof(int) - -type - TRadixNodeKind = enum rnLinear, rnFull, rnLeafBits, rnLeafLinear - PRadixNode = ptr TRadixNode - TRadixNode {.pure.} = object - kind: TRadixNodeKind - TRadixNodeLinear = object of TRadixNode - len: byte - keys: array [0..31, byte] - vals: array [0..31, PRadixNode] - - TRadixNodeFull = object of TRadixNode - b: array [0..255, PRadixNode] - TRadixNodeLeafBits = object of TRadixNode - b: array [0..7, int] - TRadixNodeLeafLinear = object of TRadixNode - len: byte - keys: array [0..31, byte] - -var - root: PRadixNode - -proc searchInner(r: PRadixNode, a: int): PRadixNode = - case r.kind - of rnLinear: - var x = cast[ptr TRadixNodeLinear](r) - for i in 0..ze(x.len)-1: - if ze(x.keys[i]) == a: return x.vals[i] - of rnFull: - var x = cast[ptr TRadixNodeFull](r) - return x.b[a] - else: assert(false) - -proc testBit(w, i: int): bool {.inline.} = - result = (w and (1 shl (i %% BitsPerUnit))) != 0 - -proc setBit(w: var int, i: int) {.inline.} = - w = w or (1 shl (i %% bitsPerUnit)) - -proc resetBit(w: var int, i: int) {.inline.} = - w = w and not (1 shl (i %% bitsPerUnit)) - -proc testOrSetBit(w: var int, i: int): bool {.inline.} = - var x = (1 shl (i %% bitsPerUnit)) - if (w and x) != 0: return true - w = w or x - -proc searchLeaf(r: PRadixNode, a: int): bool = - case r.kind - of rnLeafBits: - var x = cast[ptr TRadixNodeLeafBits](r) - return testBit(x.b[a /% BitsPerUnit], a) - of rnLeafLinear: - var x = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..ze(x.len)-1: - if ze(x.keys[i]) == a: return true - else: assert(false) - -proc exclLeaf(r: PRadixNode, a: int) = - case r.kind - of rnLeafBits: - var x = cast[ptr TRadixNodeLeafBits](r) - resetBit(x.b[a /% BitsPerUnit], a) - of rnLeafLinear: - var x = cast[ptr TRadixNodeLeafLinear](r) - var L = ze(x.len) - for i in 0..L-1: - if ze(x.keys[i]) == a: - x.keys[i] = x.keys[L-1] - dec(x.len) - return - else: assert(false) - -proc in_Operator*(r: PRadixNode, a: TAddress): bool = - if r == nil: return false - var x = searchInner(r, a shr 24 and 0xff) - if x == nil: return false - x = searchInner(x, a shr 16 and 0xff) - if x == nil: return false - x = searchInner(x, a shr 8 and 0xff) - if x == nil: return false - return searchLeaf(x, a and 0xff) - -proc excl*(r: PRadixNode, a: TAddress): bool = - if r == nil: return false - var x = searchInner(r, a shr 24 and 0xff) - if x == nil: return false - x = searchInner(x, a shr 16 and 0xff) - if x == nil: return false - x = searchInner(x, a shr 8 and 0xff) - if x == nil: return false - exclLeaf(x, a and 0xff) - -proc addLeaf(r: var PRadixNode, a: int): bool = - if r == nil: - # a linear node: - var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) - x.kind = rnLeafLinear - x.len = 1'i8 - x.keys[0] = toU8(a) - r = x - return false # not already in set - case r.kind - of rnLeafBits: - var x = cast[ptr TRadixNodeLeafBits](r) - return testOrSetBit(x.b[a /% BitsPerUnit], a) - of rnLeafLinear: - var x = cast[ptr TRadixNodeLeafLinear](r) - var L = ze(x.len) - for i in 0..L-1: - if ze(x.keys[i]) == a: return true - if L <= high(x.keys): - x.keys[L] = toU8(a) - inc(x.len) - else: - # transform into a full node: - var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits))) - y.kind = rnLeafBits - for i in 0..ze(x.len)-1: - var u = ze(x.keys[i]) - setBit(y.b[u /% BitsPerUnit], u) - setBit(y.b[a /% BitsPerUnit], a) - dealloc(r) - r = y - else: assert(false) - -proc addInner(r: var PRadixNode, a: int, d: int): bool = - if d == 0: - return addLeaf(r, a and 0xff) - var k = a shr d and 0xff - if r == nil: - # a linear node: - var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) - x.kind = rnLinear - x.len = 1'i8 - x.keys[0] = toU8(k) - r = x - return addInner(x.vals[0], a, d-8) - case r.kind - of rnLinear: - var x = cast[ptr TRadixNodeLinear](r) - var L = ze(x.len) - for i in 0..L-1: - if ze(x.keys[i]) == k: # already exists - return addInner(x.vals[i], a, d-8) - if L <= high(x.keys): - x.keys[L] = toU8(k) - inc(x.len) - return addInner(x.vals[L], a, d-8) - else: - # transform into a full node: - var y = cast[ptr TRadixNodeFull](alloc0(sizeof(TRadixNodeFull))) - y.kind = rnFull - for i in 0..L-1: y.b[ze(x.keys[i])] = x.vals[i] - dealloc(r) - r = y - return addInner(y.b[k], a, d-8) - of rnFull: - var x = cast[ptr TRadixNodeFull](r) - return addInner(x.b[k], a, d-8) - else: assert(false) - -proc incl*(r: var PRadixNode, a: TAddress) {.inline.} = - discard addInner(r, a, 24) - -proc testOrIncl*(r: var PRadixNode, a: TAddress): bool {.inline.} = - return addInner(r, a, 24) - -iterator innerElements(r: PRadixNode): tuple[prefix: int, n: PRadixNode] = - if r != nil: - case r.kind - of rnFull: - var r = cast[ptr TRadixNodeFull](r) - for i in 0..high(r.b): - if r.b[i] != nil: - yield (i, r.b[i]) - of rnLinear: - var r = cast[ptr TRadixNodeLinear](r) - for i in 0..ze(r.len)-1: - yield (ze(r.keys[i]), r.vals[i]) - else: assert(false) - -iterator leafElements(r: PRadixNode): int = - if r != nil: - case r.kind - of rnLeafBits: - var r = cast[ptr TRadixNodeLeafBits](r) - # iterate over any bit: - for i in 0..high(r.b): - if r.b[i] != 0: # test all bits for zero - for j in 0..BitsPerUnit-1: - if testBit(r.b[i], j): - yield i*BitsPerUnit+j - of rnLeafLinear: - var r = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..ze(r.len)-1: - yield ze(r.keys[i]) - else: assert(false) - -iterator elements*(r: PRadixNode): TAddress {.inline.} = - for p1, n1 in innerElements(r): - for p2, n2 in innerElements(n1): - for p3, n3 in innerElements(n2): - for p4 in leafElements(n3): - yield p1 shl 24 or p2 shl 16 or p3 shl 8 or p4 - -proc main() = - const - numbers = [128, 1, 2, 3, 4, 255, 17, -8, 45, 19_000] - var - r: PRadixNode = nil - for x in items(numbers): - echo testOrIncl(r, x) - for x in elements(r): echo(x) - -main() - - -when false: - proc traverse(r: PRadixNode, prefix: int, d: int) = - if r == nil: return - case r.kind - of rnLeafBits: - assert(d == 0) - var x = cast[ptr TRadixNodeLeafBits](r) - # iterate over any bit: - for i in 0..high(x.b): - if x.b[i] != 0: # test all bits for zero - for j in 0..BitsPerUnit-1: - if testBit(x.b[i], j): - visit(prefix or i*BitsPerUnit+j) - of rnLeafLinear: - assert(d == 0) - var x = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..ze(x.len)-1: - visit(prefix or ze(x.keys[i])) - of rnFull: - var x = cast[ptr TRadixNodeFull](r) - for i in 0..high(r.b): - if r.b[i] != nil: - traverse(r.b[i], prefix or (i shl d), d-8) - of rnLinear: - var x = cast[ptr TRadixNodeLinear](r) - for i in 0..ze(x.len)-1: - traverse(x.vals[i], prefix or (ze(x.keys[i]) shl d), d-8) - - type - TRadixIter {.final.} = object - r: PRadixNode - p: int - x: int - - proc init(i: var TRadixIter, r: PRadixNode) = - i.r = r - i.x = 0 - i.p = 0 - - proc nextr(i: var TRadixIter): PRadixNode = - if i.r == nil: return nil - case i.r.kind - of rnFull: - var r = cast[ptr TRadixNodeFull](i.r) - while i.x <= high(r.b): - if r.b[i.x] != nil: - i.p = i.x - return r.b[i.x] - inc(i.x) - of rnLinear: - var r = cast[ptr TRadixNodeLinear](i.r) - if i.x < ze(r.len): - i.p = ze(r.keys[i.x]) - result = r.vals[i.x] - inc(i.x) - else: assert(false) - - proc nexti(i: var TRadixIter): int = - result = -1 - case i.r.kind - of rnLeafBits: - var r = cast[ptr TRadixNodeLeafBits](i.r) - # iterate over any bit: - for i in 0..high(r.b): - if x.b[i] != 0: # test all bits for zero - for j in 0..BitsPerUnit-1: - if testBit(x.b[i], j): - visit(prefix or i*BitsPerUnit+j) - of rnLeafLinear: - var r = cast[ptr TRadixNodeLeafLinear](i.r) - if i.x < ze(r.len): - result = ze(r.keys[i.x]) - inc(i.x) - - iterator elements(r: PRadixNode): TAddress {.inline.} = - var - a, b, c, d: TRadixIter - init(a, r) - while true: - var x = nextr(a) - if x != nil: - init(b, x) - while true: - var y = nextr(b) - if y != nil: - init(c, y) - while true: - var z = nextr(c) - if z != nil: - init(d, z) - while true: - var q = nexti(d) - if q != -1: - yield a.p shl 24 or b.p shl 16 or c.p shl 8 or q diff --git a/tests/trawstr.nim b/tests/trawstr.nim deleted file mode 100644 index 7b2db0335..000000000 --- a/tests/trawstr.nim +++ /dev/null @@ -1,5 +0,0 @@ -# Test the new raw strings: - -const - xxx = r"This is a raw string!" - yyy = "This not\" #ERROR diff --git a/tests/treadln.nim b/tests/treadln.nim deleted file mode 100644 index 7703d5a56..000000000 --- a/tests/treadln.nim +++ /dev/null @@ -1,12 +0,0 @@ -# test the improved readline handling that does not care whether its -# Macintosh, Unix or Windows text format. - -var - inp: TFile - line: string - -if openFile(inp, "readme.txt"): - while not EndOfFile(inp): - line = readLine(inp) - echo("#" & line & "#") - closeFile(inp) diff --git a/tests/treadx.nim b/tests/treadx.nim deleted file mode 100644 index 13acb0514..000000000 --- a/tests/treadx.nim +++ /dev/null @@ -1,12 +0,0 @@ -import posix - -var inp = "" -var buf: array[0..10, char] -while true: - var r = read(0, addr(buf), sizeof(buf)-1) - add inp, $buf - if r != sizeof(buf)-1: break - -echo inp -#dafkladskölklödsaf ölksdakölfölksfklwe4iojr389wr 89uweokf sdlkf jweklr jweflksdj fioewjfsdlfsd - diff --git a/tests/trecinca.nim b/tests/trecinca.nim deleted file mode 100644 index d78fee233..000000000 --- a/tests/trecinca.nim +++ /dev/null @@ -1,5 +0,0 @@ -# Test recursive includes - -include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' - -echo "trecina" diff --git a/tests/trecincb.nim b/tests/trecincb.nim deleted file mode 100644 index 6191671a1..000000000 --- a/tests/trecincb.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test recursive includes - - -include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' - -echo "trecinb" diff --git a/tests/treciter.nim b/tests/treciter.nim deleted file mode 100644 index 662239285..000000000 --- a/tests/treciter.nim +++ /dev/null @@ -1,7 +0,0 @@ -# Test that an error message occurs for a recursive iterator - -iterator myrec(n: int): int = - for x in myrec(n-1): #ERROR_MSG recursive dependency: 'myrec' - yield x - -for x in myrec(10): echo x diff --git a/tests/trecmod.nim b/tests/trecmod.nim deleted file mode 100644 index 9d39d3ff7..000000000 --- a/tests/trecmod.nim +++ /dev/null @@ -1,2 +0,0 @@ -# recursive module -import mrecmod diff --git a/tests/trecmod2.nim b/tests/trecmod2.nim deleted file mode 100644 index 85fe2215f..000000000 --- a/tests/trecmod2.nim +++ /dev/null @@ -1,10 +0,0 @@ -type - T1* = int # Module A exports the type ``T1`` - -import mrecmod2 # the compiler starts parsing B - -proc main() = - var i = p(3) # works because B has been parsed completely here - -main() - diff --git a/tests/trectype.nim b/tests/trectype.nim deleted file mode 100644 index a7a6f56e0..000000000 --- a/tests/trectype.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Test recursive type descriptions -# (mainly for the C code generator) - -type - PA = ref TA - TA = array [0..2, PA] - - PRec = ref TRec - TRec {.final.} = object - a, b: TA - - P1 = ref T1 - PB = ref TB - TB = array [0..3, P1] - T1 = array [0..6, PB] - -var - x: PA -new(x) -#ERROR_MSG internal error: cannot generate C type for: PA - diff --git a/tests/trefs.nim b/tests/trefs.nim deleted file mode 100644 index ab3934088..000000000 --- a/tests/trefs.nim +++ /dev/null @@ -1,16 +0,0 @@ -# test for ref types (including refs to procs) - -type - TProc = proc (a, b: int): int {.stdcall.} - -proc foo(c, d: int): int {.stdcall.} = - return 0 - -proc wrongfoo(c, e: int): int {.inline.} = - return 0 - -var p: TProc -p = foo -write(stdout, "success!") -p = wrongfoo #ERROR_MSG type mismatch - diff --git a/tests/tregex.nim b/tests/tregex.nim deleted file mode 100644 index d9d22d603..000000000 --- a/tests/tregex.nim +++ /dev/null @@ -1,19 +0,0 @@ -# Test the new regular expression module -# which is based on the PCRE library - -import - regexprs - -if "keyA = valueA" =~ r"\s*(\w+)\s*\=\s*(\w+)": - write(stdout, "key: ", matches[1]) -elif "# comment!" =~ r"\s*(\#.*)": - echo("comment: ", matches[1]) -else: - echo("Bug!") - -if "Username".match("[A-Za-z]+"): - echo("Yes!") -else: - echo("Bug!") - -#OUT key: keyAYes! diff --git a/tests/treguse.nim b/tests/treguse.nim deleted file mode 100644 index dc805fc70..000000000 --- a/tests/treguse.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Test the register usage of the virtual machine and -# the blocks in var statements - -proc main(a, b: int) = - var x = 0 - write(stdout, x) - if x == 0: - var y = 55 - write(stdout, y) - write(stdout, "this should be the case") - var input = "" - if input == "Andreas": - write(stdout, "wow") - else: - write(stdout, "hugh") - else: - var z = 66 - write(stdout, z) # "bug!") - -main(45, 1000) -#OUT 055this should be the casehugh diff --git a/tests/trepr.nim b/tests/trepr.nim deleted file mode 100644 index 4a56842f6..000000000 --- a/tests/trepr.nim +++ /dev/null @@ -1,32 +0,0 @@ -# test the new "repr" built-in proc - -type - TEnum = enum - en1, en2, en3, en4, en5, en6 - - TPoint {.final.} = object - x, y, z: int - s: array [0..1, string] - e: TEnum - -var - p: TPoint - q: ref TPoint - s: seq[ref TPoint] - -p.x = 0 -p.y = 13 -p.z = 45 -p.s[0] = "abc" -p.s[1] = "xyz" -p.e = en6 - -new(q) -q^ = p - -s = @[q, q, q, q] - -writeln(stdout, repr(p)) -writeln(stdout, repr(q)) -writeln(stdout, repr(s)) -writeln(stdout, repr(en4)) diff --git a/tests/tromans.nim b/tests/tromans.nim deleted file mode 100644 index 12deca1ea..000000000 --- a/tests/tromans.nim +++ /dev/null @@ -1,65 +0,0 @@ -import - strutils - -## Convert an integer to a Roman numeral -# See http://en.wikipedia.org/wiki/Roman_numerals for reference - -proc raiseInvalidValue(msg: string) {.noreturn.} = - # Yes, we really need a shorthand for this code... - var e: ref EInvalidValue - new(e) - e.msg = msg - raise e - -# I should use a class, perhaps. -# --> No. Why introduce additional state into such a simple and nice -# interface? State is evil. :D - -proc RomanToDecimal(romanVal: string): int = - result = 0 - var prevVal = 0 - for i in countdown(romanVal.len - 1, 0): - var val = 0 - case romanVal[i] - of 'I', 'i': val = 1 - of 'V', 'v': val = 5 - of 'X', 'x': val = 10 - of 'L', 'l': val = 50 - of 'C', 'c': val = 100 - of 'D', 'd': val = 500 - of 'M', 'm': val = 1000 - else: raiseInvalidValue("Incorrect character in roman numeral! (" & - $romanVal[i] & ")") - if val >= prevVal: - inc(result, val) - else: - dec(result, val) - prevVal = val - -proc DecimalToRoman(decValParam: int): string = - # Apparently numbers cannot be above 4000 - # Well, they can be (using overbar or parenthesis notation) - # but I see little interest (beside coding challenge) in coding them as - # we rarely use huge Roman numeral. - const romanComposites = [ - ("M", 1000), ("CM", 900), - ("D", 500), ("CD", 400), ("C", 100), - ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), - ("V", 5), ("IV", 4), ("I", 1)] - if decValParam < 1 or decValParam > 3999: - raiseInvalidValue("number not representable") - result = "" - var decVal = decValParam - for key, val in items(romanComposites): - while decVal >= val: - dec(decVal, val) - result.add(key) - -for i in 1..100: - if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG" - -for i in items([1238, 1777, 3830, 2401, 379, 33, 940, 3973]): - if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG" - -echo "success" #OUT success - diff --git a/tests/tseq2.nim b/tests/tseq2.nim deleted file mode 100644 index 03bdb3fab..000000000 --- a/tests/tseq2.nim +++ /dev/null @@ -1,13 +0,0 @@ - - -proc `*` *(a, b: seq[int]): seq[int] = - # allocate a new sequence: - newSeq(result, len(a)) - # multiply two int sequences: - for i in 0..len(a)-1: result[i] = a[i] * b[i] - -when isMainModule: - # test the new ``*`` operator for sequences: - assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) - - diff --git a/tests/tseqcon.nim b/tests/tseqcon.nim deleted file mode 100644 index 935da86b5..000000000 --- a/tests/tseqcon.nim +++ /dev/null @@ -1,45 +0,0 @@ -# Test the add proc for sequences and strings - -const - nestedFixed = true - -type - TRec {.final.} = object - x, y: int - s: string - seq: seq[string] - TRecSeq = seq[TRec] - -proc test() = - var s, b: seq[string] - s = @[] - add(s, "Hi") - add(s, "there, ") - add(s, "what's your name?") - - b = s # deep copying here! - b[0][1] = 'a' - - for i in 0 .. len(s)-1: - write(stdout, s[i]) - for i in 0 .. len(b)-1: - write(stdout, b[i]) - - -when nestedFixed: - proc nested() = - var - s: seq[seq[string]] - for i in 0..10_000: # test if the garbage collector - # now works with sequences - s = @[ - @["A", "B", "C", "D"], - @["E", "F", "G", "H"], - @["I", "J", "K", "L"], - @["M", "N", "O", "P"]] - -test() -when nestedFixed: - nested() - -#OUT Hithere, what's your name?Hathere, what's your name? diff --git a/tests/tseqcon2.nim b/tests/tseqcon2.nim deleted file mode 100644 index 6225c3bb1..000000000 --- a/tests/tseqcon2.nim +++ /dev/null @@ -1,9 +0,0 @@ -import os - -proc rec_dir(dir: string): seq[string] = - result = @[] - for kind, path in walk_dir(dir): - if kind == pcDirectory: - add(result, rec_dir(path)) - else: - add(result, path) diff --git a/tests/tsets.nim b/tests/tsets.nim deleted file mode 100644 index 08ab3e54b..000000000 --- a/tests/tsets.nim +++ /dev/null @@ -1,58 +0,0 @@ -# Test the handling of sets - -import - strutils - -proc testSets(s: var set[char]) = - s = {'A', 'B', 'C', 'E'..'G'} + {'Z'} + s - -# test sets if the first element is different from 0: -type - TAZ = range['a'..'z'] - TAZset = set[TAZ] - - TTokType* = enum - tkInvalid, tkEof, - tkSymbol, - tkAddr, tkAnd, tkAs, tkAsm, tkBlock, tkBreak, tkCase, tkCast, tkConst, - tkContinue, tkConverter, tkDiscard, tkDiv, tkElif, tkElse, tkEnd, tkEnum, - tkExcept, tkException, tkFinally, tkFor, tkFrom, tkGeneric, tkIf, tkImplies, - tkImport, tkIn, tkInclude, tkIs, tkIsnot, tkIterator, tkLambda, tkMacro, - tkMethod, tkMod, tkNil, tkNot, tkNotin, tkObject, tkOf, tkOr, tkOut, tkProc, - tkPtr, tkRaise, tkRecord, tkRef, tkReturn, tkShl, tkShr, tkTemplate, tkTry, - tkType, tkVar, tkWhen, tkWhere, tkWhile, tkWith, tkWithout, tkXor, tkYield, - tkIntLit, tkInt8Lit, tkInt16Lit, tkInt32Lit, tkInt64Lit, tkFloatLit, - tkFloat32Lit, tkFloat64Lit, tkStrLit, tkRStrLit, tkTripleStrLit, tkCharLit, - tkRCharLit, tkParLe, tkParRi, tkBracketLe, tkBracketRi, tkCurlyLe, - tkCurlyRi, tkBracketDotLe, tkBracketDotRi, - tkCurlyDotLe, tkCurlyDotRi, - tkParDotLe, tkParDotRi, - tkComma, tkSemiColon, tkColon, tkEquals, tkDot, tkDotDot, tkHat, tkOpr, - tkComment, tkAccent, tkInd, tkSad, tkDed, - tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr - TTokTypeRange = range[tkSymbol..tkDed] - TTokTypes* = set[TTokTypeRange] - -const - toktypes: TTokTypes = {TTokTypeRange(tkSymbol)..pred(tkIntLit), - tkStrLit..tkTripleStrLit} - -var - s: set[char] - a: TAZset -s = {'0'..'9'} -testSets(s) -if 'F' in s: write(stdout, "Ha ein F ist in s!\n") -else: write(stdout, "BUG: F ist nicht in s!\n") -a = {} #{'a'..'z'} -for x in low(TAZ) .. high(TAZ): - incl(a, x) - if x in a: nil - else: write(stdout, "BUG: something not in a!\n") - -for x in low(TTokTypeRange) .. high(TTokTypeRange): - if x in tokTypes: - nil - #writeln(stdout, "the token '$1' is in the set" % repr(x)) - -#OUT Ha ein F ist in s! diff --git a/tests/tsidee1.nim b/tests/tsidee1.nim deleted file mode 100644 index 3bd520680..000000000 --- a/tests/tsidee1.nim +++ /dev/null @@ -1,11 +0,0 @@ - -var - global: int - -proc dontcare(x: int): int = return x + global - -proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects - return x + y + dontcare(x) - -echo SideEffectLyer(1, 3) - diff --git a/tests/tsidee2.nim b/tests/tsidee2.nim deleted file mode 100644 index 2eaec01d7..000000000 --- a/tests/tsidee2.nim +++ /dev/null @@ -1,11 +0,0 @@ - -var - global: int - -proc dontcare(x: int): int = return x - -proc SideEffectLyer(x, y: int): int {.noSideEffect.} = - return x + y + dontcare(x) - -echo SideEffectLyer(1, 3) #OUT 5 - diff --git a/tests/tsidee3.nim b/tests/tsidee3.nim deleted file mode 100644 index be94192e7..000000000 --- a/tests/tsidee3.nim +++ /dev/null @@ -1,11 +0,0 @@ - -var - global: int - -proc dontcare(x: int): int {.noSideEffect.} = return x - -proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = - return x + y + dontcare(x) - -echo noSideEffect(1, 3, dontcare) #OUT 5 - diff --git a/tests/tsidee4.nim b/tests/tsidee4.nim deleted file mode 100644 index 55c474d10..000000000 --- a/tests/tsidee4.nim +++ /dev/null @@ -1,10 +0,0 @@ - -var - global: int - -proc dontcare(x: int): int = return x - -proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = - return x + y + dontcare(x) - -echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch diff --git a/tests/tsimmeth.nim b/tests/tsimmeth.nim deleted file mode 100644 index 3f5f810e6..000000000 --- a/tests/tsimmeth.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test method simulation - -import strutils - -var x = "hallo world!".toLower.toUpper -x.echo() -#OUT HALLO WORLD! - diff --git a/tests/tsimtych.nim b/tests/tsimtych.nim deleted file mode 100644 index b100c62e3..000000000 --- a/tests/tsimtych.nim +++ /dev/null @@ -1,5 +0,0 @@ -# Test 2 -# Simple type checking - -var a: string -a = false #ERROR diff --git a/tests/tsizeof.nim b/tests/tsizeof.nim deleted file mode 100644 index f7b70dd4d..000000000 --- a/tests/tsizeof.nim +++ /dev/null @@ -1,10 +0,0 @@ -# Test the sizeof proc - -type - TMyRecord {.final.} = object - x, y: int - b: bool - r: float - s: string - -write(stdout, sizeof(TMyRecord)) diff --git a/tests/tsockets.nim b/tests/tsockets.nim deleted file mode 100644 index cc7d18b87..000000000 --- a/tests/tsockets.nim +++ /dev/null @@ -1,11 +0,0 @@ -import sockets -var s: TSocket -s = socket() - -s.connect("www.google.com", TPort(80)) - -var recvData: string = "" -echo(s.recvLine(recvData)) -echo(recvData) - - diff --git a/tests/tsplit.nim b/tests/tsplit.nim deleted file mode 100644 index 711696b9e..000000000 --- a/tests/tsplit.nim +++ /dev/null @@ -1,14 +0,0 @@ -import strutils - -var s = "" -for w in split("|abc|xy|z", {'|'}): - s.add("#") - s.add(w) - -if s == "#abc#xy#z": - echo "true" -else: - echo "false" - -#OUT true - diff --git a/tests/tstatret.nim b/tests/tstatret.nim deleted file mode 100644 index ac93ac532..000000000 --- a/tests/tstatret.nim +++ /dev/null @@ -1,5 +0,0 @@ -# no statement after return -proc main() = - return - echo("huch?") #ERROR_MSG statement not allowed after - diff --git a/tests/tstmtexp.nim b/tests/tstmtexp.nim deleted file mode 100644 index f4d83e83f..000000000 --- a/tests/tstmtexp.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Test 3 - -1+4 #ERROR_MSG value returned by statement has to be discarded diff --git a/tests/tstrace.nim b/tests/tstrace.nim deleted file mode 100644 index 56f20a0dd..000000000 --- a/tests/tstrace.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test the new stacktraces (great for debugging!) - -{.push stack_trace: on.} - -proc recTest(i: int) = - # enter - if i < 10: - recTest(i+1) - else: # should printStackTrace() - var p: ptr int = nil - p^ = 12 - # leave - -{.pop.} - -recTest(0) diff --git a/tests/tstrange.nim b/tests/tstrange.nim deleted file mode 100644 index 13aab2302..000000000 --- a/tests/tstrange.nim +++ /dev/null @@ -1,17 +0,0 @@ -# test for extremely strange bug - -proc ack(x: int, y: int): int = - if x != 0: - if y != 5: - return y - return x - return x+y - -proc gen[T](a: T) = - write(stdout, a) - - -gen("hallo") -write(stdout, ack(5, 4)) -#OUT hallo4 - diff --git a/tests/tstrdesc.nim b/tests/tstrdesc.nim deleted file mode 100644 index 1c2e85b4b..000000000 --- a/tests/tstrdesc.nim +++ /dev/null @@ -1,14 +0,0 @@ -var - x: array [0..2, int] - -x = [0, 1, 2] - -type - TStringDesc {.final.} = object - len, space: int # len and space without counting the terminating zero - data: array [0..0, char] # for the '\0' character - -var - emptyString {.exportc: "emptyString".}: TStringDesc - - diff --git a/tests/tstrdist.nim b/tests/tstrdist.nim deleted file mode 100644 index 3e1939e73..000000000 --- a/tests/tstrdist.nim +++ /dev/null @@ -1,26 +0,0 @@ -# compute the edit distance between two strings - -proc editDistance(a, b: string): int = - var - c: seq[int] - n = a.len - m = b.len - newSeq(c, (n+1)*(m+1)) - for i in 0..n: - c[i*n] = i # [i,0] - for j in 0..m: - c[j] = j # [0,j] - - for i in 1..n: - for j in 1..m: - var x = c[(i-1)*n + j]+1 - var y = c[i*n + j-1]+1 - var z: int - if a[i-1] == b[j-1]: - z = c[(i-1)*n + j-1] - else: - z = c[(i-1)*n + j-1]+1 - c[(i-1)*n + (j-1)] = min(x,min(y,z)) - return c[n*m] - -write(stdout, editDistance("abc", "abd")) diff --git a/tests/tstreams.nim b/tests/tstreams.nim deleted file mode 100644 index 68ca8eeeb..000000000 --- a/tests/tstreams.nim +++ /dev/null @@ -1,7 +0,0 @@ -import streams - -var outp = newFileStream(stdout) -var inp = newFileStream(stdin) -write(outp, "Hallo! What is your name?") -var line = readLine(inp) -write(outp, "nice name: " & line) diff --git a/tests/tstrlits.nim b/tests/tstrlits.nim deleted file mode 100644 index 48ae08212..000000000 --- a/tests/tstrlits.nim +++ /dev/null @@ -1,14 +0,0 @@ -# Test the new different string literals - -const - tripleEmpty = """"long string"""""""" # "long string """"" - - rawQuote = r"a""" - - raw = r"abc""def" - -stdout.write(rawQuote) -stdout.write(tripleEmpty) -stdout.write(raw) -#OUT a""long string"""""abc"def - diff --git a/tests/tstrset.nim b/tests/tstrset.nim deleted file mode 100644 index e19ccee4d..000000000 --- a/tests/tstrset.nim +++ /dev/null @@ -1,74 +0,0 @@ -# test a simple yet highly efficient set of strings - -type - TRadixNodeKind = enum rnLinear, rnFull, rnLeaf - PRadixNode = ref TRadixNode - TRadixNode = object - kind: TRadixNodeKind - TRadixNodeLinear = object of TRadixNode - len: byte - keys: array [0..31, char] - vals: array [0..31, PRadixNode] - TRadixNodeFull = object of TRadixNode - b: array [char, PRadixNode] - TRadixNodeLeaf = object of TRadixNode - s: string - PRadixNodeLinear = ref TRadixNodeLinear - PRadixNodeFull = ref TRadixNodeFull - PRadixNodeLeaf = ref TRadixNodeLeaf - -proc search(r: PRadixNode, s: string): PRadixNode = - var r = r - var i = 0 - while r != nil: - case r.kind - of rnLinear: - var x = PRadixNodeLinear(r) - for j in 0..ze(x.len)-1: - if x.keys[j] == s[i]: - if s[i] == '\0': return r - r = x.vals[j] - inc(i) - break - break # character not found - of rnFull: - var x = PRadixNodeFull(r) - var y = x.b[s[i]] - if s[i] == '\0': - return if y != nil: r else: nil - r = y - inc(i) - of rnLeaf: - var x = PRadixNodeLeaf(r) - var j = 0 - while true: - if x.s[j] != s[i]: return nil - if s[i] == '\0': return r - inc(j) - inc(i) - -proc in_Operator*(r: PRadixNode, s: string): bool = - return search(r, s) != nil - -proc testOrincl*(r: var PRadixNode, s: string): bool = - nil - -proc incl*(r: var PRadixNode, s: string) = discard testOrIncl(r, s) - -proc excl*(r: var PRadixNode, s: string) = - var x = search(r, s) - if x == nil: return - case x.kind - of rnLeaf: PRadixNodeLeaf(x).s = "" - of rnFull: PRadixNodeFull(x).b['\0'] = nil - of rnLinear: - var x = PRadixNodeLinear(x) - for i in 0..ze(x.len)-1: - if x.keys[i] == '\0': - swap(x.keys[i], x.keys[ze(x.len)-1]) - dec(x.len) - break - -var - root: PRadixNode - diff --git a/tests/tstrtabs.nim b/tests/tstrtabs.nim deleted file mode 100644 index 299db609d..000000000 --- a/tests/tstrtabs.nim +++ /dev/null @@ -1,12 +0,0 @@ -import strtabs - -var tab = newStringTable(["key1", "val1", "key2", "val2"], - modeStyleInsensitive) -for i in 0..80: - tab["key_" & $i] = "value" & $i - -for key, val in pairs(tab): - writeln(stdout, key, ": ", val) -writeln(stdout, "length of table ", $tab.len) - -writeln(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment})) diff --git a/tests/tstrutil.nim b/tests/tstrutil.nim deleted file mode 100644 index 0468dfa0c..000000000 --- a/tests/tstrutil.nim +++ /dev/null @@ -1,24 +0,0 @@ -# test the new strutils module - -import - strutils - -proc testStrip() = - write(stdout, strip(" ha ")) - -proc main() = - testStrip() - for p in split("/home/a1:xyz:/usr/bin", {':'}): - write(stdout, p) - - -assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0) -assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1) -assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5) -assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3) -assert(editDistance("prefix__hallo_suffix", "prefix") == 14) -assert(editDistance("prefix__hallo_suffix", "suffix") == 14) -assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2) - -main() -#OUT ha/home/a1xyz/usr/bin diff --git a/tests/ttempl.nim b/tests/ttempl.nim deleted file mode 100644 index dcf096671..000000000 --- a/tests/ttempl.nim +++ /dev/null @@ -1,27 +0,0 @@ -# Test the new template file mechanism - -import - os, times - -include "sunset.tmpl" - -const - tabs = [["home", "index"], - ["news", "news"], - ["documentation", "documentation"], - ["download", "download"], - ["FAQ", "question"], - ["links", "links"]] - - -var i = 0 -for item in items(tabs): - var content = $i - var file: TFile - if openFile(file, changeFileExt(item[1], "html"), fmWrite): - write(file, sunsetTemplate(current=item[1], ticker="", content=content, - tabs=tabs)) - closeFile(file) - else: - write(stdout, "cannot open file for writing") - inc(i) diff --git a/tests/ttempl2.nim b/tests/ttempl2.nim deleted file mode 100644 index fba6bd0cb..000000000 --- a/tests/ttempl2.nim +++ /dev/null @@ -1,14 +0,0 @@ -template declareInScope(x: expr, t: typeDesc): stmt = - var x: t - -template declareInNewScope(x: expr, t: typeDesc): stmt = - # open a new scope: - block: - var x: t - -declareInScope(a, int) -a = 42 # works, `a` is known here - -declareInNewScope(b, int) -b = 42 #ERROR_MSG undeclared identifier: 'b' - diff --git a/tests/ttempl3.nim b/tests/ttempl3.nim deleted file mode 100644 index 0c8fa9a94..000000000 --- a/tests/ttempl3.nim +++ /dev/null @@ -1,26 +0,0 @@ - -template withOpenFile(f: expr, filename: string, mode: TFileMode, - actions: stmt): stmt = - block: - var f: TFile - if open(f, filename, mode): - try: - actions - finally: - close(f) - else: - quit("cannot open for writing: " & filename) - -withOpenFile(txt, "ttempl3.txt", fmWrite): - writeln(txt, "line 1") - txt.writeln("line 2") - -# Test zero argument template: -template ha: expr = myVar[0] - -var - myVar: array[0..1, int] - -ha = 1 -echo(ha) - diff --git a/tests/ttime.nim b/tests/ttime.nim deleted file mode 100644 index bad818816..000000000 --- a/tests/ttime.nim +++ /dev/null @@ -1,6 +0,0 @@ -# test the new time module - -import - times - -write(stdout, $getTime()) diff --git a/tests/ttuple1.nim b/tests/ttuple1.nim deleted file mode 100644 index 5787cc309..000000000 --- a/tests/ttuple1.nim +++ /dev/null @@ -1,16 +0,0 @@ -const romanNumbers = [ - ("M", 1000), ("D", 500), ("C", 100), - ("L", 50), ("X", 10), ("V", 5), ("I", 1) ] - -var c = 0 -for key, val in items(romanNumbers): - inc(c) - stdout.write(key & "=" & $val) - if c < romanNumbers.len: stdout.write(", ") else: echo"" -#echo"" - -proc PrintBiTuple(t: tuple[k: string, v: int]): int = - stdout.write(t.k & "=" & $t.v & ", ") - return 0 - - diff --git a/tests/tunderscores.nim b/tests/tunderscores.nim deleted file mode 100644 index 459cfda30..000000000 --- a/tests/tunderscores.nim +++ /dev/null @@ -1,7 +0,0 @@ -# Bug #502670 - -var ef_ = 3 #ERROR_MSG invalid token: _ -var a__b = 1 -var c___d = 2 -echo(ab, cd, ef_) - diff --git a/tests/tvardecl.nim b/tests/tvardecl.nim deleted file mode 100644 index 496601e3a..000000000 --- a/tests/tvardecl.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Test the new variable declaration syntax - -var - x = 0 - s = "Hallo" - a, b: int = 4 - -write(stdout, a) -write(stdout, b) #OUT 44 diff --git a/tests/tvarious.nim b/tests/tvarious.nim deleted file mode 100644 index 52dd46184..000000000 --- a/tests/tvarious.nim +++ /dev/null @@ -1,43 +0,0 @@ -# Test various aspects - -import - mvarious - -type - PA = ref TA - PB = ref TB - - TB = object - a: PA - - TA = object - b: TB - x: int - -proc getPA(): PA = - var - b: bool - b = not false - return nil - -var - global: int - -var - s: string - i: int - r: TA - -r.b.a.x = 0 -global = global + 1 -exportme() -write(stdout, "Hallo wie heißt du? ") -write(stdout, getPA().x) -s = readLine(stdin) -i = 0 -while i < s.len: - if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") - i = i + 1 - -write(stdout, "Du heißt " & s) - diff --git a/tests/tvarnums.nim b/tests/tvarnums.nim deleted file mode 100644 index 1b683ad94..000000000 --- a/tests/tvarnums.nim +++ /dev/null @@ -1,136 +0,0 @@ -# Test variable length binary integers - -import - strutils - -type - TBuffer = array [0..10, int8] - -proc toVarNum(x: int32, b: var TBuffer) = - # encoding: first bit indicates end of number (0 if at end) - # second bit of the first byte denotes the sign (1 --> negative) - var a = x - if x != low(x): - # low(int) is a special case, - # because abs() does not work here! - # we leave x as it is and use the check >% instead of > - # for low(int) this is needed and positive numbers are not affected - # anyway - a = abs(x) - # first 6 bits: - b[0] = toU8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63)) - a = a shr 6'i32 # skip first 6 bits - var i = 1 - while a != 0'i32: - b[i] = toU8(ord(a >% 127'i32) shl 7 or (int(a) and 127)) - inc(i) - a = a shr 7'i32 - -proc toVarNum64(x: int64, b: var TBuffer) = - # encoding: first bit indicates end of number (0 if at end) - # second bit of the first byte denotes the sign (1 --> negative) - var a = x - if x != low(x): - # low(int) is a special case, - # because abs() does not work here! - # we leave x as it is and use the check >% instead of > - # for low(int) this is needed and positive numbers are not affected - # anyway - a = abs(x) - # first 6 bits: - b[0] = toU8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63)) - a = a shr 6 # skip first 6 bits - var i = 1 - while a != 0'i64: - b[i] = toU8(ord(a >% 127'i64) shl 7 or int(a and 127)) - inc(i) - a = a shr 7 - -proc toNum64(b: TBuffer): int64 = - # treat first byte different: - result = ze64(b[0]) and 63 - var - i = 0 - Shift = 6'i64 - while (ze(b[i]) and 128) != 0: - inc(i) - result = result or ((ze64(b[i]) and 127) shl Shift) - inc(Shift, 7) - if (ze(b[0]) and 64) != 0: # sign bit set? - result = not result +% 1 - # this is the same as ``- result`` - # but gives no overflow error for low(int) - -proc toNum(b: TBuffer): int32 = - # treat first byte different: - result = ze(b[0]) and 63 - var - i = 0 - Shift = 6'i32 - while (ze(b[i]) and 128) != 0: - inc(i) - result = result or ((int32(ze(b[i])) and 127'i32) shl Shift) - Shift = shift + 7'i32 - if (ze(b[0]) and (1 shl 6)) != 0: # sign bit set? - result = (not result) +% 1'i32 - # this is the same as ``- result`` - # but gives no overflow error for low(int) - -proc toBinary(x: int64): string = - result = newString(64) - for i in 0..63: - result[63-i] = chr((int(x shr i) and 1) + ord('0')) - -proc t64(i: int64) = - var - b: TBuffer - toVarNum64(i, b) - var x = toNum64(b) - if x != i: - writeln(stdout, $i) - writeln(stdout, toBinary(i)) - writeln(stdout, toBinary(x)) - -proc t32(i: int32) = - var - b: TBuffer - toVarNum(i, b) - var x = toNum(b) - if x != i: - writeln(stdout, toBinary(i)) - writeln(stdout, toBinary(x)) - -proc tm(i: int32) = - var - b: TBuffer - toVarNum64(i, b) - var x = toNum(b) - if x != i: - writeln(stdout, toBinary(i)) - writeln(stdout, toBinary(x)) - -t32(0) -t32(1) -t32(-1) -t32(-100_000) -t32(100_000) -t32(low(int32)) -t32(high(int32)) - -t64(low(int64)) -t64(high(int64)) -t64(0) -t64(-1) -t64(1) -t64(1000_000) -t64(-1000_000) - -tm(0) -tm(1) -tm(-1) -tm(-100_000) -tm(100_000) -tm(low(int32)) -tm(high(int32)) - -writeln(stdout, "Success!") #OUT Success! diff --git a/tests/tvartup.nim b/tests/tvartup.nim deleted file mode 100644 index 05b00b207..000000000 --- a/tests/tvartup.nim +++ /dev/null @@ -1,11 +0,0 @@ -# Test the new tuple unpacking - -proc divmod(a, b: int): tuple[di, mo: int] = - return (a div b, a mod b) - -var (x, y) = divmod(15, 6) -stdout.write(x) -stdout.write(" ") -stdout.write(y) - -#OUT 2 3 diff --git a/tests/twalker.nim b/tests/twalker.nim deleted file mode 100644 index ba89ee7c6..000000000 --- a/tests/twalker.nim +++ /dev/null @@ -1,13 +0,0 @@ -# iterate over all files with a given filter: - -import - os, times - -proc main(filter: string) = - for filename in walkFiles(filter): - writeln(stdout, filename) - - for key, val in iterOverEnvironment(): - writeln(stdout, key & '=' & val) - -main("*.nim") diff --git a/tests/typalias.nim b/tests/typalias.nim deleted file mode 100644 index ba9f38ed9..000000000 --- a/tests/typalias.nim +++ /dev/null @@ -1,15 +0,0 @@ - -type - TMyObj = TYourObj - TYourObj = object of TObject - x, y: int - -proc init: TYourObj = - result.x = 0 - result.y = -1 - -proc f(x: var TYourObj) = - nil - -var m: TMyObj = init() -f(m) diff --git a/tests/typredef.nim b/tests/typredef.nim deleted file mode 100644 index a77d91f40..000000000 --- a/tests/typredef.nim +++ /dev/null @@ -1,3 +0,0 @@ -type - Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8' - diff --git a/tests/x11test.nim b/tests/x11test.nim index 2769b6c74..db51df2e0 100644 --- a/tests/x11test.nim +++ b/tests/x11test.nim @@ -61,9 +61,9 @@ proc eventloop = discard XFlush(display) var num_events = int(XPending(display)) while num_events != 0: - dec(num_events) - discard XNextEvent(display, addr(xev)) - process_event() + dec(num_events) + discard XNextEvent(display, addr(xev)) + process_event() create_window() while true: diff --git a/web/news.txt b/web/news.txt index 178bdead7..7ac039e66 100644 --- a/web/news.txt +++ b/web/news.txt @@ -23,6 +23,7 @@ Bugfixes - Fixed a serious bug in ``strutils.cmpIgnoreCase``. - Fixed ``unicode.toUTF8``. - The compiler now rejects ``'\n'``. +- ``times.getStartMilsecs()`` now works on Mac OS X. Additions -- cgit 1.4.1-2-gfad0