@@ -27,60 +27,79 @@ class FunctionalTest extends TestCase
27
27
/**
28
28
* @dataProvider getMarkdownTests
29
29
*/
30
- public function testMarkdown (string $ template , string $ expected ): void
30
+ public function testMarkdown (string $ markdown , string $ expected ): void
31
31
{
32
32
foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /*MichelfMarkdown::class,*/ DefaultMarkdown::class] as $ class ) {
33
- $ twig = new Environment (new ArrayLoader ([
34
- 'index ' => $ template ,
35
- 'html ' => <<<EOF
36
- Hello
37
- =====
33
+ $ twig = $ this ->getTwig ($ class , [
34
+ 'apply ' => "{% apply markdown_to_html %} \n{$ markdown }\n{% endapply %} " ,
35
+ 'include ' => "{{ include('md')|markdown_to_html }} " ,
36
+ 'indent ' => "{{ include('indent_md')|markdown_to_html }} " ,
37
+ 'md ' => $ markdown ,
38
+ 'indent_md ' => ltrim (str_replace ("\n" , "\n\t" , "\n$ markdown " ), "\n" ),
39
+ ]);
38
40
39
- Great!
40
- EOF
41
- ]));
42
- $ twig ->addExtension (new MarkdownExtension ());
43
- $ twig ->addRuntimeLoader (new class ($ class ) implements RuntimeLoaderInterface {
44
- private $ class ;
41
+ $ twig_md = trim ($ twig ->render ('apply ' ));
42
+ $ this ->assertMatchesRegularExpression ('{ ' .$ expected .'}m ' , $ twig_md );
45
43
46
- public function __construct (string $ class )
47
- {
48
- $ this ->class = $ class ;
49
- }
44
+ $ twig_md = trim ($ twig ->render ('include ' ));
45
+ $ this ->assertMatchesRegularExpression ('{ ' .$ expected .'}m ' , $ twig_md );
50
46
51
- public function load ($ c )
52
- {
53
- if (MarkdownRuntime::class === $ c ) {
54
- return new $ c (new $ this ->class ());
55
- }
56
- }
57
- });
58
- $ this ->assertMatchesRegularExpression ('{ ' .$ expected .'}m ' , trim ($ twig ->render ('index ' )));
47
+ $ twig_md = trim ($ twig ->render ('indent ' ));
48
+ $ this ->assertMatchesRegularExpression ('{ ' .$ expected .'}m ' , $ twig_md );
49
+
50
+ $ lib_md = trim ((new $ class )->convert ($ markdown ));
51
+ $ this ->assertEquals ($ lib_md , $ twig_md , "Twig output versus {$ class } output. " );
59
52
}
60
53
}
61
54
62
55
public function getMarkdownTests ()
63
56
{
64
57
return [
65
58
[<<<EOF
66
- {% apply markdown_to_html %}
67
59
Hello
68
60
=====
69
61
70
62
Great!
71
- {% endapply %}
72
63
EOF
73
64
, "<h1>Hello</h1> \n+<p>Great!</p> " ],
65
+
74
66
[<<<EOF
75
- {% apply markdown_to_html %}
76
- Hello
77
- =====
78
67
79
- Great!
80
- {% endapply %}
68
+ Leading
69
+
70
+ Linebreak
81
71
EOF
82
- , "<h1>Hello</h1> \n+<p>Great!</p> " ],
83
- ["{{ include('html')|markdown_to_html }} " , "<h1>Hello</h1> \n+<p>Great!</p> " ],
72
+ , "<p>Leading</p> \n+<p>Linebreak</p> " ],
73
+
74
+ [<<<EOF
75
+ Code
76
+
77
+ Paragraph
78
+ EOF
79
+ , "<pre><code>Code \n?</code></pre> \n+<p>Paragraph</p> " ],
84
80
];
85
81
}
82
+
83
+ private function getTwig (string $ class , array $ templates ): Environment
84
+ {
85
+ $ twig = new Environment (new ArrayLoader ($ templates ));
86
+ $ twig ->addExtension (new MarkdownExtension ());
87
+ $ twig ->addRuntimeLoader (new class ($ class ) implements RuntimeLoaderInterface {
88
+ private $ class ;
89
+
90
+ public function __construct (string $ class )
91
+ {
92
+ $ this ->class = $ class ;
93
+ }
94
+
95
+ public function load ($ c )
96
+ {
97
+ if (MarkdownRuntime::class === $ c )
98
+ {
99
+ return new $ c (new $ this ->class ());
100
+ }
101
+ }
102
+ });
103
+ return $ twig ;
104
+ }
86
105
}
0 commit comments