-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from pikesley/reusable-lists
Reusable lists. Closes #6
- Loading branch information
Showing
3 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
describe('Resusable lists', function() { | ||
describe('return a list item and remove it from the list', function() { | ||
it('pulls out an item', function() { | ||
items = [ | ||
'Brockway', | ||
'North Haverbrook', | ||
'Ogdenville' | ||
] | ||
var extracted = extract(items) | ||
expect(extracted['remainder'].length).toEqual(2) | ||
|
||
switch(extracted['victim']) { | ||
case 'Brockway': | ||
expect(extracted['remainder']).toEqual([ | ||
'North Haverbrook', | ||
'Ogdenville' | ||
]) | ||
break | ||
|
||
case 'North Haverbrook': | ||
expect(extracted['remainder']).toEqual([ | ||
'Brockway', | ||
'Ogdenville' | ||
]) | ||
break | ||
|
||
case 'Ogdenville': | ||
expect(extracted['remainder']).toEqual([ | ||
'Brockway', | ||
'North Haverbrook' | ||
]) | ||
} | ||
}) | ||
}) | ||
|
||
describe('populate a template with a repeated placeholder', function() { | ||
var json = { | ||
'templates': [ | ||
'@these and @these' | ||
], | ||
'these': [ | ||
'this', | ||
'that' | ||
] | ||
} | ||
|
||
it('reuses the list', function() { | ||
templated = template(json) | ||
switch(templated.substring(0, 4)) { | ||
case 'this': | ||
expect(templated).toEqual('this and that') | ||
break | ||
|
||
case 'that': | ||
expect(templated).toEqual('that and this') | ||
break | ||
} | ||
}) | ||
|
||
describe('with a recursive template', function() { | ||
var json = { | ||
'templates': [ | ||
'@things and @stuff' | ||
], | ||
'things': [ | ||
'Lions', | ||
'Tigers', | ||
'Bears' | ||
], | ||
'stuff': [ | ||
'@things and @things' | ||
] | ||
} | ||
|
||
it('reuses the list when things get recursive', function() { | ||
templated = template(json) | ||
words = templated.split(' ').sort() | ||
expect(words).toEqual([ | ||
'Bears', | ||
'Lions', | ||
'Tigers', | ||
'and', | ||
'and' | ||
]) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters