예제 #1
0
파일: Assert.php 프로젝트: djuptho/Ruler
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $ruler = new Ruler();
     $context = new Ruler\Context();
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case '__ambiguous':
                 $context[$v['option']] = $v['value'];
                 break;
             case 'h':
             case '?':
                 return $this->usage();
         }
     }
     $this->parser->listInputs($rule);
     if (empty($rule)) {
         return $this->usage();
     }
     return (int) (!$ruler->assert($rule, $context));
 }
예제 #2
0
파일: Operator.php 프로젝트: djuptho/Ruler
 public function case_lazy_or()
 {
     $this->given($ruler = new LUT(), $fExecuted = false, $gExecuted = false, $asserter = $ruler->getDefaultAsserter(), $asserter->setOperator('f', function ($a) use(&$fExecuted) {
         $fExecuted = true;
         return $a;
     }), $asserter->setOperator('g', function ($b) use(&$gExecuted) {
         $gExecuted = true;
         return $b;
     }), $rule = 'f(false) or g(true)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isTrue()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isTrue()->given($fExecuted = false, $gExecuted = false, $rule = 'f(true) or g(true)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isTrue()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isFalse()->given($fExecuted = false, $gExecuted = false, $rule = 'f(true) or g(false)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isTrue()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isFalse()->given($fExecuted = false, $gExecuted = false, $rule = 'f(false) or g(false)')->when($result = $ruler->assert($rule, new LUT\Context()))->then->boolean($result)->isFalse()->boolean($fExecuted)->isTrue()->boolean($gExecuted)->isTrue();
 }
예제 #3
0
    public function case_compile()
    {
        $expectedResult = <<<'RESULT'
$model = new \Hoa\Ruler\Model();
$model->expression =
    $model->and(
        $model->func(
            'logged',
            $model->variable('user')
        ),
        $model->and(
            $model->in(
                $model->variable('group'),
                [
                    'customer',
                    'guest'
                ]
            ),
            $model->{'>'}(
                $model->variable('points'),
                30
            )
        )
    );
RESULT;
        $this->when($result = LUT::interpret('logged(user) and group in ["customer", "guest"] and points > 30') . '')->then->string($result)->isEqualTo($expectedResult);
    }
예제 #4
0
파일: Issue.php 프로젝트: K-Phoen/Ruler
 public function case_github_50()
 {
     $this->given($ruler = new LUT(), $rule = 'variable', $context = new LUT\Context(), $context['variable'] = 'file')->when(function () use($ruler, $rule, $context) {
         $ruler->assert($rule, $context);
     })->error()->notExists();
 }
예제 #5
0
파일: Issue.php 프로젝트: djuptho/Ruler
 public function case_github_70()
 {
     $this->given($ruler = new LUT(), $rule = 'variable["foo"] is null', $context = new LUT\Context(), $context['variable'] = ['foo' => null])->when($result = $ruler->assert($rule, $context))->then->boolean($result)->isTrue();
 }