Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[t/hitomi] added three more test files

They cover variable substitution, if statements, and for loops. The exact
type names and calling conventions are still not set in stone.
  • Loading branch information...
commit 6918b4ee73ac2ca57302cadedf88c541ef56ec3a 1 parent 56156ff
@masak authored
Showing with 93 additions and 0 deletions.
  1. +31 −0 t/hitomi/02-substitution.t
  2. +25 −0 t/hitomi/03-if.t
  3. +37 −0 t/hitomi/04-for.t
View
31 t/hitomi/02-substitution.t
@@ -0,0 +1,31 @@
+use v6;
+use Test;
+use Hitomi;
+
+plan 2;
+
+{
+ my Hitomi::MarkupTemplate $template .= new('<html>
+ <h1>Hello, $name!</h1>
+</html>
+');
+ my Hitomi::Stream $stream = $template.generate( :name<world> );
+ is $stream.render('html', :doctype(Hitomi::DocType::HTML5)),
+ '<!DOCTYPE html>
+<html>
+ <h1>Hello, world!</h1>
+</html>
+', 'simple variable substitution works';
+}
+
+{
+ my Hitomi::MarkupTemplate $template .= new('<html>
+ <h1>Hello, ${ $name }</h1></html>
+');
+ my Hitomi::Stream $stream = $template.generate( :name<world> );
+ is $stream.render('html', :doctype(Hitomi::DocType::HTML5)), '<!DOCTYPE html>
+<html>
+ <h1>Hello, world!</h1>
+</html>
+', 'dollar block substitution works';
+}
View
25 t/hitomi/03-if.t
@@ -0,0 +1,25 @@
+use v6;
+use Test;
+use Hitomi;
+
+plan 2;
+
+{
+ my Hitomi::MarkupTemplate $template .= new('<html>
+ <h1 pe:if="$flag">Hello, world!</h1>
+</html>
+');
+ is $template.generate( :flag(True) ).render('html',
+ :doctype(Hitomi::DocType::HTML5)),
+ '<!DOCTYPE html>
+<html>
+ <h1>Hello, world!</h1>
+</html>
+', 'true if statement works';
+ is $template.generate( :flag(False) ).render('html',
+ :doctype(Hitomi::DocType::HTML5)),
+ '<!DOCTYPE html>
+<html>
+</html>
+', 'false if statement works';
+}
View
37 t/hitomi/04-for.t
@@ -0,0 +1,37 @@
+use v6;
+use Test;
+use Hitomi;
+
+plan 2;
+
+{
+ my Hitomi::MarkupTemplate $template .= new('<html>
+ <h1 pe:for="@list">$_</h1>
+</html>
+');
+ is $template.generate( '@list' => <foo bar baz> ).render('html',
+ :doctype(Hitomi::DocType::HTML5)),
+ '<!DOCTYPE html>
+<html>
+ <h1>foo</h1>
+ <h1>bar</h1>
+ <h1>baz</h1>
+</html>
+', 'for loop with loop variable $_ works';
+}
+
+{
+ my Hitomi::MarkupTemplate $template .= new('<html>
+ <h1 pe:for="@list -> $item">$item</h1>
+</html>
+');
+ is $template.generate( '@list' => <foo bar baz> ).render('html',
+ :doctype(Hitomi::DocType::HTML5)),
+ '<!DOCTYPE html>
+<html>
+ <h1>foo</h1>
+ <h1>bar</h1>
+ <h1>baz</h1>
+</html>
+', 'for loop with custom loop variable works';
+}
Please sign in to comment.
Something went wrong with that request. Please try again.