225 lines
5.8 KiB
PHP
225 lines
5.8 KiB
PHP
<?php
|
|
|
|
// require_once(DIR_ALVEOLATA . '/definitions.php');
|
|
require_once(DIR_ALVEOLATA . '/args/functions.php');
|
|
|
|
|
|
\alveolata\test\add(
|
|
[
|
|
'name' => 'alveolata',
|
|
'sections' => [
|
|
[
|
|
'name' => 'args',
|
|
'setup' => function (&$environment) {
|
|
$spec_raw = [
|
|
'positioned_mandatory' => [
|
|
[
|
|
'target' => 'hagalaz',
|
|
],
|
|
],
|
|
'positioned_optional' => [
|
|
[
|
|
'target' => 'naudhiz',
|
|
'default' => 'hau_mich_blau',
|
|
],
|
|
],
|
|
'named' => [
|
|
'fehuz' => [
|
|
// 'target' => 'fehuz',
|
|
'default' => false,
|
|
'processing' => function ($x) {return ($x === 'yes');},
|
|
],
|
|
'uruz' => [
|
|
// 'target' => 'uruz',
|
|
'default' => 42,
|
|
'processing' => function ($x) {return intval($x);},
|
|
],
|
|
'thurisaz' => [
|
|
// 'target' => 'thurisaz',
|
|
'default' => 2.7182,
|
|
'processing' => function ($x) {return floatval($x);},
|
|
],
|
|
'ansuz' => [
|
|
// 'target' => 'ansuz',
|
|
'default' => 'math',
|
|
'processing' => function ($x) {return ($x);},
|
|
],
|
|
],
|
|
];
|
|
$environment['call'] = function ($args_raw) use (&$spec_raw) {
|
|
return \alveolata\args\parse(
|
|
$spec_raw,
|
|
$args_raw,
|
|
[
|
|
'supress_warnings' => false,
|
|
]
|
|
);
|
|
};
|
|
},
|
|
'cleanup' => function (&$environment) {
|
|
},
|
|
'sections' => [
|
|
[
|
|
'name' => 'parse',
|
|
'cases' => [
|
|
[
|
|
'name' => 'positined_mandatory_missing',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$assert->crashes(
|
|
function () use (&$environment) {
|
|
$args = $environment['call']([]);
|
|
}
|
|
);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'positined_mandatory_present',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo']);
|
|
|
|
// assertions
|
|
$assert->equal($args['hagalaz'], 'foo');
|
|
}
|
|
],
|
|
[
|
|
'name' => 'positined_optional_missing',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo']);
|
|
|
|
// assertions
|
|
$assert->equal($args['naudhiz'], 'hau_mich_blau');
|
|
}
|
|
],
|
|
[
|
|
'name' => 'positined_optional_present',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo', 'bar']);
|
|
|
|
// assertions
|
|
$assert->equal($args['naudhiz'], 'bar');
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_boolean_missing',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo']);
|
|
|
|
// assertions
|
|
$assert->equal($args['fehuz'], false);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_boolean_present_negative',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo', '--fehuz=no']);
|
|
|
|
// assertions
|
|
$assert->equal($args['fehuz'], false);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_boolean_present_positive',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo', '--fehuz=yes']);
|
|
|
|
// assertions
|
|
$assert->equal($args['fehuz'], true);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_integer_missing',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo']);
|
|
|
|
// assertions
|
|
$assert->equal($args['uruz'], 42);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_integer_present',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo', '--uruz=7']);
|
|
|
|
// assertions
|
|
$assert->equal($args['uruz'], 7);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_float_missing',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo']);
|
|
|
|
// assertions
|
|
$assert->equal($args['thurisaz'], 2.7182);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_float_present',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo', '--thurisaz=3.1415']);
|
|
|
|
// assertions
|
|
$assert->equal($args['thurisaz'], 3.1415);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_string_missing',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo']);
|
|
|
|
// assertions
|
|
$assert->equal($args['ansuz'], 'math');
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_string_present',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution
|
|
$args = $environment['call'](['foo', '--ansuz=algebra']);
|
|
|
|
// assertions
|
|
$assert->equal($args['ansuz'], 'algebra');
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_malformed',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution & assertions
|
|
$assert->runs(
|
|
function () use (&$environment) {
|
|
$args = $environment['call'](['foo', '--raid==ho=odin']);
|
|
}
|
|
);
|
|
}
|
|
],
|
|
[
|
|
'name' => 'named_unspecified',
|
|
'procedure' => function ($assert, $environment) {
|
|
// execution & assertions
|
|
$assert->runs(
|
|
function () use (&$environment) {
|
|
$args = $environment['call'](['foo', '--raidho=odin']);
|
|
}
|
|
);
|
|
}
|
|
],
|
|
]
|
|
],
|
|
]
|
|
]
|
|
]
|
|
]
|
|
);
|
|
|