[Argil-svn] SF.net SVN: argil: [530] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-05-25 23:00:37
|
Revision: 530
http://argil.svn.sourceforge.net/argil/?rev=530&view=rev
Author: tswicegood
Date: 2007-05-25 16:00:37 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in the Annotation_Parser object and appropriate tests
Added Paths:
-----------
branches/experimental/src/Argil/Util/Annotation/Parser.php
branches/experimental/tests/Argil/Util/Annotation/ParserTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Parser.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Parser.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Parser.php 2007-05-25 23:00:37 UTC (rev 530)
@@ -0,0 +1,21 @@
+<?php
+
+require_once 'Argil/Util/Annotation/Collection.php';
+
+class Argil_Util_Annotation_Parser
+{
+ public function parse($string)
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ if (!preg_match_all('/@([a-z]+) ?(.*)/i', $string, $matches)) {
+ return $collection;
+ }
+
+ foreach ($matches[1] as $key => $match) {
+ $params = !empty($matches[2][$key]) ? explode(' ', $matches[2][$key]) : array();
+
+ $collection->add(new Argil_Util_Annotation_Value($match, $params));
+ }
+ return $collection;
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/ParserTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ParserTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/ParserTest.php 2007-05-25 23:00:37 UTC (rev 530)
@@ -0,0 +1,54 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Parser.php';
+
+class Argil_Util_Annontation_ParserTest extends UnitTestCase
+{
+ public function testReturnsACollectionOfAnnotationsAfterParsing()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $list = $parser->parse('');
+
+ $this->assertIsA($list, 'Argil_Util_Annotation_Collection');
+ $this->assertEqual(0, $list->count());
+ unset($list);
+
+ $random = rand(10, 20);
+ $str = <<<END
+/**
+ * @is String
+ * @dummy
+ * @table string_table
+ * @isNot Length {$random} <
+ */
+END;
+ $list = $parser->parse($str);
+ $this->assertEqual(4, $list->count());
+
+ $this->assertTrue($list->has('is'));
+ $this->assertTrue($list->has('dummy'));
+ $this->assertTrue($list->has('table'));
+ $this->assertTrue($list->has('isNot'));
+
+ $is = $list->filter('is')->current();
+ $this->assertIsA($is, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($is->name, 'is');
+ $this->assertEqual($is->params, array('String'));
+
+ $dummy = $list->filter('dummy')->current();
+ $this->assertIsA($dummy, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($dummy->name, 'dummy');
+ $this->assertEqual($dummy->params, array());
+
+ $table = $list->filter('table')->current();
+ $this->assertIsA($table, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($table->name, 'table');
+ $this->assertEqual($table->params, array('string_table'));
+
+ $isNot = $list->filter('isNot')->current();
+ $this->assertIsA($isNot, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($isNot->name, 'isNot');
+ $this->assertEqual($isNot->params, array('Length', $random, '<'));
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|