MINOR Remove php-peg third party PHPUnit tests to avoid them being executed in default phpunit binary test runs (which auto-discover tests ignoring _manifest_exclude).

This commit is contained in:
Ingo Schommer 2011-12-04 13:37:05 +01:00
parent 1b544a46a3
commit e20304276f
9 changed files with 0 additions and 494 deletions

View File

@ -1,25 +0,0 @@
<?php
require '../Parser.php' ;
class CalculatedLiterals extends Parser {
/*!* CalculatedLiterals
string: ( /\\./ | /[^${parent.q}]/ )*
simplequote: q:/['"]/ string '$q'
freequote-matched: "qq" q:/[{\[(<]/ string '$matched'
function $matched( $res ) {
$a = array( '{' => '}', '[' => ']', '(' => ')', '<' => '>' ) ;
return $a[$res['q']] ;
}
freequote-unmatched: "qq" q:/./ string '$q'
quoted-string: freequote-matched | freequote-unmatched | simplequote
*/
}

View File

@ -1,63 +0,0 @@
<?php
require '../Parser.php' ;
class Calculator extends Parser {
/*!* Calculator
Number: /[0-9]+/
Value: Number > | '(' > Expr > ')' >
function Number( &$result, $sub ) {
$result['val'] = $sub['text'] ;
}
function Expr( &$result, $sub ) {
$result['val'] = $sub['val'] ;
}
Times: '*' > operand:Value >
Div: '/' > operand:Value >
Product: Value > ( Times | Div ) *
function Value( &$result, $sub ) {
$result['val'] = $sub['val'] ;
}
function Times( &$result, $sub ) {
$result['val'] *= $sub['operand']['val'] ;
}
function Div( &$result, $sub ) {
$result['val'] /= $sub['operand']['val'] ;
}
Plus: '+' > operand:Product >
Minus: '-' > operand:Product >
Sum: Product > ( Plus | Minus ) *
function Product( &$result, $sub ) {
$result['val'] = $sub['val'] ;
}
function Plus( &$result, $sub ) {
$result['val'] += $sub['operand']['val'] ;
}
function Minus( &$result, $sub ) {
$result['val'] -= $sub['operand']['val'] ;
}
Expr: Sum
function Sum( &$result, $sub ) {
$result['val'] = $sub['val'] ;
}
*/
}
$x = new Calculator( '(2 + 4) * 3 - 10' ) ;
$res = $x->match_Expr() ;
if ( $res === FALSE ) {
print "No Match\n" ;
}
else {
print_r( $res ) ;
}

View File

@ -1,36 +0,0 @@
<?php
require '../Parser.php' ;
class EqualRepeat extends Packrat {
/* Any number of a followed by the same number of b and the same number of c characters
* aabbcc - good
* aaabbbccc - good
* aabbc - bad
* aabbacc - bad
*/
/*!* Grammar1
A: "a" A? "b"
B: "b" B? "c"
T: !"b"
X: &(A !"b") "a"+ B !("a" | "b" | "c")
*/
}
function match( $str ) {
$p = new EqualRepeat( $str ) ;
$r = $p->match_X() ;
print "$str\n" ;
print $r ? print_r( $r, true ) : 'No Match' ;
print "\n\n" ;
}
match( 'aabbcc' ) ; // Should match
match( 'aaabbbccc' ) ; // Should match
match( 'aabbbccc' ) ; // Should not match
match( 'aaabbccc' ) ; // Should not match
match( 'aaabbbcc' ) ; // Should not match
match( 'aaabbbcccc' ) ; // Should not match

View File

@ -1,88 +0,0 @@
<?php
require '../Parser.php';
/**
* This parser strictly matches the RFC822 standard. No characters outside the ASCII range 0-127 are allowed
* @author Hamish Friedlander
*/
class Rfc822 extends Parser {
/*!* Rfc822
crlf: /\r\n/
lwsp-char: " " | "\t"
linear-white-space: (crlf? lwsp-char)+
atom: /[^\x00-\x1F\x20()<>@,;:\\".\[\]\x80-\xFF]+/
qtext-chars: /[^"\\\x0D]+/
qtext: linear-white-space | qtext-chars
quoted-pair: /\\[\x00-\x7F]/
quoted-string: .'"' ( quoted-pair | qtext )* .'"'
word: atom | quoted-string
phrase: (word >)+
dtext-chars: /[^\[\]\\\r]+/
dtext: linear-white-space | dtext-chars
domain-literal: "[" ( dtext | quoted-pair )* "]"
domain-ref: atom
sub-domain: domain-ref | domain-literal
domain: sub-domain ("." sub-domain)*
route: "@" domain ("," "@" domain)* ":"
route-addr: "<" route? addr-spec ">"
function addr_spec ( &$self, $sub ) {
$self['addr_spec'] = $sub['text'] ;
}
local-part: word ("." word)*
addr-spec: local-part "@" domain
mailbox: ( addr-spec | phrase route-addr ) >
function __construct( &$self ) {
$self['phrase'] = NULL ;
$self['address'] = NULL ;
}
function phrase ( &$self, $sub ) {
$self['phrase'] = $sub['text'] ;
}
function addr_spec ( &$self, $sub ) {
$self['address'] = $sub['text'] ;
}
function route_addr ( &$self, $sub ) {
$self['address'] = $sub['addr_spec'] ;
}
group: phrase ":" ( mailbox ("," mailbox)* )? ";"
address: :mailbox | group
address-header: address (<","> address)*
function __construct( &$self ) {
$self['addresses'] = array() ;
}
function address( &$self, $sub ) {
$self['addresses'][] = $sub['mailbox'] ;
}
*/
}
$p = new Rfc822( 'John Byorgson <byorn@again.com>, "Akira \"Bad Boy\" Kenada" <akira@neotokyo.com>' ) ;
print_r( $p->match_address_header() ) ;

View File

@ -1,30 +0,0 @@
<?php
require 'Rfc822.php';
/**
* This parser extends the RFC822 standard to allow XML entities and UTF-8 characters in atoms and quoted-strings
* @author Hamish Friedlander
*/
class Rfc822UTF8 extends Rfc822 {
/*!* Rfc822UTF8
crlf: /\r\n/u
atom: /((&[A-Za-z]+;)|(&#(xX)?[A-Fa-f0-9]+;)|([^\x00-\x1F\x20()<>@,;:\\".\[\]]))+/u
qtext-chars: /[^"\\\x0D]+/u
quoted-pair: /\\./u
*/
}
/**
* Some trial code. Remove soon
*/
$p = new Rfc822UTF8( 'JØhn ByØrgsØn <byorn@again.com>, "アキラ" <akira@neotokyo.com>' ) ;
print_r( $p->match_address_header() ) ;
/* */

View File

@ -1,123 +0,0 @@
<?php
require_once "ParserTestBase.php";
class ParserInheritanceTest extends ParserTestBase {
public function testBasicInheritance() {
$parser = $this->buildParser('
/*!* BasicInheritanceTestParser
Foo: "a"
Bar extends Foo
*/
');
$this->assertTrue($parser->matches('Foo', 'a'));
$this->assertTrue($parser->matches('Bar', 'a'));
$this->assertFalse($parser->matches('Foo', 'b'));
$this->assertFalse($parser->matches('Bar', 'b'));
}
public function testBasicInheritanceConstructFallback() {
$parser = $this->buildParser('
/*!* BasicInheritanceConstructFallbackParser
Foo: "a"
function __construct(&$res){ $res["test"] = "test"; }
Bar extends Foo
*/
');
$res = $parser->match('Foo', 'a');
$this->assertEquals($res['test'], 'test');
$res = $parser->match('Bar', 'a');
$this->assertEquals($res['test'], 'test');
$parser = $this->buildParser('
/*!* BasicInheritanceConstructFallbackParser2
Foo: "a"
function __construct(&$res){ $res["testa"] = "testa"; }
Bar extends Foo
function __construct(&$res){ $res["testb"] = "testb"; }
*/
');
$res = $parser->match('Foo', 'a');
$this->assertArrayHasKey('testa', $res);
$this->assertEquals($res['testa'], 'testa');
$this->assertArrayNotHasKey('testb', $res);
$res = $parser->match('Bar', 'a');
$this->assertArrayHasKey('testb', $res);
$this->assertEquals($res['testb'], 'testb');
$this->assertArrayNotHasKey('testa', $res);
}
public function testBasicInheritanceStoreFallback() {
$parser = $this->buildParser('
/*!* BasicInheritanceStoreFallbackParser
Foo: Pow:"a"
function *(&$res, $sub){ $res["test"] = "test"; }
Bar extends Foo
*/
');
$res = $parser->match('Foo', 'a');
$this->assertEquals($res['test'], 'test');
$res = $parser->match('Bar', 'a');
$this->assertEquals($res['test'], 'test');
$parser = $this->buildParser('
/*!* BasicInheritanceStoreFallbackParser2
Foo: Pow:"a" Zap:"b"
function *(&$res, $sub){ $res["testa"] = "testa"; }
Bar extends Foo
function *(&$res, $sub){ $res["testb"] = "testb"; }
Baz extends Foo
function Zap(&$res, $sub){ $res["testc"] = "testc"; }
*/
');
$res = $parser->match('Foo', 'ab');
$this->assertArrayHasKey('testa', $res);
$this->assertEquals($res['testa'], 'testa');
$this->assertArrayNotHasKey('testb', $res);
$res = $parser->match('Bar', 'ab');
$this->assertArrayHasKey('testb', $res);
$this->assertEquals($res['testb'], 'testb');
$this->assertArrayNotHasKey('testa', $res);
$res = $parser->match('Baz', 'ab');
$this->assertArrayHasKey('testa', $res);
$this->assertEquals($res['testa'], 'testa');
$this->assertArrayHasKey('testc', $res);
$this->assertEquals($res['testc'], 'testc');
$this->assertArrayNotHasKey('testb', $res);
}
public function testInheritanceByReplacement() {
$parser = $this->buildParser('
/*!* InheritanceByReplacementParser
A: "a"
B: "b"
Foo: A B
Bar extends Foo; B => A
Baz extends Foo; A => ""
*/
');
$parser->assertMatches('Foo', 'ab');
$parser->assertMatches('Bar', 'aa');
$parser->assertMatches('Baz', 'b');
}
}

View File

@ -1,26 +0,0 @@
<?php
require_once "ParserTestBase.php";
class ParserSyntaxTest extends ParserTestBase {
public function testBasicRuleSyntax() {
$parser = $this->buildParser('
/*!* BasicRuleSyntax
Foo: "a" "b"
Bar: "a"
"b"
Baz:
"a" "b"
Qux:
"a"
"b"
*/
');
$parser->assertMatches('Foo', 'ab');
$parser->assertMatches('Bar', 'ab');
$parser->assertMatches('Baz', 'ab');
$parser->assertMatches('Qux', 'ab');
}
}

View File

@ -1,48 +0,0 @@
<?php
$base = dirname(dirname(__FILE__));
include "$base/Compiler.php";
include "$base/Parser.php";
class ParserTestWrapper {
function __construct($testcase, $class){
$this->testcase = $testcase;
$this->class = $class;
}
function match($method, $string, $allowPartial = false){
$class = $this->class;
$func = 'match_'.$method;
$parser = new $class($string);
$res = $parser->$func();
return ($allowPartial || $parser->pos == strlen($string)) ? $res : false;
}
function matches($method, $string, $allowPartial = false){
return $this->match($method, $string, $allowPartial) !== false;
}
function assertMatches($method, $string, $message = null){
$this->testcase->assertTrue($this->matches($method, $string), $message ? $message : "Assert parser method $method matches string $string");
}
function assertDoesntMatch($method, $string, $message = null){
$this->testcase->assertFalse($this->matches($method, $string), $message ? $message : "Assert parser method $method doesn't match string $string");
}
}
class ParserTestBase extends PHPUnit_Framework_TestCase {
function buildParser($parser) {
$class = 'Parser'.sha1($parser);
echo ParserCompiler::compile("class $class extends Parser {\n $parser\n}") . "\n\n\n";
eval(ParserCompiler::compile("class $class extends Parser {\n $parser\n}"));
return new ParserTestWrapper($this, $class);
}
}

View File

@ -1,55 +0,0 @@
<?php
require_once "ParserTestBase.php";
class ParserVariablesTest extends ParserTestBase {
public function testBasicLiteralVariables() {
$parser = $this->buildParser('
/*!* BasicVariables
Foo: Letter:"a" "$Letter"
Bar: Letter:"b" "$Letter $Letter"
Baz: Letter:"c" "$Letter a $Letter a"
Qux: Letter:"d" "{$Letter}a{$Letter}a"
*/
');
$parser->assertMatches('Foo', 'aa');
$parser->assertMatches('Bar', 'bb b');
$parser->assertMatches('Baz', 'cc a c a');
$parser->assertMatches('Qux', 'ddada');
}
public function testRecurseOnVariables() {
$parser = $this->buildParser('
/*!* RecurseOnVariablesParser
A: "a"
B: "b"
Foo: $Template
Bar: Foo
function __construct(&$res){ $res["Template"] = "A"; }
Baz: Foo
function __construct(&$res){ $res["Template"] = "B"; }
*/
');
$parser->assertMatches('Bar', 'a'); $parser->assertDoesntMatch('Bar', 'b');
$parser->assertMatches('Baz', 'b'); $parser->assertDoesntMatch('Baz', 'a');
}
public function testSetOnRuleVariables() {
$parser = $this->buildParser('
/*!* SetOnRuleVariablesParser
A: "a"
B: "b"
Foo: $Template
Bar (Template = A): Foo
Baz (Template = B): Foo
*/
');
$parser->assertMatches('Bar', 'a');
$parser->assertMatches('Baz', 'b');
}
}