php/googleClientLib/envTst.php
<?php
/*********************** first comment in envTst.php
test of env.php
look at output
********************* */
$dbg = 1;
# define('OutHtml', 1);
require_once('env.php');
outBegin('mit title', 'title two');
# outBegin(new OutCsv, 'mit title', 'title two');
function tbRows($tx) {
outTR();
outW("cell$tx", 'a2');
out('out -> nl');
outW('und Wörter');
outTD('b2...');
outOL('eins 1');
outLi('zwei-2');
outOL('nesting 21');
outOLEnd('nesting 22');
out('zwei.2 weiter');
outLi('und drei');
outTD('und end 2. row');
outTR();
outTH("3. nested$tx");
outTD('mit subTable');
outTb('a');
outTD('b');
outTR('cccc');
outTbEnd("d$tx");
}
if (1) {
# outBegin();
out('wie gehts?', 'oder nicht');
outNL('outNL', 'vorher und nicht nachher');
out('zweitens wie gehts?', 'oder nicht');
outH('und', 'outH');
outEC('eins', 1, 'zwei', 2);
out('und schluesxs gehts?', 'oder nicht');
outH('Listen');
out('ordered');
outOL('ordered list eins');
outLi('zwei');
outNL('nach nl zwei');
outOL('nested ordered list drei');
outLi(32);
outOLEnd();
outOLEnd('vier');
outUL();
outLi('unordered list eins');
outLi('ul zwei');
outNL('+ nl');
outULEnd();
outH('table');
outTb();
outTCF(['l','r'], 'a');
outTRH('h1', "header2\n2zei", "hhhh3");
outTR();
outTD('eins' , 'zwei');
# err('in tableCell');
outNL(11, 12, 13);
outNL(14, 15, 16);
outTD('dreri' , 'vier');
outTRD(21,23,24);
outTbEnd();
out('ente');
outUL('eins');
outOL('elf');
out('out in nested list');
outFlush();
out('out nach flush');
outH('table to buf with flush without tbEnd');
outTbCH('tbRetC', 'first cell a1', 'second header b1', '3, head');
tbRows("-tbFlu-");
outFlush();
outH('table to buf');
outTbCH('tbRetH', 'first cell a1', 'second header b1', '3, head');
tbRows("-tbBuf-");
outTbEndCsv(':E', 'tstTb1');
}
function doErrs($m) {
out("doErrs($m) begin");
envCatch2out(function () {
out('failing assert');
assert(0 === 'failing assert', 'failing assert text');
});
envCatch2out(function () {
out('modulo zero');
$qq = 1%0;
});
envCatch2out(function () {
out('divide by zero');
$qq = 1/0;
out("1/0 = $qq");
});
envCatch2out(function () {
out('string conversion error, if fatal ==> continues only if errHH does not return false');
$errHHRet = true;
$qq = (string) function () {};
});
$errHHRet = false;
envCatch2out(function () {
out('call err()');
err('error called in doErrs');
});
out("doErrs($m) end");
}
out("php_sapi_name() =", php_sapi_name());
out('$_SERVER[REQUEST_METHOD] = ', ( isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'isset=false'));
out('$_SERVER[SERVER_PROTOCOL]=' . ( isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'isset=false'));
help("help call");
outH('error handling');
out('err() can be catched');
try {
err('err at', __line__, null, false, ['a', 'b'], 'will be catched');
} catch (Error $e) {
out('catch(Error $e) $e->getMessage()() =', $e->getMessage());
out('... $e =', $e);
}
doErrs("doErrs directly");
errHHAct();
#$errHHRet = true;
doErrs('doErrs with errHH');
out('*** errHH does not handle err(...) ==>: search for fehlerli at end, after source files!');
errHHAct(false);
outH('out');
outW('wo=word and wa=append');outW('Wb'); outA('Ac');outA('Ad');outW('We');out('OutD');
outW('EC: "= ,":'); outWEC('a',1,'b',2); outEC('c',3);
outW('CE: ", =":'); outACE('a',1,'b',2); outACE('c',3); out();
outH('lists: ol ul');
out('ol begin .....');
outOL('liste eins', 'first line');
outLi('second', 'listline');
outW('words', 'for listline', 2);
out('out', 'for 2 listline with nl');
outW('undOutW');
outLi('and 3. third outLi');
outOL();
outLi('nested ol 31');
outLi('nested 32');
outOlEnd();
outW('end 3. line');
outOLEnd('end with', "4. list line");
out('ol end .....');
out('ul begin .....');
outUL('outUL liste zwei', 'first line 21');
outLi('second', 'listline', 22);
out('out', 'for 2 listline', 22, 'withNL');
outW('outWords', 'for 22 listline');
outLi();
out('and third 23 out');
outLi('li for 24. listline');
outUL();
outLi('nested li after outUL() 241');
outLi('nested 242');
outOL('nested ol 2421');
outLi();
outOL('nested ol 24221');
outUL('nested ul 242211');
outULEnd('nested ul 242212');
outW('weiter nested ol 24221');
outOLEnd('nested ol 24222');
outOLEnd('nested ol 2423');
outW('weiter 242 end after nesting');
outUlEnd('nested', 243);
outW('weiter line 24. line');
outULEnd('end with', "25. list line");
out('ul end .....');
outH('table');
outTb('first', 'cell a1');
outTH('second', 'header', 'b1');
outTH('3, head');
tbRows('');
outTbEnd('last' , 'cell');
outTB();
outTRH("tb with", "multi", "functions");
outTRD('trd 11', 12, 13);
outTR('tr', 21);
outTDD();
outTDD('22 after ()', 23);
outTR('tr' , 31);
outTHH('hh 32', 33);
outTBEnd();
outTB();
outTCF('l', 'r', 'l', 'r');
outTRH('left0', 'right1', 'left2', 'right3', 'unspec4');
out('nl');
outW('word');
outTRD('row1left0', 'row1right1', 'row1left2', 'row1right3', 'row1unspec4');
outTRD('r2left0', 'r2right1');
out('nl');
outW('word');
outTRH('h3left0');
outNL('und', 'outNL...');
outTH('h3right1');
outTBEnd();
outH('arguments from uri or commandline');
out('envArgs()==', envArgs(), 'envArg with def==', envArgs('a=1 b c=3 a=4'));
function tstEnvArg($aa, ...$tsts) {
$ea = new EnvArg($aa);
out("tstEnvArg($aa), type=", $ea->type);
outUL();
foreach($tsts as $t) {
outLi('arg(', $t, ') ===', $ea->arg($t), ', val ===', $ea->val);
outOL("itr1 begin {$ea->itr1}");
foreach($ea->{$ea->itr1}() as $oprK => $oprV)
outLi("$oprK =>", $oprV);
outOLend();
outOL("iterate begin");
foreach($ea->iterate() as $oprK => $oprV)
outLi("$oprK =>", $oprV, ', val=', $ea->val);
outOLend();
}
outULend();
return $ea;
}
$ea = tstEnvArg('ai bb ci hh', envArgs(), ['a=1', 'b', 'c=3', 'a=4', 'ende', 'gut']);
out('$ea->do: iterate using callbacktable, arg =', $ea->arg);
outOL();
$ea->do($cbt = ['a' => function ($v) { outLi('function at $cbt[a] v=', $v); }
,'' => function ($v) { outLi('function AT $cbt[] v=', $v); }]
, function ($k, $v) use($cbt) { outLi('function undef key', $k, '=>', $v, 'supported are'
, implode(', ', array_keys($cbt))); }, 'a=1 b c=3 a=4' );
outOLEnd();
tstEnvArg('asahaSo bb cb0 dsundWeiter [sdefArg...', envArgs(), explode(' ', 'null -arunA eins -bcdrunBweiter zwei -d drunNa drei'), ['-arunA', '-bcdrunBweiter', '-d', 'drunNa']);
tstEnvArg('asahaSo bb c> d>sd_def e>s--e-def f>s- r> q<sqdef hh', envArgs(), explode(' ', 'null b=arunA eins r=zwei drei a=due vier q=fuenf sechs'), ['-eeEins', 'eZwei', 'ccDr']
, ['aha', '?h', 'y', '-aundA']);
tstEnvArg('as ab=s abc=s db de=b def=b' , envArgs(), explode(' ', '-aNurA -ab2ab -abc3abc -d d1 -dde d1de2 -defded defded +ddef plusDDef'));
function tstFmt() {
$tst = [];
outTb();
outTCF('r');
foreach ( [0, 1, 9, 10, 11,87, 99, 99.999, 100, 100.0001, 123456, 2e15, 3e37, 4.5e-3, 6.78e-10, 9.012e-13, 123e111, 9e-10, 0.99e-9] as $t1) {
foreach ( [1, -1, 1/7] as $t2) {
$t = $t1 * $t2;
outTRD(sprintf("%12.3e", $t), fmtE($t,3), fmtE($t,4), fmtE($t,5), fmtE($t), fmtE($t,7), fmtG($t, 8), fmtG($t, 9, '+'), $t);
}
}
outTbEnd();
}
outH('fmtE, fmtG');
tstFmt();
class C1 {
public $v = 'C1->v';
public $f = 'f start';
function eins() {
out('called eins', $this->v);
}
function zwei() {
out('called zwei', $this->v);
}
static function test() {
$o = new C1();
$o->eins();
$o->zwei();
$o->v .= ' mod';
$o->eins();
$o->zwei();
$o->v .= ' via f';
$o->f = 'eins';
$o->{$o->f}();
$o->f = 'zwei';
$o->{$o->f}();
}
}
# outH('C1');
# C1::test();
outH(__FILE__);
echo highlightNum(__FILE__);
outH('env.php');
echo highlightNum('env.php');
err('test fehlerli nachher', ['null', 1, 'und' => 'so weiter']);
outEnd(__FILE__);
?>