#!/usr/bin/env perl use strict; use warnings; use lib 't/lib'; use Test::More; use Test::Handlebars; render_ok( '

{{title}}

', { title => 'Xslate rocks' }, '

Xslate rocks

', "basic variables" ); render_ok( '

{{article.title}}

', { article => { title => 'Hash references rock' } }, '

Hash references rock

', ". separator" ); render_ok( '

{{article/title}}

', { article => { title => 'Deprecated syntax does not' } }, '

Deprecated syntax does not

', "/ separator" ); render_ok( '

{{page.article.title}}

- {{date}}', { page => { article => { title => 'Multilevel field access' }, }, date => '2012-10-01', }, '

Multilevel field access

- 2012-10-01', "multilevel field access with ." ); render_ok( '{{#article}}

{{title}}

- {{../date}}{{/article}}', { article => { title => 'Backtracking' }, date => '2012-10-01' }, '

Backtracking

- 2012-10-01', "backtracking with ../" ); render_ok( <<'TEMPLATE', {{#page}} {{#article}}

{{title}}

- {{../../date}}{{/article}} {{/page}} TEMPLATE { page => { article => { title => 'Multilevel Backtracking' }, }, date => '2012-10-01', }, <<'RENDERED',

Multilevel Backtracking

- 2012-10-01 RENDERED "multilevel backtracking with ../" ); render_ok( '{{#article}}

{{title}}

- {{../metadata.date}}{{/article}}', { article => { title => 'Backtracking' }, metadata => { date => '2012-10-01' }, }, '

Backtracking

- 2012-10-01', "backtracking into other hash variables with ../ and ." ); render_ok( '{{articles.[10].comments}}', { articles => { 10 => { comments => "First post!" }, }, }, 'First post!', "field access with non-identifiers" ); render_ok( '{{articles.[.foo\som#th"ing].comments}}', { articles => { '.foo\som#th"ing' => { comments => "First post!" }, }, }, 'First post!', "field access with non-identifiers" ); render_ok( '{{articles.[10].comments}}', { articles => [ (({}) x 10), { comments => "First post!" }, ], }, 'First post!', "array dereferencing" ); render_ok( '{{.}} {{this}}', "foo", "foo foo", "top level current context" ); render_ok( '{{#thing}}{{.}} {{this}}{{/thing}}', { thing => [ "foo" ], }, "foo foo", "nested current context" ); render_ok( '{{#hellos}}{{this/text}}{{/hellos}}', { hellos => [ { text => 'hello' }, { text => 'Hello' }, { text => 'HELLO' }, ], }, 'helloHelloHELLO', "'this' with paths" ); render_ok( '{{#thing}}{{{.}}} {{{this}}}{{/thing}}', { thing => [ "" ], }, " ", "{{{.}}}" ); render_ok( '{{foo-bar}}', { 'foo-bar' => "FOOBAR", }, 'FOOBAR', "- is a valid character" ); render_ok( '{{foo.foo-bar}}', { foo => { 'foo-bar' => "FOOBAR", }, }, 'FOOBAR', "- is a valid character" ); done_testing;