cvs: pear /URI_Template Template.php makepackage.php package.xml /URI_Template/tests/URI/Template TemplateTest.php
| From: | Martin Jansen | Date: | Sat, 05 Apr 2008 15:00:11 +0000 |
| Subject: | cvs: pear /URI_Template Template.php makepackage.php package.xml /URI_Template/tests/URI/Template TemplateTest.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-51803@lists.php.net to get a copy of this message | ||
mj Sat Apr 5 15:00:11 2008 UTC
Modified files:
/pear/URI_Template Template.php makepackage.php package.xml
/pear/URI_Template/tests/URI/Template TemplateTest.php
Log:
* Added support for the 03 Draft released yesterday.
http://cvs.php.net/viewvc.cgi/pear/URI_Template/Template.php?r1=1.1&r2=1.2&diff_format=u Index: pear/URI_Template/Template.php diff -u pear/URI_Template/Template.php:1.1 pear/URI_Template/Template.php:1.2 --- pear/URI_Template/Template.php:1.1 Sun Mar 9 10:59:12 2008 +++ pear/URI_Template/Template.php Sat Apr 5 15:00:11 2008 @@ -117,6 +117,7 @@ * * Adds the value of the second parameter to the beginning of the first * element from the first parameter and returns the resulting string. + * The value of the second parameter may be an array. * * @param array List of variables. Only the first element is used. * @param string Prefix string @@ -125,22 +126,37 @@ private function operationPrefix($variables, $arg) { $tmp = current($variables); + if (is_array($tmp)) { + if (count($tmp) > 0) { + $tmp = join($arg, $tmp); + } else { + $tmp = ''; + } + } return (empty($tmp) ? '' : $arg . $tmp); } /** - * Implements the 'append' operator + * Implements the 'suffix' operator * * Appends the value of the second parameter to the first element of the - * first parameter and returns the resulting string. + * first parameter and returns the resulting string. The value of the + * second parameter may be an array. * * @param array List of variables. Only the first element is used. * @param string String to append to the first element of $variables * @return string */ - private function operationAppend($variables, $arg) + private function operationSuffix($variables, $arg) { $tmp = current($variables); + if (is_array($tmp)) { + if (count($tmp) > 0) { + $tmp = join($arg, $tmp); + } else { + $tmp = ''; + } + } return (empty($tmp) ? '' : $tmp . $arg); } @@ -172,7 +188,7 @@ } /** - * Implements the 'listjoin' operator + * Implements the 'list' operator * * Joins the elements of the first element of the first parameter with the * value of the second parameter. @@ -182,7 +198,7 @@ * @param string Join needle * @return string */ - private function operationListjoin($variables, $arg) + private function operationList($variables, $arg) { $tmp = current($variables); return (is_array($tmp) ? join($arg, $tmp) : ''); http://cvs.php.net/viewvc.cgi/pear/URI_Template/makepackage.php?r1=1.4&r2=1.5&diff_format=u Index: pear/URI_Template/makepackage.php diff -u pear/URI_Template/makepackage.php:1.4 pear/URI_Template/makepackage.php:1.5 --- pear/URI_Template/makepackage.php:1.4 Sun Mar 9 12:33:38 2008 +++ pear/URI_Template/makepackage.php Sat Apr 5 15:00:11 2008 @@ -46,11 +46,11 @@ $p2->setChannel("pear.php.net"); $p2->setSummary("Parser for URI Templates."); $p2->setDescription("URI_Template is a parser for URI Templates as defined in the URI Template specification (http://bitworking.org/projects/URI-Templates)."); -$p2->setReleaseVersion("0.1.0"); +$p2->setReleaseVersion("0.2.0"); $p2->setReleaseStability("alpha"); -$p2->setAPIVersion("0.1.0"); +$p2->setAPIVersion("0.2.0"); $p2->setAPIStability("alpha"); -$p2->setNotes("Initial release"); +$p2->setNotes("Added support for the 03 draft of the URI Template specification."); $p2->setLicense("BSD License", "http://www.opensource.org/licenses/bsd-license.php"); $p2->setPhpDep("5.2.0"); http://cvs.php.net/viewvc.cgi/pear/URI_Template/package.xml?r1=1.3&r2=1.4&diff_format=u Index: pear/URI_Template/package.xml diff -u pear/URI_Template/package.xml:1.3 pear/URI_Template/package.xml:1.4 --- pear/URI_Template/package.xml:1.3 Sun Mar 9 12:33:38 2008 +++ pear/URI_Template/package.xml Sat Apr 5 15:00:11 2008 @@ -13,18 +13,18 @@ <email>mj@php.net</email> <active>yes</active> </lead> - <date>2008-03-09</date> - <time>13:33:09</time> + <date>2008-04-05</date> + <time>16:59:09</time> <version> - <release>0.1.0</release> - <api>0.1.0</api> + <release>0.2.0</release> + <api>0.2.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license> - <notes>Initial release</notes> + <notes>Added support for the 03 draft of the URI Template specification.</notes> <contents> <dir baseinstalldir="URI" name="/"> <dir name="tests"> @@ -76,5 +76,18 @@ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license> <notes>Initial release</notes> </release> + <release> + <version> + <release>0.2.0</release> + <api>0.2.0</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2008-04-05</date> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license> + <notes>Added support for the 03 draft of the URI Template specification.</notes> + </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pear/URI_Template/tests/URI/Template/TemplateTest.php?r1=1.1&r2=1.2&diff_format=u Index: pear/URI_Template/tests/URI/Template/TemplateTest.php diff -u pear/URI_Template/tests/URI/Template/TemplateTest.php:1.1 pear/URI_Template/tests/URI/Template/TemplateTest.php:1.2 --- pear/URI_Template/tests/URI/Template/TemplateTest.php:1.1 Sun Mar 9 10:59:12 2008 +++ pear/URI_Template/tests/URI/Template/TemplateTest.php Sat Apr 5 15:00:11 2008 @@ -77,23 +77,24 @@ self::runnerHelper($tests); } - public function testAppend() { + public function testSuffix() { $tests = array( - array("-append|/|foo", array(), ""), - array("-append|#|foo=wilma", array(), "wilma#"), - array("-append|&?|foo=wilma", array("foo" => "barney"), "barney&?"), + array("-suffix|/|foo", array(), ""), + array("-suffix|#|foo=wilma", array(), "wilma#"), + array("-suffix|&?|foo=wilma", array("foo" => "barney"), "barney&?"), + array("-suffix|&|foo", array("foo" => array("wilma", "barney")), "wilma&barney&") ); self::runnerHelper($tests); } - public function testListjoin() { + public function testList() { $tests = array( - array("-listjoin|/|foo", array(), ""), - array("-listjoin|/|foo", array("foo" => array("a", "b")), "a/b"), - array("-listjoin||foo", array("foo" => array("a", "b")), "ab"), - array("-listjoin|/|foo", array("foo" => array("a")), "a"), - array("-listjoin|/|foo", array("foo" => array()), ""), + array("-list|/|foo", array(), ""), + array("-list|/|foo", array("foo" => array("a", "b")), "a/b"), + array("-list||foo", array("foo" => array("a", "b")), "ab"), + array("-list|/|foo", array("foo" => array("a")), "a"), + array("-list|/|foo", array("foo" => array()), ""), ); self::runnerHelper($tests); @@ -119,6 +120,7 @@ array("-prefix|&|foo=wilma", array(), "&wilma"), array("-prefix||foo=wilma", array(), "wilma"), array("-prefix|&|foo=wilma", array("foo" => "barney"), "&barney"), + array("-prefix|&|foo", array("foo" => array("wilma", "barney")), "&wilma&barney") ); self::runnerHelper($tests); @@ -154,7 +156,7 @@ public function testSpecials() { $tests = array( array("foo", array("foo" => " "), "%20"), - array("-listjoin|&|foo", array("foo" => array("&", "&", "|", "_")), "%26&%26&%7C&_"), + array("-list|&|foo", array("foo" => array("&", "&", "|", "_")), "%26&%26&%7C&_"), ); self::runnerHelper($tests); @@ -164,44 +166,58 @@ $t = new URI_Template("http://example.org/news/{id}/"); self::assertEquals("http://example.org/news/joe/", $t->substitute(array("id" => "joe"))); - $t = new URI_Template("http://www.google.com/notebook/feeds/{userID}{-prefix|/notebooks/|notebookID}{-opt|/-/|categories}{-listjoin|/|categories}?{-join|&|updated-min,updated-max,alt,start-index,max-results,entryID,orderby}"); + $t = new URI_Template("http://www.google.com/notebook/feeds/{userID}{-prefix|/notebooks/|notebookID}{-opt|/-/|categories}{-list|/|categories}?{-join|&|updated-min,updated-max,alt,start-index,max-results,entryID,orderby}"); self::assertEquals("http://www.google.com/notebook/feeds/joe?", $t->substitute(array("userID" => "joe"))); self::assertEquals("http://www.google.com/notebook/feeds/joe/-/A%7C-B/-C?start-index=10", - $t->substitute(array("userID" => "joe", "categories" => array("A|-B", "-C"), "start-index" => "10"))); + $t->substitute(array("userID" => "joe", "categories" => array("A|-B", "-C"), "start-index" => "10"))); - /* Source: From the IETF Draft */ + /* Source: IETF Draft 03 */ + $values = array("bar" => "fred", "baz" => "10,20,30", "qux" => array(10, 20, 30), + "corge" => array(), "grault" => " ", "garply" => "a/b/c", + "waldo" => "ben & jerrys", "fred" => array("fred", "", "wilma"), + "1-a_b.c" => 200); + + $tests = array( + "http://example.org/?q={bar}" => "http://example.org/?q=fred", + "/{xyzzy}" => "/", + "http://example.org/?{-join|&|bar,xyzzy,baz}" => "http://example.org/?bar=fred&baz=10%2C20%2C30", + "http://example.org/?d={-list|,|qux}" => "http://example.org/?d=10,20,30", + "http://example.org/?d={-list|&d=|qux}" => "http://example.org/?d=10&d=20&d=30", + "http://example.org/{bar}{bar}/{garply}" => "http://example.org/fredfred/a%2Fb%2Fc", + "http://example.org/{bar}{-prefix|/|fred}" => "http://example.org/fred/fred//wilma", + "../{waldo}/" => "../ben%20%26%20jerrys/", + "telnet:192.0.2.16{-opt|:80|grault}" => "telnet:192.0.2.16:80", + ":{1-a_b.c}:" => ":200:", + ); + + foreach ($tests as $key => $value) { + $t = new URI_Template($key); + self::assertEquals($value, $t->substitute($values)); + } + + /* Source: IETF Draft 02 */ $values = array("a" => "foo", "b" => "bar", "data" => "10,20,30", "points" => array(10, 20, 30), "list0" => array(), "str0" => "", "reserved" => ":/?#[]@!$&'()*+,;=", "a_b" => "baz"); - $t = new URI_Template("/{-append|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}"); - self::assertEquals("/foo/data#bar", $t->substitute($values)); - - $t = new URI_Template("relative/{reserved}/"); - self::assertEquals("relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/", $t->substitute($values)); - - $t = new URI_Template("http://example.org/{foo=%25}/"); - self::assertEquals("http://example.org/%25/", $t->substitute($values)); - - $t = new URI_Template("http://example.org/?{-join|&|a,data}"); - self::assertEquals("http://example.org/?a=foo&data=10%2C20%2C30", $t->substitute($values)); - - $t = new URI_Template("http://example.org/?d={-listjoin|,|points}&{-join|&|a,b}"); - self::assertEquals("http://example.org/?d=10,20,30&a=foo&b=bar", $t->substitute($values)); - - $t = new URI_Template("http://example.org/?d={-listjoin|,|list0}&{-join|&|foo}"); - self::assertEquals("http://example.org/?d=&", $t->substitute(array())); - - $t = new URI_Template("http://example.org/?d={-listjoin|&d=|points}"); - self::assertEquals("http://example.org/?d=10&d=20&d=30", $t->substitute($values)); - - $t = new URI_Template("http://example.org/{a}{b}/{a_b}"); - self::assertEquals("http://example.org/foobar/baz", $t->substitute($values)); - - $t = new URI_Template("http://example.org/{a}{-prefix|/-/|a}/"); - self::assertEquals("http://example.org/foo/-/foo/", $t->substitute($values)); + $tests = array( + "/{-suffix|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}" => "/foo/data#bar", + "relative/{reserved}/" => "relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/", + "http://example.org/{foo=%25}/" => "http://example.org/%25/", + "http://example.org/?{-join|&|a,data}" => "http://example.org/?a=foo&data=10%2C20%2C30", + "http://example.org/?d={-list|,|points}&{-join|&|a,b}" => "http://example.org/?d=10,20,30&a=foo&b=bar", + "http://example.org/?d={-list|,|list0}&{-join|&|foo}" => "http://example.org/?d=&", + "http://example.org/?d={-list|&d=|points}" => "http://example.org/?d=10&d=20&d=30", + "http://example.org/{a}{b}/{a_b}" => "http://example.org/foobar/baz", + "http://example.org/{a}{-prefix|/-/|a}/" => "http://example.org/foo/-/foo/", + ); + + foreach ($tests as $key => $value) { + $t = new URI_Template($key); + self::assertEquals($value, $t->substitute($values)); + } } private static function runnerHelper($tests) {
http://cvs.php.net/viewvc.cgi/pear/URI_Template/Template.php?r1=1.1&r2=1.2&diff_format=u Index: pear/URI_Template/Template.php diff -u pear/URI_Template/Template.php:1.1 pear/URI_Template/Template.php:1.2 --- pear/URI_Template/Template.php:1.1 Sun Mar 9 10:59:12 2008 +++ pear/URI_Template/Template.php Sat Apr 5 15:00:11 2008 @@ -117,6 +117,7 @@ * * Adds the value of the second parameter to the beginning of the first * element from the first parameter and returns the resulting string. + * The value of the second parameter may be an array. * * @param array List of variables. Only the first element is used. * @param string Prefix string @@ -125,22 +126,37 @@ private function operationPrefix($variables, $arg) { $tmp = current($variables); + if (is_array($tmp)) { + if (count($tmp) > 0) { + $tmp = join($arg, $tmp); + } else { + $tmp = ''; + } + } return (empty($tmp) ? '' : $arg . $tmp); } /** - * Implements the 'append' operator + * Implements the 'suffix' operator * * Appends the value of the second parameter to the first element of the - * first parameter and returns the resulting string. + * first parameter and returns the resulting string. The value of the + * second parameter may be an array. * * @param array List of variables. Only the first element is used. * @param string String to append to the first element of $variables * @return string */ - private function operationAppend($variables, $arg) + private function operationSuffix($variables, $arg) { $tmp = current($variables); + if (is_array($tmp)) { + if (count($tmp) > 0) { + $tmp = join($arg, $tmp); + } else { + $tmp = ''; + } + } return (empty($tmp) ? '' : $tmp . $arg); } @@ -172,7 +188,7 @@ } /** - * Implements the 'listjoin' operator + * Implements the 'list' operator * * Joins the elements of the first element of the first parameter with the * value of the second parameter. @@ -182,7 +198,7 @@ * @param string Join needle * @return string */ - private function operationListjoin($variables, $arg) + private function operationList($variables, $arg) { $tmp = current($variables); return (is_array($tmp) ? join($arg, $tmp) : ''); http://cvs.php.net/viewvc.cgi/pear/URI_Template/makepackage.php?r1=1.4&r2=1.5&diff_format=u Index: pear/URI_Template/makepackage.php diff -u pear/URI_Template/makepackage.php:1.4 pear/URI_Template/makepackage.php:1.5 --- pear/URI_Template/makepackage.php:1.4 Sun Mar 9 12:33:38 2008 +++ pear/URI_Template/makepackage.php Sat Apr 5 15:00:11 2008 @@ -46,11 +46,11 @@ $p2->setChannel("pear.php.net"); $p2->setSummary("Parser for URI Templates."); $p2->setDescription("URI_Template is a parser for URI Templates as defined in the URI Template specification (http://bitworking.org/projects/URI-Templates)."); -$p2->setReleaseVersion("0.1.0"); +$p2->setReleaseVersion("0.2.0"); $p2->setReleaseStability("alpha"); -$p2->setAPIVersion("0.1.0"); +$p2->setAPIVersion("0.2.0"); $p2->setAPIStability("alpha"); -$p2->setNotes("Initial release"); +$p2->setNotes("Added support for the 03 draft of the URI Template specification."); $p2->setLicense("BSD License", "http://www.opensource.org/licenses/bsd-license.php"); $p2->setPhpDep("5.2.0"); http://cvs.php.net/viewvc.cgi/pear/URI_Template/package.xml?r1=1.3&r2=1.4&diff_format=u Index: pear/URI_Template/package.xml diff -u pear/URI_Template/package.xml:1.3 pear/URI_Template/package.xml:1.4 --- pear/URI_Template/package.xml:1.3 Sun Mar 9 12:33:38 2008 +++ pear/URI_Template/package.xml Sat Apr 5 15:00:11 2008 @@ -13,18 +13,18 @@ <email>mj@php.net</email> <active>yes</active> </lead> - <date>2008-03-09</date> - <time>13:33:09</time> + <date>2008-04-05</date> + <time>16:59:09</time> <version> - <release>0.1.0</release> - <api>0.1.0</api> + <release>0.2.0</release> + <api>0.2.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license> - <notes>Initial release</notes> + <notes>Added support for the 03 draft of the URI Template specification.</notes> <contents> <dir baseinstalldir="URI" name="/"> <dir name="tests"> @@ -76,5 +76,18 @@ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license> <notes>Initial release</notes> </release> + <release> + <version> + <release>0.2.0</release> + <api>0.2.0</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2008-04-05</date> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license> + <notes>Added support for the 03 draft of the URI Template specification.</notes> + </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pear/URI_Template/tests/URI/Template/TemplateTest.php?r1=1.1&r2=1.2&diff_format=u Index: pear/URI_Template/tests/URI/Template/TemplateTest.php diff -u pear/URI_Template/tests/URI/Template/TemplateTest.php:1.1 pear/URI_Template/tests/URI/Template/TemplateTest.php:1.2 --- pear/URI_Template/tests/URI/Template/TemplateTest.php:1.1 Sun Mar 9 10:59:12 2008 +++ pear/URI_Template/tests/URI/Template/TemplateTest.php Sat Apr 5 15:00:11 2008 @@ -77,23 +77,24 @@ self::runnerHelper($tests); } - public function testAppend() { + public function testSuffix() { $tests = array( - array("-append|/|foo", array(), ""), - array("-append|#|foo=wilma", array(), "wilma#"), - array("-append|&?|foo=wilma", array("foo" => "barney"), "barney&?"), + array("-suffix|/|foo", array(), ""), + array("-suffix|#|foo=wilma", array(), "wilma#"), + array("-suffix|&?|foo=wilma", array("foo" => "barney"), "barney&?"), + array("-suffix|&|foo", array("foo" => array("wilma", "barney")), "wilma&barney&") ); self::runnerHelper($tests); } - public function testListjoin() { + public function testList() { $tests = array( - array("-listjoin|/|foo", array(), ""), - array("-listjoin|/|foo", array("foo" => array("a", "b")), "a/b"), - array("-listjoin||foo", array("foo" => array("a", "b")), "ab"), - array("-listjoin|/|foo", array("foo" => array("a")), "a"), - array("-listjoin|/|foo", array("foo" => array()), ""), + array("-list|/|foo", array(), ""), + array("-list|/|foo", array("foo" => array("a", "b")), "a/b"), + array("-list||foo", array("foo" => array("a", "b")), "ab"), + array("-list|/|foo", array("foo" => array("a")), "a"), + array("-list|/|foo", array("foo" => array()), ""), ); self::runnerHelper($tests); @@ -119,6 +120,7 @@ array("-prefix|&|foo=wilma", array(), "&wilma"), array("-prefix||foo=wilma", array(), "wilma"), array("-prefix|&|foo=wilma", array("foo" => "barney"), "&barney"), + array("-prefix|&|foo", array("foo" => array("wilma", "barney")), "&wilma&barney") ); self::runnerHelper($tests); @@ -154,7 +156,7 @@ public function testSpecials() { $tests = array( array("foo", array("foo" => " "), "%20"), - array("-listjoin|&|foo", array("foo" => array("&", "&", "|", "_")), "%26&%26&%7C&_"), + array("-list|&|foo", array("foo" => array("&", "&", "|", "_")), "%26&%26&%7C&_"), ); self::runnerHelper($tests); @@ -164,44 +166,58 @@ $t = new URI_Template("http://example.org/news/{id}/"); self::assertEquals("http://example.org/news/joe/", $t->substitute(array("id" => "joe"))); - $t = new URI_Template("http://www.google.com/notebook/feeds/{userID}{-prefix|/notebooks/|notebookID}{-opt|/-/|categories}{-listjoin|/|categories}?{-join|&|updated-min,updated-max,alt,start-index,max-results,entryID,orderby}"); + $t = new URI_Template("http://www.google.com/notebook/feeds/{userID}{-prefix|/notebooks/|notebookID}{-opt|/-/|categories}{-list|/|categories}?{-join|&|updated-min,updated-max,alt,start-index,max-results,entryID,orderby}"); self::assertEquals("http://www.google.com/notebook/feeds/joe?", $t->substitute(array("userID" => "joe"))); self::assertEquals("http://www.google.com/notebook/feeds/joe/-/A%7C-B/-C?start-index=10", - $t->substitute(array("userID" => "joe", "categories" => array("A|-B", "-C"), "start-index" => "10"))); + $t->substitute(array("userID" => "joe", "categories" => array("A|-B", "-C"), "start-index" => "10"))); - /* Source: From the IETF Draft */ + /* Source: IETF Draft 03 */ + $values = array("bar" => "fred", "baz" => "10,20,30", "qux" => array(10, 20, 30), + "corge" => array(), "grault" => " ", "garply" => "a/b/c", + "waldo" => "ben & jerrys", "fred" => array("fred", "", "wilma"), + "1-a_b.c" => 200); + + $tests = array( + "http://example.org/?q={bar}" => "http://example.org/?q=fred", + "/{xyzzy}" => "/", + "http://example.org/?{-join|&|bar,xyzzy,baz}" => "http://example.org/?bar=fred&baz=10%2C20%2C30", + "http://example.org/?d={-list|,|qux}" => "http://example.org/?d=10,20,30", + "http://example.org/?d={-list|&d=|qux}" => "http://example.org/?d=10&d=20&d=30", + "http://example.org/{bar}{bar}/{garply}" => "http://example.org/fredfred/a%2Fb%2Fc", + "http://example.org/{bar}{-prefix|/|fred}" => "http://example.org/fred/fred//wilma", + "../{waldo}/" => "../ben%20%26%20jerrys/", + "telnet:192.0.2.16{-opt|:80|grault}" => "telnet:192.0.2.16:80", + ":{1-a_b.c}:" => ":200:", + ); + + foreach ($tests as $key => $value) { + $t = new URI_Template($key); + self::assertEquals($value, $t->substitute($values)); + } + + /* Source: IETF Draft 02 */ $values = array("a" => "foo", "b" => "bar", "data" => "10,20,30", "points" => array(10, 20, 30), "list0" => array(), "str0" => "", "reserved" => ":/?#[]@!$&'()*+,;=", "a_b" => "baz"); - $t = new URI_Template("/{-append|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}"); - self::assertEquals("/foo/data#bar", $t->substitute($values)); - - $t = new URI_Template("relative/{reserved}/"); - self::assertEquals("relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/", $t->substitute($values)); - - $t = new URI_Template("http://example.org/{foo=%25}/"); - self::assertEquals("http://example.org/%25/", $t->substitute($values)); - - $t = new URI_Template("http://example.org/?{-join|&|a,data}"); - self::assertEquals("http://example.org/?a=foo&data=10%2C20%2C30", $t->substitute($values)); - - $t = new URI_Template("http://example.org/?d={-listjoin|,|points}&{-join|&|a,b}"); - self::assertEquals("http://example.org/?d=10,20,30&a=foo&b=bar", $t->substitute($values)); - - $t = new URI_Template("http://example.org/?d={-listjoin|,|list0}&{-join|&|foo}"); - self::assertEquals("http://example.org/?d=&", $t->substitute(array())); - - $t = new URI_Template("http://example.org/?d={-listjoin|&d=|points}"); - self::assertEquals("http://example.org/?d=10&d=20&d=30", $t->substitute($values)); - - $t = new URI_Template("http://example.org/{a}{b}/{a_b}"); - self::assertEquals("http://example.org/foobar/baz", $t->substitute($values)); - - $t = new URI_Template("http://example.org/{a}{-prefix|/-/|a}/"); - self::assertEquals("http://example.org/foo/-/foo/", $t->substitute($values)); + $tests = array( + "/{-suffix|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}" => "/foo/data#bar", + "relative/{reserved}/" => "relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/", + "http://example.org/{foo=%25}/" => "http://example.org/%25/", + "http://example.org/?{-join|&|a,data}" => "http://example.org/?a=foo&data=10%2C20%2C30", + "http://example.org/?d={-list|,|points}&{-join|&|a,b}" => "http://example.org/?d=10,20,30&a=foo&b=bar", + "http://example.org/?d={-list|,|list0}&{-join|&|foo}" => "http://example.org/?d=&", + "http://example.org/?d={-list|&d=|points}" => "http://example.org/?d=10&d=20&d=30", + "http://example.org/{a}{b}/{a_b}" => "http://example.org/foobar/baz", + "http://example.org/{a}{-prefix|/-/|a}/" => "http://example.org/foo/-/foo/", + ); + + foreach ($tests as $key => $value) { + $t = new URI_Template($key); + self::assertEquals($value, $t->substitute($values)); + } } private static function runnerHelper($tests) {