[limb-svn] r5808 - in 3.x/trunk/limb/macro: src tests/cases

svn at limb-project.com svn at limb-project.com
Sat May 5 01:32:57 MSD 2007


Author: pachanga
Date: 2007-05-05 01:32:57 +0400 (Sat, 05 May 2007)
New Revision: 5808
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5808

Added:
   3.x/trunk/limb/macro/src/lmbMacroTokenizer.class.php
   3.x/trunk/limb/macro/src/lmbMacroTokenizerListener.interface.php
   3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerMalformedTest.class.php
   3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php
Removed:
   3.x/trunk/limb/macro/src/lmbMacroParser.class.php
   3.x/trunk/limb/macro/src/lmbMacroParserListener.interface.php
   3.x/trunk/limb/macro/tests/cases/lmbMacroParserMalformedTest.class.php
   3.x/trunk/limb/macro/tests/cases/lmbMacroParserTest.class.php
Log:
-- lmbMacroParser => lmbMacroTokenizer

Deleted: 3.x/trunk/limb/macro/src/lmbMacroParser.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroParser.class.php	2007-05-04 14:07:37 UTC (rev 5807)
+++ 3.x/trunk/limb/macro/src/lmbMacroParser.class.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -1,255 +0,0 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    macro
- */
-
-class lmbMacroParser
-{
-  protected $publicId;
-  protected $observer;
-  protected $rawtext;
-  protected $position;
-  protected $length;
-
-  function __construct($observer)
-  {
-    $this->observer = $observer;
-  }
-
-  function getLineNumber()
-  {
-    return 1 + substr_count(substr($this->rawtext, 0, $this->position), "\n");
-  }
-
-  function getCurrentLocation()
-  {
-    return new lmbMacroSourceLocation($this->getPublicId(), $this->getLineNumber());
-  }
-
-  function getPublicId()
-  {
-    return $this->publicId;
-  }
-
-  /**
-  * Moves the position forward past any whitespace characters
-  */
-  function ignoreWhitespace()
-  {
-    while($this->position < $this->length &&
-        strpos(" \n\r\t", $this->rawtext{$this->position}) !== false)
-      $this->position++;
-  }
-
-  /**
-  * Begins the parsing operation, setting up any decorators, depending on
-  * parse options invoking _parse() to execute parsing
-  */
-  function parse($data, $publicId = null)
-  {
-    $this->rawtext = $data;
-    $this->length = strlen($data);
-    $this->position = 0;
-    $this->publicId = $publicId;
-
-    do
-    {
-      $start = $this->position;
-      $this->position = strpos($this->rawtext, '<%', $start);
-      if($this->position === false)
-      {
-        if($start < $this->length)
-          $this->observer->characters(substr($this->rawtext, $start));
-        return;
-      }
-
-      if($this->position > $start)
-      {
-        $this->observer->characters(substr($this->rawtext, $start, $this->position - $start));
-      }
-
-      $this->position += 2;   // ignore '<%' string
-      if($this->position >= $this->length)
-      {
-        $this->observer->unexpectedEOF('<%');
-        return;
-      }
-
-      $element_pos = $this->position;
-      $this->position += 1;
-
-      switch($this->rawtext{$element_pos})
-      {
-        case '/':
-          $start = $this->position;
-          while($this->position < $this->length &&
-                $this->rawtext{$this->position} != '%' &&
-                $this->rawtext{$this->position+1} != '>')
-            $this->position++;
-
-          if($this->position >= $this->length)
-          {
-            $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-            return;
-          }
-
-          $tag = substr($this->rawtext, $start, $this->position - $start);
-
-          $this->observer->endElement($tag);
-          $this->position += 2;   // ignore '%>' string
-          break;
-
-      default:
-          while($this->position < $this->length && strpos("%/ \n\r\t", $this->rawtext{$this->position}) === false)
-            $this->position++;
-
-          if($this->position >= $this->length)
-          {
-            $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-            return;
-          }
-
-          $tag = substr($this->rawtext, $element_pos, $this->position - $element_pos);
-          $attributes = array();
-
-          $this->ignoreWhitespace();
-
-          //tag attributes
-          while($this->position < $this->length &&
-                $this->rawtext{$this->position} != '%' &&
-                $this->rawtext{$this->position} != '/')
-          {
-            $start = $this->position;
-            while($this->position < $this->length && strpos("%= \n\r\t", $this->rawtext{$this->position}) === false)
-              $this->position++;
-
-            if($this->position >= $this->length)
-            {
-              $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-              return;
-            }
-
-            $attribute_name = substr($this->rawtext, $start, $this->position - $start);
-            $attribute_value = null;
-
-            $this->ignoreWhitespace();
-            if($this->position >= $this->length)
-            {
-              $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-              return;
-            }
-
-            if($this->rawtext{$this->position} == '=')
-            {
-              $attribute_value = "";
-
-              $this->position++;
-              $this->ignoreWhitespace();
-              if($this->position >= $this->length)
-              {
-                $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-                return;
-              }
-
-              $quote = $this->rawtext{$this->position};
-              if($quote == '"' || $quote == "'")
-              {
-                $start = $this->position + 1;
-                $this->position = strpos($this->rawtext, $quote, $start);
-                if($this->position === false)
-                {
-                  $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-                  return;
-                }
-
-                $attribute_value = substr($this->rawtext, $start, $this->position - $start);
-
-                $this->position++;
-                if($this->position >= $this->length)
-                {
-                  $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-                  return;
-                }
-
-                if(strpos("% \n\r\t", $this->rawtext{$this->position}) === false)
-                  $this->observer->invalidAttributeSyntax();
-
-              }
-              else
-              {
-                $start = $this->position;
-                while($this->position < $this->length && strpos("% \n\r\t", $this->rawtext{$this->position}) === false)
-                  $this->position++;
-
-                if($this->position >= $this->length)
-                {
-                  $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-                  return;
-                }
-                $attribute_value = substr($this->rawtext, $start, $this->position - $start);
-              }
-            }
-
-            $attributes[$attribute_name] = $attribute_value;
-
-            $this->ignoreWhitespace();
-          }
-
-          if($this->position >= $this->length)
-          {
-            $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-            return;
-          }
-
-          //self closing tag check
-          if($this->rawtext{$this->position} == '/' && $this->rawtext{$this->position + 1} == '%')
-          {
-            $this->position += 2;
-            if($this->position >= $this->length)
-            {
-              $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
-              return;
-            }
-
-            if($this->rawtext{$this->position} != '>')
-            {
-              $start = $this->position;
-              while($this->position < $this->length && $this->rawtext{$this->position} != '>')
-                $this->position++;
-
-              if($this->position >= $this->length)
-              {
-                $this->observer->invalidEntitySyntax(substr($this->rawtext, $element_pos - 2));
-                break;
-              }
-
-              $this->observer->invalidEntitySyntax(substr($this->rawtext, $element_pos - 2,
-                                                          $this->position - $element_pos + 2));
-              $this->position += 1;
-              break;
-            }
-            $this->observer->emptyElement($tag, $attributes);
-          }
-          else
-          {
-            $this->observer->startElement($tag, $attributes);
-            //skipping %
-            $this->position += 1;
-          }
-
-          $this->position += 1;
-
-          break;
-        }
-    }
-    while ($this->position < $this->length);
-  }
-}
-?>

Deleted: 3.x/trunk/limb/macro/src/lmbMacroParserListener.interface.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroParserListener.interface.php	2007-05-04 14:07:37 UTC (rev 5807)
+++ 3.x/trunk/limb/macro/src/lmbMacroParserListener.interface.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -1,24 +0,0 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id: WactParserListener.interface.php 5553 2007-04-06 09:05:17Z serega $
- * @package    view
- */
-
-interface lmbMacroParserListener
-{
-  function startElement($tag_name, $attrs);
-  function endElement($tag_name);
-  function emptyElement($tag_name, $attrs);
-  function characters($data);
-  function unexpectedEOF($data);
-  function invalidEntitySyntax($data);
-  function invalidAttributeSyntax();
-  function setDocumentLocator($locator);
-}
-?>
\ No newline at end of file

Copied: 3.x/trunk/limb/macro/src/lmbMacroTokenizer.class.php (from rev 5796, 3.x/trunk/limb/macro/src/lmbMacroParser.class.php)
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTokenizer.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/lmbMacroTokenizer.class.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -0,0 +1,255 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    macro
+ */
+
+class lmbMacroTokenizer
+{
+  protected $publicId;
+  protected $observer;
+  protected $rawtext;
+  protected $position;
+  protected $length;
+
+  function __construct($observer)
+  {
+    $this->observer = $observer;
+  }
+
+  function getLineNumber()
+  {
+    return 1 + substr_count(substr($this->rawtext, 0, $this->position), "\n");
+  }
+
+  function getCurrentLocation()
+  {
+    return new lmbMacroSourceLocation($this->getPublicId(), $this->getLineNumber());
+  }
+
+  function getPublicId()
+  {
+    return $this->publicId;
+  }
+
+  /**
+  * Moves the position forward past any whitespace characters
+  */
+  function ignoreWhitespace()
+  {
+    while($this->position < $this->length &&
+        strpos(" \n\r\t", $this->rawtext{$this->position}) !== false)
+      $this->position++;
+  }
+
+  /**
+  * Begins the parsing operation, setting up any decorators, depending on
+  * parse options invoking _parse() to execute parsing
+  */
+  function parse($data, $publicId = null)
+  {
+    $this->rawtext = $data;
+    $this->length = strlen($data);
+    $this->position = 0;
+    $this->publicId = $publicId;
+
+    do
+    {
+      $start = $this->position;
+      $this->position = strpos($this->rawtext, '<%', $start);
+      if($this->position === false)
+      {
+        if($start < $this->length)
+          $this->observer->characters(substr($this->rawtext, $start));
+        return;
+      }
+
+      if($this->position > $start)
+      {
+        $this->observer->characters(substr($this->rawtext, $start, $this->position - $start));
+      }
+
+      $this->position += 2;   // ignore '<%' string
+      if($this->position >= $this->length)
+      {
+        $this->observer->unexpectedEOF('<%');
+        return;
+      }
+
+      $element_pos = $this->position;
+      $this->position += 1;
+
+      switch($this->rawtext{$element_pos})
+      {
+        case '/':
+          $start = $this->position;
+          while($this->position < $this->length &&
+                $this->rawtext{$this->position} != '%' &&
+                $this->rawtext{$this->position+1} != '>')
+            $this->position++;
+
+          if($this->position >= $this->length)
+          {
+            $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+            return;
+          }
+
+          $tag = substr($this->rawtext, $start, $this->position - $start);
+
+          $this->observer->endElement($tag);
+          $this->position += 2;   // ignore '%>' string
+          break;
+
+      default:
+          while($this->position < $this->length && strpos("%/ \n\r\t", $this->rawtext{$this->position}) === false)
+            $this->position++;
+
+          if($this->position >= $this->length)
+          {
+            $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+            return;
+          }
+
+          $tag = substr($this->rawtext, $element_pos, $this->position - $element_pos);
+          $attributes = array();
+
+          $this->ignoreWhitespace();
+
+          //tag attributes
+          while($this->position < $this->length &&
+                $this->rawtext{$this->position} != '%' &&
+                $this->rawtext{$this->position} != '/')
+          {
+            $start = $this->position;
+            while($this->position < $this->length && strpos("%= \n\r\t", $this->rawtext{$this->position}) === false)
+              $this->position++;
+
+            if($this->position >= $this->length)
+            {
+              $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+              return;
+            }
+
+            $attribute_name = substr($this->rawtext, $start, $this->position - $start);
+            $attribute_value = null;
+
+            $this->ignoreWhitespace();
+            if($this->position >= $this->length)
+            {
+              $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+              return;
+            }
+
+            if($this->rawtext{$this->position} == '=')
+            {
+              $attribute_value = "";
+
+              $this->position++;
+              $this->ignoreWhitespace();
+              if($this->position >= $this->length)
+              {
+                $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+                return;
+              }
+
+              $quote = $this->rawtext{$this->position};
+              if($quote == '"' || $quote == "'")
+              {
+                $start = $this->position + 1;
+                $this->position = strpos($this->rawtext, $quote, $start);
+                if($this->position === false)
+                {
+                  $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+                  return;
+                }
+
+                $attribute_value = substr($this->rawtext, $start, $this->position - $start);
+
+                $this->position++;
+                if($this->position >= $this->length)
+                {
+                  $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+                  return;
+                }
+
+                if(strpos("% \n\r\t", $this->rawtext{$this->position}) === false)
+                  $this->observer->invalidAttributeSyntax();
+
+              }
+              else
+              {
+                $start = $this->position;
+                while($this->position < $this->length && strpos("% \n\r\t", $this->rawtext{$this->position}) === false)
+                  $this->position++;
+
+                if($this->position >= $this->length)
+                {
+                  $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+                  return;
+                }
+                $attribute_value = substr($this->rawtext, $start, $this->position - $start);
+              }
+            }
+
+            $attributes[$attribute_name] = $attribute_value;
+
+            $this->ignoreWhitespace();
+          }
+
+          if($this->position >= $this->length)
+          {
+            $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+            return;
+          }
+
+          //self closing tag check
+          if($this->rawtext{$this->position} == '/' && $this->rawtext{$this->position + 1} == '%')
+          {
+            $this->position += 2;
+            if($this->position >= $this->length)
+            {
+              $this->observer->unexpectedEOF(substr($this->rawtext, $element_pos - 1));
+              return;
+            }
+
+            if($this->rawtext{$this->position} != '>')
+            {
+              $start = $this->position;
+              while($this->position < $this->length && $this->rawtext{$this->position} != '>')
+                $this->position++;
+
+              if($this->position >= $this->length)
+              {
+                $this->observer->invalidEntitySyntax(substr($this->rawtext, $element_pos - 2));
+                break;
+              }
+
+              $this->observer->invalidEntitySyntax(substr($this->rawtext, $element_pos - 2,
+                                                          $this->position - $element_pos + 2));
+              $this->position += 1;
+              break;
+            }
+            $this->observer->emptyElement($tag, $attributes);
+          }
+          else
+          {
+            $this->observer->startElement($tag, $attributes);
+            //skipping %
+            $this->position += 1;
+          }
+
+          $this->position += 1;
+
+          break;
+        }
+    }
+    while ($this->position < $this->length);
+  }
+}
+?>

Copied: 3.x/trunk/limb/macro/src/lmbMacroTokenizerListener.interface.php (from rev 5796, 3.x/trunk/limb/macro/src/lmbMacroParserListener.interface.php)
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTokenizerListener.interface.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/lmbMacroTokenizerListener.interface.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id: WactParserListener.interface.php 5553 2007-04-06 09:05:17Z serega $
+ * @package    view
+ */
+
+interface lmbMacroTokenizerListener
+{
+  function startElement($tag_name, $attrs);
+  function endElement($tag_name);
+  function emptyElement($tag_name, $attrs);
+  function characters($data);
+  function unexpectedEOF($data);
+  function invalidEntitySyntax($data);
+  function invalidAttributeSyntax();
+  function setDocumentLocator($locator);
+}
+?>
\ No newline at end of file

Deleted: 3.x/trunk/limb/macro/tests/cases/lmbMacroParserMalformedTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroParserMalformedTest.class.php	2007-05-04 14:07:37 UTC (rev 5807)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroParserMalformedTest.class.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -1,73 +0,0 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    view
- */
-
-lmb_require('limb/macro/src/lmbMacroParserListener.interface.php');
-lmb_require('limb/macro/src/lmbMacroParser.class.php');
-
-Mock::generate('lmbMacroParserListener', 'MockMacroParserListener');
-
-class lmbMacroParserMalformedTest extends UnitTestCase
-{
-  protected $parser;
-  protected $listener;
-
-  function setUp()
-  {
-    $this->listener = new MockMacroParserListener();
-    $this->parser = new lmbMacroParser($this->listener);
-  }
-
-  function testOpenElementMalformedClose()
-  {
-    $this->listener->expectOnce('characters', array('stuff'));
-    $this->listener->expectOnce('invalidEntitySyntax', array('<%tag attribute=\'value\'/%morestuff'));
-    $this->listener->expectNever('startElement');
-    $this->parser->parse('stuff<%tag attribute=\'value\'/%morestuff');
-  }
-
-  /*function testOpenElementMalformedClose2()
-  {
-    $this->listener->expectOnce('characters', array('stuff'));
-    $this->listener->expectOnce('invalidEntitySyntax', array('<tag attribute=\'value\'/morestuff>'));
-    $this->listener->expectNever('startElement');
-    $this->parser->parse('stuff<tag attribute=\'value\'/morestuff>');
-  }
-
-  function testElementNestedSingleQuote()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '', "'" => NULL)));
-    $this->listener->expectOnce('invalidAttributeSyntax');
-    $this->listener->expectNever('characters');
-    $this->listener->expectNever('endElement');
-    $this->parser->parse('<tag attribute=\'\'\'>');
-  }
-
-  function testElementNestedDoubleQuote()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '', '"' => NULL)));
-    $this->listener->expectOnce('invalidAttributeSyntax');
-    $this->listener->expectNever('characters');
-    $this->listener->expectNever('endElement');
-    $this->parser->parse('<tag attribute=""">');
-  }
-
-  function testElementMalformedAttribute()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array('attribute' => 'test', 'extra' => NULL)));
-    $this->listener->expectOnce('invalidAttributeSyntax');
-    $this->listener->expectNever('characters');
-    $this->listener->expectNever('endElement');
-    $this->parser->parse('<tag attribute="test"extra>');
-  }*/
-}
-
-?>
\ No newline at end of file

Deleted: 3.x/trunk/limb/macro/tests/cases/lmbMacroParserTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroParserTest.class.php	2007-05-04 14:07:37 UTC (rev 5807)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroParserTest.class.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -1,172 +0,0 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    view
- */
-
-lmb_require('limb/macro/src/lmbMacroParserListener.interface.php');
-lmb_require('limb/macro/src/lmbMacroParser.class.php');
-
-Mock::generate('lmbMacroParserListener', 'MockMacroParserListener');
-
-class lmbMacroParserTest extends UnitTestCase
-{
-  protected $parser;
-  protected $listener;
-
-  function setUp()
-  {
-    $this->listener = new MockMacroParserListener();
-    $this->parser = new lmbMacroParser($this->listener);
-  }
-
-  function testEmpty()
-  {
-    $this->listener->expectNever('characters');
-    $this->listener->expectNever('startElement');
-    $this->listener->expectNever('endElement');
-    $this->parser->parse('');
-  }
-
-  function testSimpledata()
-  {
-    $this->listener->expectOnce('characters', array('stuff'));
-    $this->parser->parse('stuff');
-  }
-
-  function testPreservingWhiteSpace()
-  {
-    $this->listener->expectOnce('characters', array(" stuff\t\r\n "));
-    $this->parser->parse(" stuff\t\r\n ");
-  }
-
-  function testEmptyElement()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array()));
-    $this->listener->expectOnce('endElement', array('tag'));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%tag%><%/tag%>');
-  }
-
-  function testEmptyElementSelfClose()
-  {
-    $this->listener->expectOnce('emptyElement', array('tag', array()));
-    $this->listener->expectNever('startElement');
-    $this->listener->expectNever('endElement');
-    $this->parser->parse('<%tag/%>');
-  }
-
-  function testElementWithContent()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array()));
-    $this->listener->expectOnce('characters', array('stuff'));
-    $this->listener->expectOnce('endElement', array('tag'));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%tag%>stuff<%/tag%>');
-  }
-
-  function testElementNestedSingleQuote()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '\'')));
-    $this->listener->expectNever('characters');
-    $this->listener->expectNever('endElement');
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%tag attribute="\'"%>');
-  }
-
-  function testElementNestedDoubleQuote()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '"')));
-    $this->listener->expectNever('characters');
-    $this->listener->expectNever('endElement');
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%tag attribute=\'"\'%>');
-  }
-
-
-  function testEmptyClose()
-  {
-    $this->listener->expectOnce('endElement', array(''));
-    $this->listener->expectNever('characters');
-    $this->parser->parse('<%/%>');
-  }
-
-  function testElementWithPreContent()
-  {
-    $this->listener->expectOnce('characters', array('stuff'));
-    $this->listener->expectOnce('startElement', array('br', array()));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('stuff<%br%>');
-  }
-
-  function testElementWithPostContent()
-  {
-    $this->listener->expectOnce('startElement', array('br', array()));
-    $this->listener->expectOnce('characters', array('stuff'));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%br%>stuff');
-  }
-
-  function testExpressionAfterTag()
-  {
-    $this->listener->expectOnce('emptyElement', array('br', array()));
-    $this->listener->expectOnce('characters', array('{$str}'));
-    $this->parser->parse('<%br/%>{$str}');
-  }
-
-  function testExpressionAfterTagWithArguments()
-  {
-    $this->listener->expectOnce('emptyElement', array('tag', array('str' => 'abcdefgh')));
-    $this->listener->expectOnce('characters', array('{$str}'));
-    $this->parser->parse('<%tag str="abcdefgh" /%>{$str}');
-  }
-
-  function testMismatchedElements()
-  {
-    $this->listener->expectArgumentsAt(0, 'startElement', array('b', array()));
-    $this->listener->expectArgumentsAt(1, 'startElement', array('i', array()));
-    $this->listener->expectArgumentsAt(0, 'endElement', array('b'));
-    $this->listener->expectArgumentsAt(1, 'endElement', array('i'));
-    $this->listener->expectCallCount('startElement', 2);
-    $this->listener->expectCallCount('endElement', 2);
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%b%><%i%>stuff<%/b%><%/i%>');
-  }
-
-  function testAttributes()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array("a" => "A", "b" => "B", "c" => "C")));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%tag a="A" b=\'B\' c = "C"%>');
-  }
-
-  function testEmptyAttributes()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array("a" => NULL, "b" => NULL, "c" => NULL)));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse('<%tag a b c%>');
-  }
-
-  function testNastyAttributes()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array("a" => "&%$'?<>",
-                                                                   "b" => "\r\n\t\"",
-                                                                   "c" => "")));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse("<%tag a=\"&%$'?<>\" b='\r\n\t\"' c = ''%>");
-  }
-
-  function testAttributesPadding()
-  {
-    $this->listener->expectOnce('startElement', array('tag', array("a" => "A", "b" => "B", "c" => "C")));
-    $this->listener->expectNever('invalidAttributeSyntax');
-    $this->parser->parse("<%tag\ta=\"A\"\rb='B'\nc = \"C\"\n%>");
-  }
-}
-?>
\ No newline at end of file

Copied: 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerMalformedTest.class.php (from rev 5796, 3.x/trunk/limb/macro/tests/cases/lmbMacroParserMalformedTest.class.php)
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerMalformedTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerMalformedTest.class.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    view
+ */
+
+lmb_require('limb/macro/src/lmbMacroTokenizerListener.interface.php');
+lmb_require('limb/macro/src/lmbMacroTokenizer.class.php');
+
+Mock::generate('lmbMacroTokenizerListener', 'MockMacroTokenizerListener');
+
+class lmbMacroTokenizerMalformedTest extends UnitTestCase
+{
+  protected $parser;
+  protected $listener;
+
+  function setUp()
+  {
+    $this->listener = new MockMacroTokenizerListener();
+    $this->parser = new lmbMacroTokenizer($this->listener);
+  }
+
+  function testOpenElementMalformedClose()
+  {
+    $this->listener->expectOnce('characters', array('stuff'));
+    $this->listener->expectOnce('invalidEntitySyntax', array('<%tag attribute=\'value\'/%morestuff'));
+    $this->listener->expectNever('startElement');
+    $this->parser->parse('stuff<%tag attribute=\'value\'/%morestuff');
+  }
+
+  /*function testOpenElementMalformedClose2()
+  {
+    $this->listener->expectOnce('characters', array('stuff'));
+    $this->listener->expectOnce('invalidEntitySyntax', array('<tag attribute=\'value\'/morestuff>'));
+    $this->listener->expectNever('startElement');
+    $this->parser->parse('stuff<tag attribute=\'value\'/morestuff>');
+  }
+
+  function testElementNestedSingleQuote()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '', "'" => NULL)));
+    $this->listener->expectOnce('invalidAttributeSyntax');
+    $this->listener->expectNever('characters');
+    $this->listener->expectNever('endElement');
+    $this->parser->parse('<tag attribute=\'\'\'>');
+  }
+
+  function testElementNestedDoubleQuote()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '', '"' => NULL)));
+    $this->listener->expectOnce('invalidAttributeSyntax');
+    $this->listener->expectNever('characters');
+    $this->listener->expectNever('endElement');
+    $this->parser->parse('<tag attribute=""">');
+  }
+
+  function testElementMalformedAttribute()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array('attribute' => 'test', 'extra' => NULL)));
+    $this->listener->expectOnce('invalidAttributeSyntax');
+    $this->listener->expectNever('characters');
+    $this->listener->expectNever('endElement');
+    $this->parser->parse('<tag attribute="test"extra>');
+  }*/
+}
+
+?>
\ No newline at end of file

Copied: 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php (from rev 5796, 3.x/trunk/limb/macro/tests/cases/lmbMacroParserTest.class.php)
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php	2007-05-04 21:32:57 UTC (rev 5808)
@@ -0,0 +1,172 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    view
+ */
+
+lmb_require('limb/macro/src/lmbMacroTokenizerListener.interface.php');
+lmb_require('limb/macro/src/lmbMacroTokenizer.class.php');
+
+Mock::generate('lmbMacroTokenizerListener', 'MockMacroTokenizerListener');
+
+class lmbMacroTokenizerTest extends UnitTestCase
+{
+  protected $parser;
+  protected $listener;
+
+  function setUp()
+  {
+    $this->listener = new MockMacroTokenizerListener();
+    $this->parser = new lmbMacroTokenizer($this->listener);
+  }
+
+  function testEmpty()
+  {
+    $this->listener->expectNever('characters');
+    $this->listener->expectNever('startElement');
+    $this->listener->expectNever('endElement');
+    $this->parser->parse('');
+  }
+
+  function testSimpledata()
+  {
+    $this->listener->expectOnce('characters', array('stuff'));
+    $this->parser->parse('stuff');
+  }
+
+  function testPreservingWhiteSpace()
+  {
+    $this->listener->expectOnce('characters', array(" stuff\t\r\n "));
+    $this->parser->parse(" stuff\t\r\n ");
+  }
+
+  function testEmptyElement()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array()));
+    $this->listener->expectOnce('endElement', array('tag'));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%tag%><%/tag%>');
+  }
+
+  function testEmptyElementSelfClose()
+  {
+    $this->listener->expectOnce('emptyElement', array('tag', array()));
+    $this->listener->expectNever('startElement');
+    $this->listener->expectNever('endElement');
+    $this->parser->parse('<%tag/%>');
+  }
+
+  function testElementWithContent()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array()));
+    $this->listener->expectOnce('characters', array('stuff'));
+    $this->listener->expectOnce('endElement', array('tag'));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%tag%>stuff<%/tag%>');
+  }
+
+  function testElementNestedSingleQuote()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '\'')));
+    $this->listener->expectNever('characters');
+    $this->listener->expectNever('endElement');
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%tag attribute="\'"%>');
+  }
+
+  function testElementNestedDoubleQuote()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array('attribute' => '"')));
+    $this->listener->expectNever('characters');
+    $this->listener->expectNever('endElement');
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%tag attribute=\'"\'%>');
+  }
+
+
+  function testEmptyClose()
+  {
+    $this->listener->expectOnce('endElement', array(''));
+    $this->listener->expectNever('characters');
+    $this->parser->parse('<%/%>');
+  }
+
+  function testElementWithPreContent()
+  {
+    $this->listener->expectOnce('characters', array('stuff'));
+    $this->listener->expectOnce('startElement', array('br', array()));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('stuff<%br%>');
+  }
+
+  function testElementWithPostContent()
+  {
+    $this->listener->expectOnce('startElement', array('br', array()));
+    $this->listener->expectOnce('characters', array('stuff'));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%br%>stuff');
+  }
+
+  function testExpressionAfterTag()
+  {
+    $this->listener->expectOnce('emptyElement', array('br', array()));
+    $this->listener->expectOnce('characters', array('{$str}'));
+    $this->parser->parse('<%br/%>{$str}');
+  }
+
+  function testExpressionAfterTagWithArguments()
+  {
+    $this->listener->expectOnce('emptyElement', array('tag', array('str' => 'abcdefgh')));
+    $this->listener->expectOnce('characters', array('{$str}'));
+    $this->parser->parse('<%tag str="abcdefgh" /%>{$str}');
+  }
+
+  function testMismatchedElements()
+  {
+    $this->listener->expectArgumentsAt(0, 'startElement', array('b', array()));
+    $this->listener->expectArgumentsAt(1, 'startElement', array('i', array()));
+    $this->listener->expectArgumentsAt(0, 'endElement', array('b'));
+    $this->listener->expectArgumentsAt(1, 'endElement', array('i'));
+    $this->listener->expectCallCount('startElement', 2);
+    $this->listener->expectCallCount('endElement', 2);
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%b%><%i%>stuff<%/b%><%/i%>');
+  }
+
+  function testAttributes()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array("a" => "A", "b" => "B", "c" => "C")));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%tag a="A" b=\'B\' c = "C"%>');
+  }
+
+  function testEmptyAttributes()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array("a" => NULL, "b" => NULL, "c" => NULL)));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse('<%tag a b c%>');
+  }
+
+  function testNastyAttributes()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array("a" => "&%$'?<>",
+                                                                   "b" => "\r\n\t\"",
+                                                                   "c" => "")));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse("<%tag a=\"&%$'?<>\" b='\r\n\t\"' c = ''%>");
+  }
+
+  function testAttributesPadding()
+  {
+    $this->listener->expectOnce('startElement', array('tag', array("a" => "A", "b" => "B", "c" => "C")));
+    $this->listener->expectNever('invalidAttributeSyntax');
+    $this->parser->parse("<%tag\ta=\"A\"\rb='B'\nc = \"C\"\n%>");
+  }
+}
+?>
\ No newline at end of file



More information about the limb-svn mailing list