|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +var tap = require('tap'); |
| 4 | + |
3 | 5 | var path = require('path'); |
4 | 6 | var pha = require('../core/lib/pseudopattern_hunter'); |
5 | 7 | var pa = require('../core/lib/pattern_assembler'); |
@@ -30,59 +32,57 @@ function stubPatternlab() { |
30 | 32 | return pl; |
31 | 33 | } |
32 | 34 |
|
33 | | -exports['pseudopattern_hunter'] = { |
34 | | - 'pseudpattern found and added as a pattern' : function (test) { |
35 | | - //arrange |
36 | | - var pl = stubPatternlab(); |
37 | | - |
38 | | - var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); |
39 | | - atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); |
40 | | - atomPattern.extendedTemplate = atomPattern.template; |
41 | | - atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
42 | | - |
43 | | - pattern_assembler.addPattern(atomPattern, pl); |
44 | | - |
45 | | - //act |
46 | | - var patternCountBefore = pl.patterns.length; |
47 | | - pseudopattern_hunter.find_pseudopatterns(atomPattern, pl); |
48 | | - |
49 | | - //assert |
50 | | - test.equals(patternCountBefore + 1, pl.patterns.length); |
51 | | - test.equals(pl.patterns[1].patternPartial, 'test-styled-atom-alt'); |
52 | | - test.equals(pl.patterns[1].extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), '<span class="test_base {{styleModifier}}"> {{message}} </span>'); |
53 | | - test.equals(JSON.stringify(pl.patterns[1].jsonFileData), JSON.stringify({"message": "alternateMessage"})); |
54 | | - test.equals(pl.patterns[1].patternLink, '00-test-03-styled-atom-alt' + path.sep + '00-test-03-styled-atom-alt.html'); |
55 | | - |
56 | | - test.done(); |
57 | | - }, |
58 | | - |
59 | | - 'pseudpattern variant includes stylePartials and parameteredPartials' : function (test) { |
60 | | - //arrange |
61 | | - var pl = stubPatternlab(); |
62 | | - |
63 | | - var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); |
64 | | - atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); |
65 | | - atomPattern.extendedTemplate = atomPattern.template; |
66 | | - atomPattern.stylePartials = atomPattern.findPartialsWithStyleModifiers(atomPattern); |
67 | | - atomPattern.parameteredPartials = atomPattern.findPartialsWithPatternParameters(atomPattern); |
68 | | - |
69 | | - var pseudoPattern = new Pattern('00-test/474-pseudomodifier.mustache'); |
70 | | - pseudoPattern.template = fs.readFileSync(patterns_dir + '00-test/474-pseudomodifier.mustache', 'utf8'); |
71 | | - pseudoPattern.extendedTemplate = atomPattern.template; |
72 | | - pseudoPattern.stylePartials = pseudoPattern.findPartialsWithStyleModifiers(pseudoPattern); |
73 | | - pseudoPattern.parameteredPartials = pseudoPattern.findPartialsWithPatternParameters(pseudoPattern); |
74 | | - |
75 | | - pattern_assembler.addPattern(atomPattern, pl); |
76 | | - pattern_assembler.addPattern(pseudoPattern, pl); |
77 | | - |
78 | | - //act |
79 | | - pseudopattern_hunter.find_pseudopatterns(pseudoPattern, pl); |
80 | | - |
81 | | - //assert |
82 | | - test.equals(pl.patterns[2].patternPartial, 'test-pseudomodifier-test'); |
83 | | - test.equals(pl.patterns[2].stylePartials, pseudoPattern.stylePartials); |
84 | | - test.equals(pl.patterns[2].parameteredPartials, pseudoPattern.parameteredPartials); |
85 | | - |
86 | | - test.done(); |
87 | | - } |
88 | | -}; |
| 35 | +tap.test('pseudpattern found and added as a pattern', function (test) { |
| 36 | + //arrange |
| 37 | + var pl = stubPatternlab(); |
| 38 | + |
| 39 | + var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); |
| 40 | + atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); |
| 41 | + atomPattern.extendedTemplate = atomPattern.template; |
| 42 | + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
| 43 | + |
| 44 | + pattern_assembler.addPattern(atomPattern, pl); |
| 45 | + |
| 46 | + //act |
| 47 | + var patternCountBefore = pl.patterns.length; |
| 48 | + pseudopattern_hunter.find_pseudopatterns(atomPattern, pl); |
| 49 | + |
| 50 | + //assert |
| 51 | + test.equals(patternCountBefore + 1, pl.patterns.length); |
| 52 | + test.equals(pl.patterns[1].patternPartial, 'test-styled-atom-alt'); |
| 53 | + test.equals(pl.patterns[1].extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), '<span class="test_base {{styleModifier}}"> {{message}} </span>'); |
| 54 | + test.equals(JSON.stringify(pl.patterns[1].jsonFileData), JSON.stringify({"message": "alternateMessage"})); |
| 55 | + test.equals(pl.patterns[1].patternLink, '00-test-03-styled-atom-alt' + path.sep + '00-test-03-styled-atom-alt.html'); |
| 56 | + |
| 57 | + test.end(); |
| 58 | +}); |
| 59 | + |
| 60 | +tap.test('pseudpattern variant includes stylePartials and parameteredPartials', function (test) { |
| 61 | + //arrange |
| 62 | + var pl = stubPatternlab(); |
| 63 | + |
| 64 | + var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); |
| 65 | + atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); |
| 66 | + atomPattern.extendedTemplate = atomPattern.template; |
| 67 | + atomPattern.stylePartials = atomPattern.findPartialsWithStyleModifiers(atomPattern); |
| 68 | + atomPattern.parameteredPartials = atomPattern.findPartialsWithPatternParameters(atomPattern); |
| 69 | + |
| 70 | + var pseudoPattern = new Pattern('00-test/474-pseudomodifier.mustache'); |
| 71 | + pseudoPattern.template = fs.readFileSync(patterns_dir + '00-test/474-pseudomodifier.mustache', 'utf8'); |
| 72 | + pseudoPattern.extendedTemplate = atomPattern.template; |
| 73 | + pseudoPattern.stylePartials = pseudoPattern.findPartialsWithStyleModifiers(pseudoPattern); |
| 74 | + pseudoPattern.parameteredPartials = pseudoPattern.findPartialsWithPatternParameters(pseudoPattern); |
| 75 | + |
| 76 | + pattern_assembler.addPattern(atomPattern, pl); |
| 77 | + pattern_assembler.addPattern(pseudoPattern, pl); |
| 78 | + |
| 79 | + //act |
| 80 | + pseudopattern_hunter.find_pseudopatterns(pseudoPattern, pl); |
| 81 | + |
| 82 | + //assert |
| 83 | + test.equals(pl.patterns[2].patternPartial, 'test-pseudomodifier-test'); |
| 84 | + test.equals(pl.patterns[2].stylePartials, pseudoPattern.stylePartials); |
| 85 | + test.equals(pl.patterns[2].parameteredPartials, pseudoPattern.parameteredPartials); |
| 86 | + |
| 87 | + test.end(); |
| 88 | +}); |
0 commit comments