Permalink
Browse files

Add spec for new Directives capabilities

  • Loading branch information...
1 parent 5a1dce9 commit c528c4ac7cf2016699feb2c4b5b5ffed1a8ad803 @padolsey committed Mar 18, 2013
Showing with 66 additions and 0 deletions.
  1. +66 −0 test/DirectivesSpec.js
View
@@ -0,0 +1,66 @@
+describe('Directives', function() {
+
+ describe('Custom Generator with directives', function() {
+
+ var directives = {};
+
+ var customGen = new siml.Generator({
+ directives: directives,
+ pretty: false
+ });
+
+ it('Throws error on undefined directives', function() {
+ expect(function() {
+ customGen.parse('a @foo');
+ }).toThrow('SIML: Directive not resolvable: foo');
+ });
+
+ describe('Custom @foo directive', function() {
+
+ beforeEach(function() {
+ directives.foo = {
+ type: 'CONTENT',
+ make: function(name, children/*, args */) {
+ this.parentElement.htmlContent.push(
+ '<foo>' + [].slice.call(arguments, 2).join()
+ );
+ if (children.length) {
+ this.parentElement.processChildren(children);
+ }
+ this.parentElement.htmlContent.push('</foo>');
+ }
+ };
+ });
+
+ afterEach(function() {
+ delete directives.foo;
+ });
+
+ it('Generates @foo with no args correctly', function() {
+ expect(customGen.parse('div @foo')).toBe('<div><foo></foo></div>');
+ });
+
+ it('Generates @foo with args correctly', function() {
+ expect(customGen.parse('div @foo(123,"four", false)')).toBe('<div><foo>123,four,false</foo></div>');
+ });
+
+ it('Generates @foo with args & children correctly', function() {
+ expect(customGen.parse('div @foo(1,2,3) { a, b }')).toBe('<div><foo>1,2,3<a></a><b></b></foo></div>');
+ expect(customGen.parse('\
+ div\n\
+ h1\n\
+ @foo WOW\n\
+ ')).toBe('<div><h1><foo><WOW></WOW></foo></h1></div>');
+ expect(customGen.parse('\
+ div\n\
+ @foo\n\
+ @foo\n\
+ @foo(4) @foo\n\
+ ')).toBe('<div><foo><foo><foo>4<foo></foo></foo></foo></foo></div>');
+ });
+
+ });
+
+ });
+
+});

0 comments on commit c528c4a

Please sign in to comment.