metagen/tests/run.php

86 lines
3.9 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
require_once(__DIR__ . '/../metagen.inc.php');
require_once(__DIR__ . '/../parser.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");