### ----------------------------------------------------
### -- Template::Mustache
### -- Licenses: Artistic-2.0
### -- Authors: Tim Smith, Richard Hainsworth
### -- File: t/specs/inheritable_partials.json
### ----------------------------------------------------
{
  "tests": [
    {
      "name": "Template can embed an inherited partial",
      "data": { },
      "template": "before {{<partial}}{{/partial}} after",
      "partials": { "partial": "partial" },
      "expected": "before partial after"
    },
    {
      "name": "Template can embed several inherited partials",
      "data": { },
      "template": "before1 {{<partial1}}{{/partial1}} | {{<partial2}}{{/partial2}} after2",
      "partials": { "partial1": "partial1", "partial2": "partial2" },
      "expected": "before1 partial1 | partial2 after2"
    },
    {
      "name": "Template can embed an inherited partial inside in a section",
      "data": { "items": [0,1,2,3] },
      "template": "{{#items}}{{<partial}}{{/partial}}{{/items}}",
      "partials": { "partial": "{{.}}" },
      "expected": "0123"
    },
    {
      "name": "Inherited partials can embed inherited partials",
      "data": { },
      "template": "before1 {{<partial1}}{{/partial1}} after1",
      "partials": {
        "partial1": "before2 {{<partial2}}{{/partial2}} after2",
        "partial2": "partial2" },
      "expected": "before1 before2 partial2 after2 after1"
    },
    {
      "name": "Partials can embed inherited partials",
      "data": { },
      "template": "before1 {{>partial1}} after1",
      "partials": {
        "partial1": "before2 {{<partial2}}{{/partial2}} after2",
        "partial2": "partial2" },
      "expected": "before1 before2 partial2 after2 after1"
    },
    {
      "name": "Inherited partials can embed partials",
      "data": { },
      "template": "before1 {{<partial1}}{{/partial1}} after1",
      "partials": {
        "partial1": "before2 {{>partial2}} after2",
        "partial2": "partial2" },
      "expected": "before1 before2 partial2 after2 after1"
    },
    {
      "name": "Templates can override top level inheritable sections in inherited partials",
      "data": { },
      "template": "{{<partial}}{{$inheritable}}inherited{{/inheritable}}{{/partial}}",
      "partials": { "partial": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "inherited"
    },
    {
      "name": "Templates can override nested inheritable sections in inherited partials",
      "data": { "items": [0,1,2,3] },
      "template": "{{<partial}}{{$inheritable}}{{.}}{{/inheritable}}{{/partial}}",
      "partials": { "partial": "{{#items}}{{$inheritable}}ignored{{/inheritable}}{{/items}}" },
      "expected": "0123"
    },
    {
      "name": "Templates can override duplicated inheritable sections",
      "data": { },
      "template": "{{<partial}}{{$inheritable}}inherited{{/inheritable}}{{/partial}}",
      "partials": { "partial": "{{$inheritable}}ignored{{/inheritable}} {{$inheritable}}ignored{{/inheritable}}" },
      "expected": "inherited inherited"
    },
    {
      "name": "The content of the last inheritable section is rendered in the inherited section",
      "data": { },
      "template": "{{<partial}}{{$inheritable}}1{{/inheritable}}{{$inheritable}}2{{/inheritable}}{{/partial}}",
      "partials": { "partial": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "2"
    },
    {
      "name": "The content of the last inheritable sections in partials is rendered in the inherited section",
      "data": { },
      "template": "{{<partial1}}{{$inheritable}}1{{/inheritable}}{{>partial2}}{{$inheritable}}4{{/inheritable}}{{/partial1}}",
      "partials": {
        "partial1": "{{$inheritable}}ignored{{/inheritable}}",
        "partial2": "{{$inheritable}}2{{/inheritable}}{{$inheritable}}3{{/inheritable}}" },
      "expected": "4"
    },
    {
      "name": "The content of the last inheritable sections in partials is rendered in the inherited section",
      "data": { },
      "template": "{{<partial1}}{{$inheritable}}1{{/inheritable}}{{>partial2}}{{/partial1}}",
      "partials": {
        "partial1": "{{$inheritable}}ignored{{/inheritable}}",
        "partial2": "{{$inheritable}}2{{/inheritable}}{{$inheritable}}3{{/inheritable}}" },
      "expected": "3"
    },
    {
      "name": "Inherited partials can override inheritable sections in their own inherited partials",
      "data": { },
      "template": "{{<partial1}}{{/partial1}}",
      "partials": {
          "partial1": "{{<partial2}}{{$inheritable}}partial1{{/inheritable}}{{/partial2}}",
          "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "partial1"
    },
    {
      "name": "Partials in inherited partials can override inheritable sections",
      "data": { },
      "template": "{{<partial2}}{{>partial1}}{{/partial2}}",
      "partials": {
          "partial1": "{{$inheritable}}partial1{{/inheritable}}",
          "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "partial1"
    },
    {
      "name": "Partials can override inheritable sections in their own inherited partials",
      "data": { },
      "template": "{{>partial1}}",
      "partials": {
          "partial1": "{{<partial2}}{{$inheritable}}partial1{{/inheritable}}{{/partial2}}",
          "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "partial1"
    },
    {
      "name": "Templates and partials can both override the same inherited partial",
      "data": { },
      "template": "{{<partial2}}{{$inheritable}}base{{/inheritable}}{{/partial2}} {{>partial1}}",
      "partials": {
          "partial1": "{{<partial2}}{{$inheritable}}partial1{{/inheritable}}{{/partial2}}",
          "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "base partial1"
    },
    {
      "name": "Templates can override inheritable sections in partials embedded in inherited partials",
      "data": { },
      "template": "{{<partial1}}{{$inheritable}}inherited{{/inheritable}}{{/partial1}}",
      "partials": {
        "partial1": "{{>partial2}}",
        "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "inherited"
    },
    {
      "name": "Templates can override inheritable sections in inherited partials embedded in inherited partials",
      "data": { },
      "template": "{{<partial1}}{{$inheritable}}inherited{{/inheritable}}{{/partial1}}",
      "partials": {
        "partial1": "{{<partial2}}{{/partial2}}",
        "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "inherited"
    },
    {
      "name": "Templates can not override non-inheritable sections",
      "data": { "section": true },
      "template": "{{<partial}}{{$section}}inherited{{/section}}{{/partial}}",
      "partials": { "partial": "{{#section}}success{{/section}}" },
      "expected": "success"
    },
    {
      "name": "Templates sections can not override inheritable sections in inherited partial",
      "data": { "section": true },
      "template": "{{<partial}}{{#section}}inherited{{/section}}{{/partial}}",
      "partials": { "partial": "{{$section}}success{{/section}}" },
      "expected": "success"
    },
    {
      "!comment": "// Inspired by https://github.com/spullara/mustache.java/commit/d2942e39a671ee71c0427b3a963149af81bdb0a5",
      "name": "Recursive inherited partials should be rendered.",
      "data": { "content": "X", "nodes": [ { "content": "Y", "nodes": [] } ] },
      "template": "<{{<node}}{{/node}}>",
      "partials": {
        "node": "{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"
      },
      "expected": "<X<Y<>>>"
    },
    {
      "name": "Templates can override inheritable sections in recursive partials",
      "data": { "content": "X", "nodes": [ { "content": "Y", "nodes": [] } ] },
      "template": "<{{<node}}{{$value}}{{>node}}{{/value}}{{/node}}>",
      "partials": { "node": "{{content}}<{{#nodes}}{{$value}}overriden{{/value}}{{/nodes}}>" },
      "expected": "<X<Y<>>>"
    },
    {
      "name": "Inheritable section context is cleaned after inherited partial rendering.",
      "data": { },
      "template": "{{$section}}rendered{{/section}}|{{<partial}}{{$section}}inherited{{/section}}{{/partial}}|{{$section}}rendered{{/section}}",
      "partials": { "partial": "{{$section}}ignored{{/section}}" },
      "expected": "rendered|inherited|rendered"
    },
    {
      "name": "Two levels of inheritance: inherited partial with overriding content containing a partial",
      "data": { },
      "template": "{{<partial}}{{>partial2}}{{/partial}}",
      "partials": {
          "partial": "{{$inheritable}}ignored{{/inheritable}}",
          "partial2": "{{$inheritable}}inherited{{/inheritable}}" },
      "expected": "inherited"
    },
    {
      "name": "Two levels of inheritance: inherited partial with overriding content containing another inherited partial",
      "data": { },
      "template": "{{<partial}}{{<partial2}}{{/partial2}}{{/partial}}",
      "partials": {
          "partial": "{{$inheritable}}ignored{{/inheritable}}",
          "partial2": "{{$inheritable}}inherited{{/inheritable}}" },
      "expected": "inherited"
    },
    {
      "name": "Two levels of inheritance: inherited partial with overriding content containing another inherited partial with overriding content containing an inheritable section",
      "data": { },
      "template": "{{<partial}}{{<partial2}}{{$inheritable}}inherited{{/inheritable}}{{/partial2}}{{/partial}}",
      "partials": {
          "partial": "{{$inheritable}}ignored{{/inheritable}}",
          "partial2": "{{$inheritable}}ignored{{/inheritable}}" },
      "expected": "inherited"
    }
  ]
}


