Skip to content

Commit

Permalink
Merge pull request #159 from linkedin/vybs-dustjs
Browse files Browse the repository at this point in the history
fix the description on the core tests for $idx and $len for scalar
  • Loading branch information
vybs committed Oct 1, 2012
2 parents 5fce821 + 7a45615 commit 4ce7917
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions dist/dust-core-1.1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ Chunk.prototype.partial = function(elem, context, params) {
//put the params context second to match what section does. {.} matches the current context without parameters
// start with an empty context
partialContext = dust.makeBase(context.global);
partialContext.blocks = context.blocks;
if (context.stack && context.stack.tail){
// grab the stack(tail) off of the previous context if we have it
partialContext.stack = context.stack.tail;
Expand Down
1 change: 1 addition & 0 deletions dist/dust-full-1.1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ Chunk.prototype.partial = function(elem, context, params) {
//put the params context second to match what section does. {.} matches the current context without parameters
// start with an empty context
partialContext = dust.makeBase(context.global);
partialContext.blocks = context.blocks;
if (context.stack && context.stack.tail){
// grab the stack(tail) off of the previous context if we have it
partialContext.stack = context.stack.tail;
Expand Down
56 changes: 56 additions & 0 deletions test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,62 @@ var coreTests = [
expected: "",
message: "should ignore carriage return or tab in inline param values"
},
{
name: "array: reference $idx in iteration on objects",
source: "{#names}({$idx}).{title} {name}{~n}{/names}",
context: { title: "Sir", names: [ { name: "Moe" }, { name: "Larry" }, { name: "Curly" } ] },
expected: "(0).Sir Moe\n(1).Sir Larry\n(2).Sir Curly\n",
message: "array: reference $idx in iteration on objects"
},
{
name: "array: reference $len in iteration on objects",
source: "{#names}Size=({$len}).{title} {name}{~n}{/names}",
context: { title: "Sir", names: [ { name: "Moe" }, { name: "Larry" }, { name: "Curly" } ] },
expected: "Size=(3).Sir Moe\nSize=(3).Sir Larry\nSize=(3).Sir Curly\n",
message: "test array: reference $len in iteration on objects"
},
{
name: "array reference $idx in iteration on simple type",
source: "{#names}({$idx}).{title} {.}{~n}{/names}",
context: { title: "Sir", names: [ "Moe", "Larry", "Curly" ] },
expected: "(0).Sir Moe\n(1).Sir Larry\n(2).Sir Curly\n",
message: "test array reference $idx in iteration on simple types"
},
{
name: "array reference $len in iteration on simple type",
source: "{#names}Size=({$len}).{title} {.}{~n}{/names}",
context: { title: "Sir", names: [ "Moe", "Larry", "Curly" ] },
expected: "Size=(3).Sir Moe\nSize=(3).Sir Larry\nSize=(3).Sir Curly\n",
message: "test array reference $len in iteration on simple types"
},
{
name: "array reference $idx/$len on empty array case",
source: "{#names}Idx={$idx} Size=({$len}).{title} {.}{~n}{/names}",
context: { title: "Sir", names: [ ] },
expected: "",
message: "test array reference $idx/$len on empty array case"
},
{
name: "array reference $idx/$len on single element case (scalar case)",
source: "{#name}Idx={$idx} Size={$len} {.}{/name}",
context: { name: "Just one name" },
expected: "Idx= Size= Just one name",
message: "test array reference $idx/$len on single element case"
},
{
name: "array reference $idx/$len {#.} section case",
source: "{#names}{#.}{$idx}{.} {/.}{/names}",
context: { names: ["Moe", "Larry", "Curly"] },
expected: "0Moe 1Larry 2Curly ",
message: "test array reference $idx/$len {#.} section case"
},
{
name: "array reference $idx/$len nested loops",
source: "{#A}A loop:{$idx}-{$len},{#B}B loop:{$idx}-{$len}C[0]={.C[0]} {/B}A loop trailing: {$idx}-{$len}{/A}",
context: {"A": [ {"B": [ {"C": ["Ca1", "C2"]}, {"C": ["Ca2", "Ca22"]} ] }, {"B": [ {"C": ["Cb1", "C2"]}, {"C": ["Cb2", "Ca2"]} ] } ] },
expected: "A loop:0-2,B loop:0-2C[0]=Ca1 B loop:1-2C[0]=Ca2 A loop trailing: 0-2A loop:1-2,B loop:0-2C[0]=Cb1 B loop:1-2C[0]=Cb2 A loop trailing: 1-2",
message: "test array reference $idx/$len nested loops"
},
{
name: "blocks with dynamic keys",
source: ['{<title_A}',
Expand Down
1 change: 0 additions & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<script src="./dust_files/jsdump.js"></script>
<script src="./dust_files/beautify.js"></script>
<script src="../lib/dust.js"></script>
<script src="../lib/dust-helpers.js"></script>
<script src="../lib/parser.js"></script>
<script src="../lib/compiler.js"></script>
<script src="./jasmine-test/spec/coreTests.js"></script>
Expand Down

0 comments on commit 4ce7917

Please sign in to comment.