-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide stubbed visitor implementation
Part of #889
- Loading branch information
Showing
2 changed files
with
106 additions
and
2 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,48 @@ | ||
/*global Handlebars */ | ||
|
||
describe('Visitor', function() { | ||
if (!Handlebars.Visitor) { | ||
return; | ||
} | ||
|
||
function ast_for(template) { | ||
var ast = Handlebars.parse(template); | ||
return Handlebars.print(ast); | ||
} | ||
|
||
it('should provide coverage', function() { | ||
// Simply run the thing and make sure it does not fail and that all of the | ||
// stub methods are executed | ||
var visitor = new Handlebars.Visitor(); | ||
visitor.accept(Handlebars.parse('{{#foo (bar 1 "1" true) foo=@data}}{{!comment}}{{> bar }} {{/foo}}')); | ||
}); | ||
|
||
it('should traverse to stubs', function() { | ||
var visitor = new Handlebars.Visitor(); | ||
|
||
visitor.PARTIAL_NAME = function(partialName) { | ||
equal(partialName.name, 'bar'); | ||
}; | ||
|
||
visitor.STRING = function(string) { | ||
equal(string.string, '2'); | ||
}; | ||
visitor.NUMBER = function(number) { | ||
equal(number.stringModeValue, 1); | ||
}; | ||
visitor.BOOLEAN = function(bool) { | ||
equal(bool.stringModeValue, true); | ||
}; | ||
visitor.ID = function(id) { | ||
equal(id.original, 'foo.bar'); | ||
}; | ||
visitor.content = function(content) { | ||
equal(content.string, ' '); | ||
}; | ||
visitor.comment = function(comment) { | ||
equal(comment.comment, 'comment'); | ||
}; | ||
|
||
visitor.accept(Handlebars.parse('{{#foo.bar (foo.bar 1 "2" true) [email protected]}}{{!comment}}{{> bar }} {{/foo.bar}}')); | ||
}); | ||
}); |