Skip to content

Commit

Permalink
adding appos removing cruft classes
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunxcode committed May 18, 2011
1 parent 402d878 commit 67a1592
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 152 deletions.
6 changes: 6 additions & 0 deletions src/Appos.php
@@ -0,0 +1,6 @@
<?php
namespace Phutility;

class Appos {

}
106 changes: 0 additions & 106 deletions src/MOP.php

This file was deleted.

15 changes: 14 additions & 1 deletion src/Node.php
Expand Up @@ -4,7 +4,7 @@
class Node {
protected $_type;
protected $_vals;
public function __construct($type, $vals) {
public function __construct($type, $vals = array()) {
$this->_type = $type;
$this->_vals = $vals;
}
Expand Down Expand Up @@ -84,4 +84,17 @@ public function add($node) {
$this->_vals[] = $node;
return $this;
}

public function toArray() {
$array = array();
foreach($this->_vals as $val) {
if($val instanceof Node) {
$array[] = array($val->getType() => $val->toArray());
} else {
$array[] = is_scalar($val) ? $val : (array)$val;
}
}

return $array;
}
}
21 changes: 11 additions & 10 deletions src/Parser.php
Expand Up @@ -3,7 +3,7 @@
namespace Phutility;

class Parser {
public static function subExpressions($chars, $brackets = array('(' => ')')) {
public static function subExpressions($chars, $callback = false, $brackets = array('(' => ')')) {
$tree = array();

if(is_string($chars)) {
Expand All @@ -13,16 +13,17 @@ public static function subExpressions($chars, $brackets = array('(' => ')')) {

$chars = explode(
' ',
str_replace(
$flatBrackets,
array_map(
function($i) { return " $i "; },
$flatBrackets),
$chars));
preg_replace('/\s+/', ' ',
str_replace(
$flatBrackets,
array_map(
function($i) { return " $i "; },
$flatBrackets),
$chars)));
}

foreach($chars as $char) {
if(empty($char)) {
if($char == ' ') {
continue;
}

Expand All @@ -46,7 +47,7 @@ function($i) { return " $i "; },
if($count) {
$branch[] = $char;
} else {
$tree[] = Parser::subExpressions($branch);
$tree[] = Parser::subExpressions($branch, $callback, $brackets);
unset($branch);
unset($count);
}
Expand All @@ -56,6 +57,6 @@ function($i) { return " $i "; },
$tree[] = $char;
}

return $tree;
return $callback($tree);
}
}
30 changes: 0 additions & 30 deletions src/String.php

This file was deleted.

27 changes: 22 additions & 5 deletions src/Test.php
Expand Up @@ -14,21 +14,38 @@ public static function text($color, $text = '') {
return chr(27) . self::$colors[$color] . $text;
}

public static function assert($description, $val, $isVal = true) {
$pass = $val == $isVal;

private static function outputResult($description, $val, $isVal, $pass = false) {
if($pass) {
self::$passCount++;
} else {
self::$failCount++;
}

echo self::text('white', $description . ' ['
. self::text($pass ? 'green' : 'red', $pass ? 'PASS' : 'FAIL [expected: ' . json_encode($isVal) . ' | got: ' . json_encode($val) . ']'))
. self::text($pass ? 'green' : 'red', $pass ? 'PASS' : 'FAIL [expected: '
. json_encode(is_callable(array($isVal, 'toArray')) ? $isVal->toArray() : $val)
. ' | got: '
. json_encode(is_callable(array($val, 'toArray')) ? $val->toArray() : $val)
. ']'))
. self::text('white', ']')
. self::text('normal', "\n");

return $pass;
return $pass;
}

public static function assert($description, $val, $isVal = true) {
return self::outputResult($description, $val, $isVal, $val == $isVal);
}

public static function throwsException($description, $func, $exception = '\Exception') {
$result = false;
try {
$func();
} catch (\Exception $e) {
$result = true;
}
return self::outputResult($description, "[closure]", $exception, $result);

}

public static function totals() {
Expand Down

0 comments on commit 67a1592

Please sign in to comment.