Permalink
Browse files

Updating mustache spec

  • Loading branch information...
1 parent 663f58f commit 26fc8f8f5e417489964c65ec8b4637b6bc9fc8cd @jbboehr committed Jul 11, 2012
Showing with 3,112 additions and 28 deletions.
  1. +14 −7 generate-tests.php
  2. +3 −3 mustache.php
  3. +1 −1 spec
  4. +24 −0 tests/mustache-spec-comment-indented-inline.phpt
  5. +29 −0 tests/mustache-spec-comment-indented-multiline-standalone.phpt
  6. +27 −0 tests/mustache-spec-comment-indented-standalone.phpt
  7. +22 −0 tests/mustache-spec-comment-inline.phpt
  8. +29 −0 tests/mustache-spec-comment-multiline-standalone.phpt
  9. +27 −0 tests/mustache-spec-comment-multiline.phpt
  10. +25 −0 tests/mustache-spec-comment-standalone-line-endings.phpt
  11. +24 −0 tests/mustache-spec-comment-standalone-without-newline.phpt
  12. +23 −0 tests/mustache-spec-comment-standalone-without-previous-line.phpt
  13. +27 −0 tests/mustache-spec-comment-standalone.phpt
  14. +22 −0 tests/mustache-spec-comment-surrounding-whitespace.phpt
  15. +3 −3 tests/mustache-spec-comments-standalone-line-endings.phpt
  16. +27 −0 tests/mustache-spec-delimiter-indented-standalone-tag.phpt
  17. +43 −0 tests/mustache-spec-delimiter-inverted-sections.phpt
  18. +24 −0 tests/mustache-spec-delimiter-outlying-whitespace-inline.phpt
  19. +23 −0 tests/mustache-spec-delimiter-pair-behavior.phpt
  20. +22 −0 tests/mustache-spec-delimiter-pair-with-padding.phpt
  21. +32 −0 tests/mustache-spec-delimiter-partial-inheritence.phpt
  22. +31 −0 tests/mustache-spec-delimiter-post-partial-behavior.phpt
  23. +43 −0 tests/mustache-spec-delimiter-sections.phpt
  24. +23 −0 tests/mustache-spec-delimiter-special-characters.phpt
  25. +25 −0 tests/mustache-spec-delimiter-standalone-line-endings.phpt
  26. +27 −0 tests/mustache-spec-delimiter-standalone-tag.phpt
  27. +24 −0 tests/mustache-spec-delimiter-standalone-without-newline.phpt
  28. +23 −0 tests/mustache-spec-delimiter-standalone-without-previous-line.phpt
  29. +22 −0 tests/mustache-spec-delimiter-surrounding-whitespace.phpt
  30. +3 −3 tests/mustache-spec-delimiters-standalone-line-endings.phpt
  31. +22 −0 tests/mustache-spec-interpolatio-ampersand-context-miss-interpolation.phpt
  32. +23 −0 tests/mustache-spec-interpolatio-ampersand-decimal-interpolation.phpt
  33. +23 −0 tests/mustache-spec-interpolatio-ampersand-integer-interpolation.phpt
  34. +25 −0 tests/mustache-spec-interpolatio-ampersand-standalone.phpt
  35. +23 −0 tests/mustache-spec-interpolatio-ampersand-surrounding-whitespace.phpt
  36. +23 −0 tests/mustache-spec-interpolatio-ampersand-with-padding.phpt
  37. +25 −0 tests/mustache-spec-interpolatio-ampersand.phpt
  38. +22 −0 tests/mustache-spec-interpolatio-basic-context-miss-interpolation.phpt
  39. +23 −0 tests/mustache-spec-interpolatio-basic-decimal-interpolation.phpt
  40. +23 −0 tests/mustache-spec-interpolatio-basic-integer-interpolation.phpt
  41. +25 −0 tests/mustache-spec-interpolatio-basic-interpolation.phpt
  42. +26 −0 tests/mustache-spec-interpolatio-dotted-names-ampersand-interpolation.phpt
  43. +38 −0 tests/mustache-spec-interpolatio-dotted-names-arbitrary-depth.phpt
  44. +26 −0 tests/mustache-spec-interpolatio-dotted-names-basic-interpolation.phpt
  45. +32 −0 tests/mustache-spec-interpolatio-dotted-names-broken-chain-resolution.phpt
  46. +25 −0 tests/mustache-spec-interpolatio-dotted-names-broken-chains.phpt
  47. +31 −0 tests/mustache-spec-interpolatio-dotted-names-context-precedence.phpt
  48. +51 −0 tests/mustache-spec-interpolatio-dotted-names-initial-resolution.phpt
  49. +26 −0 tests/mustache-spec-interpolatio-dotted-names-triple-mustache-interpolation.phpt
  50. +25 −0 tests/mustache-spec-interpolatio-html-escaping.phpt
  51. +25 −0 tests/mustache-spec-interpolatio-interpolation-standalone.phpt
  52. +23 −0 tests/mustache-spec-interpolatio-interpolation-surrounding-whitespace.phpt
  53. +23 −0 tests/mustache-spec-interpolatio-interpolation-with-padding.phpt
  54. +24 −0 tests/mustache-spec-interpolatio-no-interpolation.phpt
  55. +22 −0 tests/mustache-spec-interpolatio-triple-mustache-context-miss-interpolation.phpt
  56. +23 −0 tests/mustache-spec-interpolatio-triple-mustache-decimal-interpolation.phpt
  57. +23 −0 tests/mustache-spec-interpolatio-triple-mustache-integer-interpolation.phpt
  58. +25 −0 tests/mustache-spec-interpolatio-triple-mustache-standalone.phpt
  59. +23 −0 tests/mustache-spec-interpolatio-triple-mustache-surrounding-whitespace.phpt
  60. +23 −0 tests/mustache-spec-interpolatio-triple-mustache-with-padding.phpt
  61. +25 −0 tests/mustache-spec-interpolatio-triple-mustache.phpt
  62. +22 −0 tests/mustache-spec-inverte-context-misses.phpt
  63. +26 −0 tests/mustache-spec-inverte-context.phpt
  64. +25 −0 tests/mustache-spec-inverte-dotted-names-broken-chains.phpt
  65. +29 −0 tests/mustache-spec-inverte-dotted-names-falsey.phpt
  66. +29 −0 tests/mustache-spec-inverte-dotted-names-truthy.phpt
  67. +34 −0 tests/mustache-spec-inverte-doubled.phpt
  68. +25 −0 tests/mustache-spec-inverte-empty-list.phpt
  69. +23 −0 tests/mustache-spec-inverte-falsey.phpt
  70. +27 −0 tests/mustache-spec-inverte-indented-inline-sections.phpt
  71. +27 −0 tests/mustache-spec-inverte-internal-whitespace.phpt
  72. +37 −0 tests/mustache-spec-inverte-list.phpt
  73. +23 −0 tests/mustache-spec-inverte-nested-falsey.phpt
  74. +23 −0 tests/mustache-spec-inverte-nested-truthy.phpt
  75. +23 −0 tests/mustache-spec-inverte-padding.phpt
  76. +31 −0 tests/mustache-spec-inverte-standalone-indented-lines.phpt
  77. +27 −0 tests/mustache-spec-inverte-standalone-line-endings.phpt
  78. +31 −0 tests/mustache-spec-inverte-standalone-lines.phpt
  79. +27 −0 tests/mustache-spec-inverte-standalone-without-newline.phpt
  80. +26 −0 tests/mustache-spec-inverte-standalone-without-previous-line.phpt
  81. +25 −0 tests/mustache-spec-inverte-surrounding-whitespace.phpt
  82. +23 −0 tests/mustache-spec-inverte-truthy.phpt
  83. +4 −4 tests/mustache-spec-inverted-standalone-line-endings.phpt
  84. +26 −0 tests/mustache-spec-partial-basic-behavior.phpt
  85. +27 −0 tests/mustache-spec-partial-context.phpt
  86. +25 −0 tests/mustache-spec-partial-failed-lookup.phpt
  87. +31 −0 tests/mustache-spec-partial-inline-indentation.phpt
  88. +27 −0 tests/mustache-spec-partial-padding-whitespace.phpt
  89. +37 −0 tests/mustache-spec-partial-recursion.phpt
  90. +40 −0 tests/mustache-spec-partial-standalone-indentation.phpt
  91. +29 −0 tests/mustache-spec-partial-standalone-line-endings.phpt
  92. +30 −0 tests/mustache-spec-partial-standalone-without-newline.phpt
  93. +29 −0 tests/mustache-spec-partial-standalone-without-previous-line.phpt
  94. +26 −0 tests/mustache-spec-partial-surrounding-whitespace.phpt
  95. +3 −3 tests/mustache-spec-partials-standalone-line-endings.phpt
  96. +22 −0 tests/mustache-spec-section-context-misses.phpt
  97. +26 −0 tests/mustache-spec-section-context.phpt
  98. +70 −0 tests/mustache-spec-section-deeply-nested-contexts.phpt
  99. +25 −0 tests/mustache-spec-section-dotted-names-broken-chains.phpt
  100. +29 −0 tests/mustache-spec-section-dotted-names-falsey.phpt
  101. +29 −0 tests/mustache-spec-section-dotted-names-truthy.phpt
  102. +34 −0 tests/mustache-spec-section-doubled.phpt
  103. +25 −0 tests/mustache-spec-section-empty-list.phpt
  104. +23 −0 tests/mustache-spec-section-falsey.phpt
  105. +30 −0 tests/mustache-spec-section-implicit-iterator-decimal.phpt
  106. +30 −0 tests/mustache-spec-section-implicit-iterator-integer.phpt
  107. +30 −0 tests/mustache-spec-section-implicit-iterator-string.phpt
  108. +27 −0 tests/mustache-spec-section-indented-inline-sections.phpt
  109. +31 −0 tests/mustache-spec-section-indented-standalone-lines.phpt
  110. +27 −0 tests/mustache-spec-section-internal-whitespace.phpt
  111. +37 −0 tests/mustache-spec-section-list.phpt
  112. +23 −0 tests/mustache-spec-section-nested-falsey.phpt
  113. +23 −0 tests/mustache-spec-section-nested-truthy.phpt
  114. +23 −0 tests/mustache-spec-section-padding.phpt
  115. +27 −0 tests/mustache-spec-section-standalone-line-endings.phpt
  116. +31 −0 tests/mustache-spec-section-standalone-lines.phpt
  117. +27 −0 tests/mustache-spec-section-standalone-without-newline.phpt
  118. +26 −0 tests/mustache-spec-section-standalone-without-previous-line.phpt
  119. +25 −0 tests/mustache-spec-section-surrounding-whitespace.phpt
  120. +23 −0 tests/mustache-spec-section-truthy.phpt
  121. +4 −4 tests/mustache-spec-sections-standalone-line-endings.phpt
View
@@ -6,6 +6,11 @@
ini_set('display_errors', true);
define('MY_EOL', "\n"); // PHP_EOL
+if( !extension_loaded('yaml') ) {
+ echo 'Requires php-yaml' . PHP_EOL;
+ exit(1);
+}
+
// Argv
if( !empty($argv[1]) && is_dir($argv[1]) ) {
$specDir = $argv[1];
@@ -17,12 +22,19 @@
}
$specs = array();
+$specData = array();
foreach( scandir($specDir) as $file ) {
if( $file[0] == '~' ) {
continue;
}
- if( strlen($file) > 5 && substr($file, -5) == '.json' ) {
- $specs[] = substr($file, 0, -5);
+ //if( strlen($file) > 5 && substr($file, -5) == '.json' ) {
+ if( strlen($file) > 4 && substr($file, -4) == '.yml' ) {
+ $spec = substr($file, 0, -5);
+ $specs[] = $spec;
+
+ $contents = file_get_contents($specDir . DIRECTORY_SEPARATOR . $file);
+ //$specData[$spec] = json_decode($contents, true);
+ $specData[$spec] = yaml_parse($contents);
}
}
@@ -31,11 +43,6 @@
exit(1);
}
-$specData = array();
-foreach( $specs as $spec ) {
- $specData[$spec] = json_decode(file_get_contents($specDir . DIRECTORY_SEPARATOR . $spec . '.json'), true);
-}
-
// Generate tests
foreach( $specData as $spec => $data ) {
$tests = $data['tests'];
View
@@ -73,9 +73,9 @@ public function tokenize($tmpl) {}
/**
* Renders a template
*
- * @param string|MustacheTemplate $tmpl The input template
- * @param array|MustacheData $data The input data
- * @param array $partials (Optional) The template partials
+ * @param mixed $tmpl The input template
+ * @param mixed $data The input data
+ * @param mixed $partials (Optional) The template partials
* @return false|string The string output, or false on failure
*/
public function render($tmpl, $data, $partials = null) {}
2 spec
Submodule spec updated 1 files
+8 −0 specs/interpolation.yml
@@ -0,0 +1,24 @@
+--TEST--
+Indented Inline
+--DESCRIPTION--
+Inline comments should not strip whitespace
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Indented Inline',
+ 'desc' => 'Inline comments should not strip whitespace',
+ 'data' =>
+ array (
+ ),
+ 'template' => ' 12 {{! 34 }}
+',
+ 'expected' => ' 12
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+\s*12\s*
@@ -0,0 +1,29 @@
+--TEST--
+Indented Multiline Standalone
+--DESCRIPTION--
+All standalone comment lines should be removed.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Indented Multiline Standalone',
+ 'desc' => 'All standalone comment lines should be removed.',
+ 'data' =>
+ array (
+ ),
+ 'template' => 'Begin.
+ {{!
+ Something\'s going on here...
+ }}
+End.
+',
+ 'expected' => 'Begin.
+End.
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+Begin\.\s*End\.\s*
@@ -0,0 +1,27 @@
+--TEST--
+Indented Standalone
+--DESCRIPTION--
+All standalone comment lines should be removed.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Indented Standalone',
+ 'desc' => 'All standalone comment lines should be removed.',
+ 'data' =>
+ array (
+ ),
+ 'template' => 'Begin.
+ {{! Indented Comment Block! }}
+End.
+',
+ 'expected' => 'Begin.
+End.
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+Begin\.\s*End\.\s*
@@ -0,0 +1,22 @@
+--TEST--
+Inline
+--DESCRIPTION--
+Comment blocks should be removed from the template.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Inline',
+ 'desc' => 'Comment blocks should be removed from the template.',
+ 'data' =>
+ array (
+ ),
+ 'template' => '12345{{! Comment Block! }}67890',
+ 'expected' => '1234567890',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+1234567890
@@ -0,0 +1,29 @@
+--TEST--
+Multiline Standalone
+--DESCRIPTION--
+All standalone comment lines should be removed.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Multiline Standalone',
+ 'desc' => 'All standalone comment lines should be removed.',
+ 'data' =>
+ array (
+ ),
+ 'template' => 'Begin.
+{{!
+Something\'s going on here...
+}}
+End.
+',
+ 'expected' => 'Begin.
+End.
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+Begin\.\s*End\.\s*
@@ -0,0 +1,27 @@
+--TEST--
+Multiline
+--DESCRIPTION--
+Multiline comments should be permitted.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Multiline',
+ 'desc' => 'Multiline comments should be permitted.',
+ 'data' =>
+ array (
+ ),
+ 'template' => '12345{{!
+ This is a
+ multi-line comment...
+}}67890
+',
+ 'expected' => '1234567890
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+1234567890\s*
@@ -0,0 +1,25 @@
+--TEST--
+Standalone Line Endings
+--DESCRIPTION--
+"\r\n" should be considered a newline for standalone tags.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Standalone Line Endings',
+ 'desc' => '"\\r\\n" should be considered a newline for standalone tags.',
+ 'data' =>
+ array (
+ ),
+ 'template' => '|
+{{! Standalone Comment }}
+|',
+ 'expected' => '|
+|',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+\|\s*\|
@@ -0,0 +1,24 @@
+--TEST--
+Standalone Without Newline
+--DESCRIPTION--
+Standalone tags should not require a newline to follow them.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Standalone Without Newline',
+ 'desc' => 'Standalone tags should not require a newline to follow them.',
+ 'data' =>
+ array (
+ ),
+ 'template' => '!
+ {{! I\'m Still Standalone }}',
+ 'expected' => '!
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+\!\s*
@@ -0,0 +1,23 @@
+--TEST--
+Standalone Without Previous Line
+--DESCRIPTION--
+Standalone tags should not require a newline to precede them.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Standalone Without Previous Line',
+ 'desc' => 'Standalone tags should not require a newline to precede them.',
+ 'data' =>
+ array (
+ ),
+ 'template' => ' {{! I\'m Still Standalone }}
+!',
+ 'expected' => '!',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+\!
@@ -0,0 +1,27 @@
+--TEST--
+Standalone
+--DESCRIPTION--
+All standalone comment lines should be removed.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Standalone',
+ 'desc' => 'All standalone comment lines should be removed.',
+ 'data' =>
+ array (
+ ),
+ 'template' => 'Begin.
+{{! Comment Block! }}
+End.
+',
+ 'expected' => 'Begin.
+End.
+',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+Begin\.\s*End\.\s*
@@ -0,0 +1,22 @@
+--TEST--
+Surrounding Whitespace
+--DESCRIPTION--
+Comment removal should preserve surrounding whitespace.
+--SKIPIF--
+<?php if(!extension_loaded('mustache')) die('skip '); ?>
+--FILE--
+<?php
+$test = array (
+ 'name' => 'Surrounding Whitespace',
+ 'desc' => 'Comment removal should preserve surrounding whitespace.',
+ 'data' =>
+ array (
+ ),
+ 'template' => '12345 {{! Comment Block! }} 67890',
+ 'expected' => '12345 67890',
+);
+$mustache = new Mustache();
+echo $mustache->render($test["template"], $test["data"]);
+?>
+--EXPECTREGEX--
+12345\s*67890
@@ -11,10 +11,10 @@ $test = array (
'data' =>
array (
),
- 'expected' => '|
+ 'expected' => '|
|',
- 'template' => '|
-{{! Standalone Comment }}
+ 'template' => '|
+{{! Standalone Comment }}
|',
'desc' => '"\\r\\n" should be considered a newline for standalone tags.',
);
Oops, something went wrong.

0 comments on commit 26fc8f8

Please sign in to comment.