Permalink
Browse files

Implemented concat(.).

  • Loading branch information...
1 parent b5f1d43 commit 9671b741d0c438aa786071740852e80327f9e4c4 @dahlia dahlia committed Nov 28, 2009
Showing with 27 additions and 0 deletions.
  1. +1 −0 Lisphp/Environment.php
  2. +1 −0 Lisphp/Runtime.php
  3. +11 −0 Lisphp/Runtime/String.php
  4. +2 −0 Lisphp/Test/EnvironmentTest.php
  5. +12 −0 Lisphp/Test/RuntimeTest.php
View
@@ -45,6 +45,7 @@ static function sandbox() {
$scope['*'] = new Lisphp_Runtime_Arithmetic_Multiplication;
$scope['/'] = new Lisphp_Runtime_Arithmetic_Division;
$scope['%'] = $scope['mod'] =new Lisphp_Runtime_Arithmetic_Modulus;
+ $scope['.'] = $scope['concat'] =new Lisphp_Runtime_String_Concat;
$scope['not'] = new Lisphp_Runtime_Logical_Not;
$scope['and'] = new Lisphp_Runtime_Logical_And;
$scope['or'] = new Lisphp_Runtime_Logical_Or;
View
@@ -14,6 +14,7 @@
require_once 'Runtime/Predicate.php';
require_once 'Runtime/Arithmetic.php';
require_once 'Runtime/List.php';
+require_once 'Runtime/String.php';
require_once 'Runtime/PHPFunction.php';
require_once 'Runtime/PHPClass.php';
require_once 'Runtime/Use.php';
View
@@ -0,0 +1,11 @@
+<?php
+require_once 'Lisphp/Runtime/BuiltinFunction.php';
+
+final class Lisphp_Runtime_String_Concat
+ extends Lisphp_Runtime_BuiltinFunction {
+ protected function execute(array $arguments) {
+ if (isset($arguments[0])) return join('', $arguments);
+ throw new InvalidArgumentException('too few strings');
+ }
+}
+
@@ -66,6 +66,8 @@ function testSandbox($scope = null) {
$this->assertType('Lisphp_Runtime_Arithmetic_Division', $scope['/']);
$this->assertType('Lisphp_Runtime_Arithmetic_Modulus', $scope['%']);
$this->assertType('Lisphp_Runtime_Arithmetic_Modulus', $scope['mod']);
+ $this->assertType('Lisphp_Runtime_String_Concat', $scope['.']);
+ $this->assertType('Lisphp_Runtime_String_Concat', $scope['concat']);
$this->assertType('Lisphp_Runtime_Logical_Not', $scope['not']);
$this->assertType('Lisphp_Runtime_Logical_And', $scope['and']);
$this->assertType('Lisphp_Runtime_Logical_Or', $scope['or']);
@@ -631,6 +631,18 @@ function testFoldl() {
}
}
+ function testConcat() {
+ $concat = new Lisphp_Runtime_String_Concat;
+ $this->assertFunction('ab', $concat, 'a', 'b');
+ $this->assertFunction('hello world!', $concat, 'hello', ' world', '!');
+ try {
+ $this->applyFunction($concat);
+ $this->fail();
+ } catch (InvalidArgumentException $e) {
+ # pass.
+ }
+ }
+
function methodTest($a) {
return array($this, $a);
}

0 comments on commit 9671b74

Please sign in to comment.