11"use strict" ;
2+ /*eslint-disable no-shadow*/
23
4+ var tap = require ( 'tap' ) ;
35var path = require ( 'path' ) ;
46var pa = require ( '../core/lib/pattern_assembler' ) ;
57var Pattern = require ( '../core/lib/object_factory' ) . Pattern ;
68var testPatternsPath = path . resolve ( __dirname , 'files' , '_patterns' ) ;
79var eol = require ( 'os' ) . EOL ;
810
11+ // don't run these tests unless mustache is installed
12+ var engineLoader = require ( '../core/lib/pattern_engines' ) ;
13+ if ( ! engineLoader . mustache ) {
14+ tap . test ( 'Mustache engine not installed, skipping tests.' , function ( test ) {
15+ test . end ( ) ;
16+ } ) ;
17+ return ;
18+ }
19+
920// fake pattern lab constructor:
1021// sets up a fake patternlab object, which is needed by the pattern processing
1122// apparatus.
@@ -33,7 +44,7 @@ function fakePatternLab() {
3344
3445// function for testing sets of partials
3546function testFindPartials ( test , partialTests ) {
36- test . expect ( partialTests . length + 1 ) ;
47+ test . plan ( partialTests . length + 1 ) ;
3748
3849 // setup current pattern from what we would have during execution
3950 // docs on partial syntax are here:
@@ -55,11 +66,11 @@ function testFindPartials(test, partialTests) {
5566 test . equals ( results [ index ] , testString ) ;
5667 } ) ;
5768
58- test . done ( ) ;
69+ test . end ( ) ;
5970}
6071
6172function testFindPartialsWithStyleModifiers ( test , partialTests ) {
62- test . expect ( partialTests . length + 1 ) ;
73+ test . plan ( partialTests . length + 1 ) ;
6374
6475 // setup current pattern from what we would have during execution
6576 // docs on partial syntax are here:
@@ -81,11 +92,11 @@ function testFindPartialsWithStyleModifiers(test, partialTests) {
8192 test . equals ( results [ index ] , testString ) ;
8293 } ) ;
8394
84- test . done ( ) ;
95+ test . end ( ) ;
8596}
8697
8798function testFindPartialsWithPatternParameters ( test , partialTests ) {
88- test . expect ( partialTests . length + 1 ) ;
99+ test . plan ( partialTests . length + 1 ) ;
89100
90101 // setup current pattern from what we would have during execution
91102 // docs on partial syntax are here:
@@ -107,110 +118,106 @@ function testFindPartialsWithPatternParameters(test, partialTests) {
107118 test . equals ( results [ index ] , testString ) ;
108119 } ) ;
109120
110- test . done ( ) ;
121+ test . end ( ) ;
111122}
112123
113- exports [ 'engine_mustache' ] = {
114- 'find_pattern_partials finds one simple partial' : function ( test ) {
115- testFindPartials ( test , [
116- "{{> molecules-comment-header}}"
117- ] ) ;
118- } ,
119-
120- 'find_pattern_partials finds simple partials under stressed circumstances' : function ( test ) {
121- testFindPartials ( test , [
122- "{{>molecules-comment-header}}" ,
123- "{{> " + eol + " molecules-comment-header" + eol + "}}" ,
124- "{{> molecules-weird-spacing }}"
125- ] ) ;
126- } ,
127-
128- 'find_pattern_partials finds one simple verbose partial' : function ( test ) {
129- testFindPartials ( test , [
130- '{{> 00-atoms/00-global/06-test }}'
131- ] ) ;
132- } ,
133-
134- 'find_pattern_partials finds partials with parameters' : function ( test ) {
135- testFindPartials ( test , [
136- "{{> molecules-single-comment(description: true) }}" ,
137- "{{> molecules-single-comment(description: 42) }}" ,
138- "{{> molecules-single-comment(description: '42') }}" ,
139- "{{> molecules-single-comment(description: \"42\") }}" ,
140- "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
141- "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
142- '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
143- ] ) ;
144- } ,
145-
146- 'find_pattern_partials finds simple partials with style modifiers' : function ( test ) {
147- testFindPartials ( test , [
148- '{{> molecules-single-comment:foo }}' ,
149- '{{> molecules-single-comment:foo|bar }}'
150- ] ) ;
151- } ,
152- 'find_pattern_partials finds mixed partials' : function ( test ) {
153- testFindPartials ( test , [
154- '{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}' ,
155- '{{> molecules-single-comment:foo|bar(description: true) }}'
156- ] ) ;
157- } ,
158-
159- 'find_pattern_partials finds one simple partial with styleModifier' : function ( test ) {
160- testFindPartialsWithStyleModifiers ( test , [
161- "{{> molecules-comment-header:test}}"
162- ] ) ;
163- } ,
164- 'find_pattern_partials finds partial with many styleModifiers' : function ( test ) {
165- testFindPartialsWithStyleModifiers ( test , [
166- "{{> molecules-comment-header:test|test2|test3}}"
167- ] ) ;
168- } ,
169- 'find_pattern_partials finds partials with differing styleModifiers' : function ( test ) {
170- testFindPartialsWithStyleModifiers ( test , [
171- "{{> molecules-comment-header:test|test2|test3}}" ,
172- "{{> molecules-comment-header:foo-1}}" ,
173- "{{> molecules-comment-header:bar_1}}"
174- ] ) ;
175- } ,
176- 'find_pattern_partials finds partials with styleModifiers when parameters present' : function ( test ) {
177- testFindPartialsWithStyleModifiers ( test , [
178- "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
179- "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
180- "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
181- ] ) ;
182- } ,
183-
184- 'find_pattern_partials_with_parameters finds one simple partial with parameters' : function ( test ) {
185- testFindPartialsWithPatternParameters ( test , [
186- "{{> molecules-comment-header(description: 'test')}}"
187- ] ) ;
188- } ,
189- 'find_pattern_partials_with_parameters finds partials with parameters' : function ( test ) {
190- testFindPartialsWithPatternParameters ( test , [
191- "{{> molecules-single-comment(description: true) }}" ,
192- "{{> molecules-single-comment(description: 42) }}" ,
193- "{{> molecules-single-comment(description: '42') }}" ,
194- "{{> molecules-single-comment(description: \"42\") }}" ,
195- "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
196- "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
197- '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
198- ] ) ;
199- } ,
200- 'find_pattern_partials finds partials with parameters when styleModifiers present' : function ( test ) {
201- testFindPartialsWithPatternParameters ( test , [
202- "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
203- "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
204- "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
205- ] ) ;
206- }
207-
208- } ;
209124
210-
211- // don't run these tests unless mustache is installed
212- var engineLoader = require ( '../core/lib/pattern_engines' ) ;
213- if ( ! engineLoader . mustache ) {
214- console . log ( "Mustache engine not installed, skipping tests." ) ;
215- delete exports . engine_mustache ;
216- }
125+ tap . test ( 'find_pattern_partials finds one simple partial' , function ( test ) {
126+ testFindPartials ( test , [
127+ "{{> molecules-comment-header}}"
128+ ] ) ;
129+ } ) ;
130+
131+ tap . test ( 'find_pattern_partials finds simple partials under stressed circumstances' , function ( test ) {
132+ testFindPartials ( test , [
133+ "{{>molecules-comment-header}}" ,
134+ "{{> " + eol + " molecules-comment-header" + eol + "}}" ,
135+ "{{> molecules-weird-spacing }}"
136+ ] ) ;
137+ } ) ;
138+
139+ tap . test ( 'find_pattern_partials finds one simple verbose partial' , function ( test ) {
140+ testFindPartials ( test , [
141+ '{{> 00-atoms/00-global/06-test }}'
142+ ] ) ;
143+ } ) ;
144+
145+ tap . test ( 'find_pattern_partials finds partials with parameters' , function ( test ) {
146+ testFindPartials ( test , [
147+ "{{> molecules-single-comment(description: true) }}" ,
148+ "{{> molecules-single-comment(description: 42) }}" ,
149+ "{{> molecules-single-comment(description: '42') }}" ,
150+ "{{> molecules-single-comment(description: \"42\") }}" ,
151+ "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
152+ "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
153+ '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
154+ ] ) ;
155+ } ) ;
156+
157+ tap . test ( 'find_pattern_partials finds simple partials with style modifiers' , function ( test ) {
158+ testFindPartials ( test , [
159+ '{{> molecules-single-comment:foo }}' ,
160+ '{{> molecules-single-comment:foo|bar }}'
161+ ] ) ;
162+ } ) ;
163+
164+ tap . test ( 'find_pattern_partials finds mixed partials' , function ( test ) {
165+ testFindPartials ( test , [
166+ '{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}' ,
167+ '{{> molecules-single-comment:foo|bar(description: true) }}'
168+ ] ) ;
169+ } ) ;
170+
171+ tap . test ( 'find_pattern_partials finds one simple partial with styleModifier' , function ( test ) {
172+ testFindPartialsWithStyleModifiers ( test , [
173+ "{{> molecules-comment-header:test}}"
174+ ] ) ;
175+ } ) ;
176+
177+ tap . test ( 'find_pattern_partials finds partial with many styleModifiers' , function ( test ) {
178+ testFindPartialsWithStyleModifiers ( test , [
179+ "{{> molecules-comment-header:test|test2|test3}}"
180+ ] ) ;
181+ } ) ;
182+
183+ tap . test ( 'find_pattern_partials finds partials with differing styleModifiers' , function ( test ) {
184+ testFindPartialsWithStyleModifiers ( test , [
185+ "{{> molecules-comment-header:test|test2|test3}}" ,
186+ "{{> molecules-comment-header:foo-1}}" ,
187+ "{{> molecules-comment-header:bar_1}}"
188+ ] ) ;
189+ } ) ;
190+
191+ tap . test ( 'find_pattern_partials finds partials with styleModifiers when parameters present' , function ( test ) {
192+ testFindPartialsWithStyleModifiers ( test , [
193+ "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
194+ "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
195+ "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
196+ ] ) ;
197+ } ) ;
198+
199+ tap . test ( 'find_pattern_partials_with_parameters finds one simple partial with parameters' , function ( test ) {
200+ testFindPartialsWithPatternParameters ( test , [
201+ "{{> molecules-comment-header(description: 'test')}}"
202+ ] ) ;
203+ } ) ;
204+
205+ tap . test ( 'find_pattern_partials_with_parameters finds partials with parameters' , function ( test ) {
206+ testFindPartialsWithPatternParameters ( test , [
207+ "{{> molecules-single-comment(description: true) }}" ,
208+ "{{> molecules-single-comment(description: 42) }}" ,
209+ "{{> molecules-single-comment(description: '42') }}" ,
210+ "{{> molecules-single-comment(description: \"42\") }}" ,
211+ "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
212+ "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
213+ '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
214+ ] ) ;
215+ } ) ;
216+
217+ tap . test ( 'find_pattern_partials finds partials with parameters when styleModifiers present' , function ( test ) {
218+ testFindPartialsWithPatternParameters ( test , [
219+ "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
220+ "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
221+ "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
222+ ] ) ;
223+ } ) ;
0 commit comments