metagen/tests/run.php

117 lines
5.0 KiB
PHP
Raw Permalink Normal View History

2022-05-16 14:20:20 +03:00
#!/usr/bin/env php
<?php
require_once(__DIR__ . '/../metagen.inc.php');
require_once(__DIR__ . '/../targets/cs/cs_generator.inc.php');
require_once(__DIR__ . '/../targets/go/go_generator.inc.php');
require_once(__DIR__ . '/../targets/php/php_generator.inc.php');
assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_BAIL, true);
assert_options(ASSERT_WARNING, true);
touch(__DIR__ . '/meta/DataAll.meta');
$meta = mtg_parse_meta(array(__DIR__ . '/meta/'));
$u = $meta->findUnit("DataPlayer");
assert($u->object instanceof mtgMetaStruct);
assert($u->object->getName() == "DataPlayer");
assert($u->object->getTokens() == array('POD' => null, 'table' => 'player', 'pkey' => 'id'));
assert(sizeof($u->object->getFields()) == 4);
assert($u->object->getFields()["id"]->getType() == "uint32");
assert($u->object->getFields()["version"]->getType() == "string");
assert($u->object->getFields()["version"]->getTokens() == array('strmax' => 16));
assert($u->object->getFields()["gold"]->getType() == "uint8");
assert($u->object->getFields()["gold"]->getTokens() == array('default' => 0));
assert($u->object->getFields()["registered"]->getType() == "bool");
assert($u->object->getFields()["registered"]->getTokens() == array('default' => 'true'));
assert(sizeof($u->object->getFuncs()) == 1);
assert($u->object->getFuncs()["Equals"]->getTokens() == array('bhl_ret_type' => "bool,bool"));
assert(sizeof($u->object->getFuncs()["Equals"]->getArgs()) == 2);
assert($u->object->getFuncs()["Equals"]->getArgs()["o"]->getType() == "DataPlayer");
assert($u->object->getFuncs()["Equals"]->getArgs()["v"]->getType() == "uint32");
assert($u->object->getFuncs()["Equals"]->getReturnType() instanceof mtgMultiType);
assert($u->object->getFuncs()["Equals"]->getReturnType()->getValues()[0] == "bool");
assert($u->object->getFuncs()["Equals"]->getReturnType()->getValues()[1] == "bool");
$u = $meta->findUnit("GetPlayer");
assert($u->object instanceof mtgMetaFunc);
assert($u->object->getName() == "GetPlayer");
assert($u->object->getReturnType() == "DataPlayer");
assert(sizeof($u->object->getArgs()) == 1);
assert($u->object->getArgs()["id"]->getName() == "id");
assert($u->object->getArgs()["id"]->getType() == "uint32");
$u = $meta->findUnit("Apply");
assert($u->object instanceof mtgMetaFunc);
assert($u->object->getName() == "Apply");
assert($u->object->getReturnType() === null);
assert($u->object->getArgs()["fn"]->getName() == "fn");
assert($u->object->getArgs()["fn"]->getType() == "func (float,DataPlayer):uint32");
$u = $meta->findUnit("ProtoBase");
assert($u->object instanceof mtgMetaStruct);
assert(sizeof($u->object->getFields()) == 2);
assert($u->object->getFields()["id"]->getType() == "uint32");
assert($u->object->getFields()["title"]->getType() == "string");
assert($u->object->getFields()["title"]->getTokens() == array('strmax' => 16, 'default' => "\"`'Hello\""));
$u = $meta->findUnit("ProtoBuilding");
assert($u->object instanceof mtgMetaStruct);
assert($u->object->getParent() == "ProtoBase");
$u = $meta->findUnit("ProtoTags");
assert($u->object instanceof mtgMetaStruct);
assert(sizeof($u->object->getFields()) == 2);
assert($u->object->getFields()["children"]->getType() instanceof mtgArrType);
assert($u->object->getFields()["children"]->getType() == "ProtoBase[]");
assert($u->object->getFields()["tags"]->getType() == "string[]");
//NOTE: RPCs are identified by ids
$u = $meta->findUnit("10");
assert($u->object instanceof mtgMetaRPC);
assert($u->object->getName() == "RPC_GET_ALL_PROTO");
assert($u->object->getNumericCode() == 10);
assert(sizeof($u->object->getReq()->getFields()) == 1);
assert($u->object->getReq()->getFields()["ticket"]->getType() == "string");
assert(sizeof($u->object->getRsp()->getFields()) == 1);
assert($u->object->getRsp()->getFields()["list"]->getType() == "ProtoBase[]");
$u = $meta->findUnit("EnumStock");
assert($u->object instanceof mtgMetaEnum);
assert($u->object->getValues() == array('GOLD' => 108683766, 'XP' => 90110385));
$u = $meta->findUnit("ConfStock");
assert($u->object instanceof mtgMetaStruct);
assert(sizeof($u->object->getFields()) == 1);
assert($u->object->getFields()["id"]->getType() == "EnumStock");
mtg_run(new mtgCsGenerator(), array(
"meta" => $meta,
"out-dir" => __DIR__ . "/autogen",
"bundle" => __DIR__ . "/autogen/bundle.cs"
));
mtg_run(new mtgGoGenerator(), array(
"meta" => $meta,
"out-dir" => __DIR__ . "/autogen",
"bundle" => __DIR__ . "/autogen/bundle.go"
));
mtg_run(new mtgPHPGenerator(), array(
"meta" => $meta,
"out-dir" => __DIR__ . "/autogen",
"inc-dir" => __DIR__ . "/autogen",
"bundle" => __DIR__ . "/autogen/bundle.inc.php"
));
//TODO: было бы хорошо реализовать
//require_once(__DIR__ . '/../../gme/src/utils.inc.php');
//require_once(__DIR__ . '/autogen/bundle.inc.php');
//
//$man = new ProtoMan();
//assert(count($man->right_hands) == 1);
//assert($man->right_hands[0]->skill == 100);
//assert($man->right_hands[0]->fingers == 1);
//assert($man->right_hands[0]->fingers2 == 77);