示例#1
0
 public function testFromFile()
 {
     $testFiles = glob(__DIR__ . '/Functional/*.lisphp');
     foreach ($testFiles as $file) {
         $code = file_get_contents($file);
         $scope = Lisphp_Environment::workflow();
         $program = new Lisphp_Program($code);
         $result = $program->execute($scope);
         $expected = file_get_contents(preg_replace('/\\.lisphp$/', '.out', $file));
         $this->assertSame(trim($expected), trim($result));
     }
 }
示例#2
0
 public function testWorkflow($scope = null)
 {
     if (is_null($scope)) {
         $scope = Lisphp_Environment::workflow();
     }
     $this->assertType('Lisphp_Scope', $scope);
     $this->assertNull($scope['nil']);
     $this->assertTrue($scope['true']);
     $this->assertTrue($scope['else']);
     $this->assertFalse($scope['false']);
     $this->assertTrue($scope['#t']);
     $this->assertFalse($scope['#f']);
     $this->assertNoType('Lisphp_Runtime_Eval', $scope['eval']);
     $this->assertType('Lisphp_Runtime_Quote', $scope['quote']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['symbol']);
     $this->assertEquals(['Lisphp_Symbol', 'get'], $scope['symbol']->callback);
     $this->assertType('Lisphp_Runtime_Define', $scope['define']);
     $this->assertNoType('Lisphp_Runtime_Let', $scope['let']);
     $this->assertNoType('Lisphp_Runtime_Macro', $scope['macro']);
     $this->assertNoType('Lisphp_Runtime_Lambda', $scope['lambda']);
     $this->assertNoType('Lisphp_Runtime_Apply', $scope['apply']);
     $this->assertNoType('Lisphp_Runtime_Do', $scope['do']);
     $this->assertNoType('Lisphp_Runtime_Dict', $scope['dict']);
     $this->assertNoType('Lisphp_Runtime_Array', $scope['array']);
     $this->assertNoType('Lisphp_Runtime_List', $scope['list']);
     $this->assertNoType('Lisphp_Runtime_List_Car', $scope['car']);
     $this->assertNoType('Lisphp_Runtime_List_Cdr', $scope['cdr']);
     $this->assertNoType('Lisphp_Runtime_List_At', $scope['at']);
     $this->assertNoType('Lisphp_Runtime_List_SetAt', $scope['set-at!']);
     $this->assertNoType('Lisphp_Runtime_List_UnsetAt', $scope['unset-at!']);
     $this->assertNoType('Lisphp_Runtime_List_ExistsAt', $scope['exists-at?']);
     $this->assertNoType('Lisphp_Runtime_List_Count', $scope['count']);
     $this->assertNoType('Lisphp_Runtime_List_Map', $scope['map']);
     $this->assertNoType('Lisphp_Runtime_List_Filter', $scope['filter']);
     $this->assertNoType('Lisphp_Runtime_List_Fold', $scope['fold']);
     $this->assertNoType('Lisphp_Runtime_List_Cond', $scope['cond']);
     $this->assertType('Lisphp_Runtime_Predicate_Eq', $scope['==']);
     $this->assertType('Lisphp_Runtime_Predicate_Eq', $scope['eq']);
     $this->assertType('Lisphp_Runtime_Predicate_Eq', $scope['eq?']);
     $this->assertType('Lisphp_Runtime_Predicate_Equal', $scope['=']);
     $this->assertType('Lisphp_Runtime_Predicate_Equal', $scope['equal']);
     $this->assertType('Lisphp_Runtime_Predicate_Equal', $scope['equal?']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['/==']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['!==']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['not-eq']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['not-eq?']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['!=']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['/=']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['not-equal']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['not-equal?']);
     foreach (Lisphp_Runtime_Predicate_Type::$types as $type) {
         $this->assertNoType('Lisphp_Runtime_Predicate_Type', $scope["{$type}?"]);
         // $this->assertEquals($type, $scope["$type?"]->type);
     }
     $this->assertNoType('Lisphp_Runtime_Predicate_Type', $scope['nil?']);
     // $this->assertEquals('null', $scope['nil?']->type);
     $this->assertNoType('Lisphp_Runtime_Predicate_IsA', $scope['is-a?']);
     $this->assertNoType('Lisphp_Runtime_Predicate_IsA', $scope['isa?']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Addition', $scope['+']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Subtraction', $scope['-']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Multiplication', $scope['*']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Division', $scope['/']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Modulus', $scope['%']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Modulus', $scope['mod']);
     $this->assertNoType('Lisphp_Runtime_PHPFunction', $scope['string']);
     // $this->assertEquals('strval', $scope['string']->callback);
     $this->assertNoType('Lisphp_Runtime_String_Concat', $scope['.']);
     $this->assertNoType('Lisphp_Runtime_String_Concat', $scope['concat']);
     $this->assertNoType('Lisphp_Runtime_String_StringJoin', $scope['string-join']);
     $this->assertNoType('Lisphp_Runtime_PHPFunction', $scope['substring']);
     // $this->assertEquals('substr', $scope['substring']->callback);
     $this->assertNoType('Lisphp_Runtime_PHPFunction', $scope['string-upcase']);
     // $this->assertEquals('strtoupper', $scope['string-upcase']->callback);
     $this->assertNoType('Lisphp_Runtime_PHPFunction', $scope['string-downcase']);
     // $this->assertEquals('strtolower', $scope['string-downcase']->callback);
     $this->assertType('Lisphp_Runtime_Logical_Not', $scope['not']);
     $this->assertType('Lisphp_Runtime_Logical_And', $scope['and']);
     $this->assertType('Lisphp_Runtime_Logical_Or', $scope['or']);
     $this->assertType('Lisphp_Runtime_Logical_If', $scope['if']);
     $this->assertNoType('Lisphp_Runtime_Object_GetAttribute', $scope['->']);
     // Expand
     $this->assertType('Workflow\\LispExpand\\String\\FetchUrl', $scope['fetch-url']);
     $this->assertType('Workflow\\LispExpand\\String\\ToJson', $scope['to-json']);
     $this->assertType('Workflow\\LispExpand\\String\\ShortUrl', $scope['short-url']);
 }
示例#3
0
 /**
  * @return \Phalcon\Http\ResponseInterface|string|void
  */
 public function resultAction()
 {
     $hash_id = $this->request->getQuery('id', 'string', '');
     $workflow = $this->workflow->findFirst($hash_id, $this->current_user->id);
     if ($workflow) {
         // delete old result
         $result = WorkflowResult::findByWf_id($workflow->id);
         $result->delete();
         // set globals var
         $GLOBALS['workflow_id'] = $workflow->id;
         $GLOBALS['user_id'] = $this->current_user->id;
         $var_code = '';
         $var = WorkflowVar::findByWf_id($workflow->id);
         foreach ($var as $item) {
             if (is_string($item->value)) {
                 $var_code .= sprintf('(define %s "%s")', $item->name, str_replace('"', '\\"', $item->value));
             } else {
                 $var_code .= sprintf('(define %s %s)', $item->name, $item->value);
             }
         }
         // run code
         try {
             $env = Lisphp_Environment::workflow();
             $program = new Lisphp_Program($var_code . $workflow->code_snippets);
             $code_result = $program->execute($env);
         } catch (Exception $e) {
             $code_result = $e->getMessage();
         }
         // active
         UserActive::record('workflow-run', $this->current_user->id);
         // unset globals var
         unset($GLOBALS['workflow_id']);
         // new result
         $workflow_result = WorkflowResult::findByWf_id($workflow->id);
         $this->view->setVar('title', $workflow->title);
         $this->view->setVar('code_result', $code_result);
         $this->view->setVar('workflow_result', $workflow_result);
         return $this->view->partial('workflow/result');
     } else {
         return $this->response->redirect('workflow/lists');
     }
 }