From 65f499f370422ab1fae501698428b4ecd2d94933 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 13:13:50 +0200 Subject: [PATCH 01/10] Test on splitting CSS code with complex content --- test/kss-splitter.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index b4c33bd8..0fc63ec7 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -375,4 +375,46 @@ multiline(function() { expect(kssBlocks).eql(result); }); + it('should pasre compex CSS code', function() { + var str = multiline(function() { + /* +@import "test"; +// Comment +// Styleguide 1.0 + +a:before { content: "/* ..." } + +// Comment +// Styleguide 2 + +// Comment +// Styleguide 2.0 + + +.a { b: c } + + */ + }), + result = [ + { + kss: '', + code: '\n@import "test";' + }, + { + kss: '// Comment\n// Styleguide 1.0', + code: '\n\n.a:before { content: "/* ..." }\n' + }, + { + kss: '// Comment\n// Styleguide 2', + code: '\n' + }, + { + kss: '// Comment\n// Styleguide 2.0', + code: '\n\n\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); + }); From c7186da33a3a40c54bb4a54b3c3481983779567e Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:19:32 +0200 Subject: [PATCH 02/10] Split code and comments using Gonzales --- lib/modules/kss-splitter.js | 101 +++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/lib/modules/kss-splitter.js b/lib/modules/kss-splitter.js index 3845a92b..b6433468 100644 --- a/lib/modules/kss-splitter.js +++ b/lib/modules/kss-splitter.js @@ -1,61 +1,76 @@ 'use strict' -var kssBlocksParser = require('./kss-blocks-parser').kssBlocksParser; +var gonzales = require('gonzales-pe'), + gonzo = require('gonzales-ast'); module.exports = { /* Split string source into array of code and comment blocks */ - pureSplitter: function(source) { - var lines = source.split(/\n|$/g), - anInlineComment = /^ *\/\//, - multilineCommentStarted = /\/\*/, - multilineCommentFinished = /\*\//, - isMultilineCommentStarted, - blocks = [], - block, - type, - prevType; - - lines.forEach(function(line) { - - if (isMultilineCommentStarted) { - type = 'comment' - if (multilineCommentFinished.test(line)) { - isMultilineCommentStarted = false; + pureSplitter: function(source, syntax) { + + syntax = syntax || 'scss'; + var out = {}, + ast = gonzales.srcToAST({ + src: source, + syntax: syntax + }), + block, + blocks = [], + prevNode; + + gonzo.traverse(ast, [{ + // Visitor for SASS and SCSS syntaxes + test: function(name, nodes) { + return name !== 'stylesheet'; + }, + process: function(nodes) { + var startNewBlock = function() { + block && blocks.push(block); + block = { + type: '', + content: '' + }; + }, + type; + + // Calculate type of the current block + + // Multiline comment is comment + if (nodes[0] == 'commentML') { + type = 'comment'; } - } else { - isMultilineCommentStarted = multilineCommentStarted.test(line); - if (isMultilineCommentStarted) { - type = 'comment' - } else { - type = anInlineComment.test(line) ? 'comment' : 'code'; + // Singleline comment is comment + else if (nodes[0] === 'commentSL') { + type = 'comment'; } - } - - if (prevType != type) { - // Save old block if a new type appears - if (block) { - block.content = block.content.join('\n'); - blocks.push(block); + // Single breaklines between singleline comments are comments + else if (nodes[0] === 's' && nodes[1].split('\n').length <= 2 && prevNode[0] === 'commentSL') { + type = 'comment'; } - // Start a new block after changing the type - block = { - type: type, - content: [line] + else { + type = 'code'; } - } else { - block.content.push(line); - } - prevType = type; + // If type has been changed, start a new block + if (!block || block.type != type) { + startNewBlock(); + } - }); + // Extend current block content + block.type = type; + block.content += gonzales.astToSrc({ + ast: nodes, + syntax: syntax + }); + prevNode = nodes; - // Push the last block - block.content = block.content.join('\n'); - blocks.push(block); + } + }]); + // push last block + blocks.push(block); return blocks; + }, getBlocks: function(source) { From 8b3bacf6f81ded775d4b0eacf01fafe7b48ae845 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:32:16 +0200 Subject: [PATCH 03/10] All the linebreaks are now saved in AST --- lib/modules/kss-splitter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/modules/kss-splitter.js b/lib/modules/kss-splitter.js index b6433468..9155e710 100644 --- a/lib/modules/kss-splitter.js +++ b/lib/modules/kss-splitter.js @@ -101,11 +101,9 @@ module.exports = { } } else { // Not KSS comments are considered to be parts of code - pair.code.push('\n') pair.code.push(block.content) } } else { - pair.code.push('\n') pair.code.push(block.content) } From c9d11ef9b97d4c23022a67e97e5311981c2f6160 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:32:38 +0200 Subject: [PATCH 04/10] All the linebreaks are save, fix tests --- test/kss-splitter.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index 0fc63ec7..d0d80916 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -19,7 +19,7 @@ describe('KSS splitter', function() { }), result = [ { type: 'comment', content: '// Comment1\n// Comment1' }, - { type: 'code', content: '' }, + { type: 'code', content: '\n\n' }, { type: 'comment', content: '// Comment2\n// Comment2' } ], split = kssSplitter.pureSplitter(str); @@ -128,7 +128,7 @@ $a: b; result = [ { 'kss': '// Comment1\n// Styleguide 1.0', - 'code': '\n\n.a { b: c }\n' + 'code': '\n\n.a { b: c }\n\n' }, { 'kss': '// Comment2\n// Styleguide 2.0', @@ -159,11 +159,11 @@ $a: b; result = [ { 'kss': '// Comment1\n// Styleguide 1.0', - 'code': '\n\n.a { b: c }\n' + 'code': '\n\n.a { b: c }\n\n' }, { 'kss': '// Comment2\n// Styleguide 2.0', - 'code': '\n' + 'code': '\n\n' }, { 'kss': '// Comment3\n// Styleguide 3.0', @@ -192,11 +192,11 @@ $a: b; result = [ { 'kss': '// Comment\n// Styleguide 1', - 'code': '\n\n.a { b: c }\n' + 'code': '\n\n.a { b: c }\n\n' }, { 'kss': '// Comment\n// Styleguide 1.1', - 'code': '\n' + 'code': '\n\n' }, { 'kss': '// Comment\n// Styleguide 5.1.2.6', @@ -221,7 +221,7 @@ $a: b; result = [ { kss: '', - code: '\n.x { y: x }\n' + code: '.x { y: x }\n\n' }, { 'kss': '// Comment\n// Styleguide 1.0', @@ -320,7 +320,7 @@ multiline(function() { result = [ { 'kss': '/*\nComment1\nStyleguide 1.0\n*/', - 'code': '\n.a { b: c }\n' + 'code': '\n.a { b: c }\n\n' }, { 'kss': '/*\nComment2\nStyleguide 2.0\n*/', @@ -356,15 +356,15 @@ multiline(function() { result = [ { kss: '', - code: '\n@import "test";' + code: '@import "test";\n' }, { kss: '// Comment\n// Styleguide 1.0', - code: '\n\n.a { b: c }\n' + code: '\n\n.a { b: c }\n\n' }, { kss: '// Comment\n// Styleguide 2', - code: '\n' + code: '\n\n' }, { kss: '// Comment\n// Styleguide 2.0', @@ -398,15 +398,15 @@ a:before { content: "/* ..." } result = [ { kss: '', - code: '\n@import "test";' + code: '@import "test";\n' }, { kss: '// Comment\n// Styleguide 1.0', - code: '\n\n.a:before { content: "/* ..." }\n' + code: '\n\na:before { content: "/* ..." }\n\n' }, { kss: '// Comment\n// Styleguide 2', - code: '\n' + code: '\n\n' }, { kss: '// Comment\n// Styleguide 2.0', From b0bd7c6698c6f67954414aae6aa4f6a83f5eac91 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:38:58 +0200 Subject: [PATCH 05/10] Tests for tricky CSS content --- test/kss-splitter.js | 73 +++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index d0d80916..156c47f0 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -375,10 +375,11 @@ multiline(function() { expect(kssBlocks).eql(result); }); - it('should pasre compex CSS code', function() { - var str = multiline(function() { - /* -@import "test"; + describe('tricky CSS content', function() { + + it('should swallow content property with multiline comment', function() { + var str = multiline(function() { + /* // Comment // Styleguide 1.0 @@ -387,34 +388,44 @@ a:before { content: "/* ..." } // Comment // Styleguide 2 -// Comment -// Styleguide 2.0 - - -.a { b: c } + */ + }), + result = [ + { + kss: '// Comment\n// Styleguide 1.0', + code: '\n\na:before { content: "/* ..." }\n\n' + }, + { + kss: '// Comment\n// Styleguide 2', + code: '' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); + + it('should swallow content property with singleline comment', function() { + var str = multiline(function() { + /* +a:before { content: "// Comment inside content" } - */ - }), - result = [ - { - kss: '', - code: '@import "test";\n' - }, - { - kss: '// Comment\n// Styleguide 1.0', - code: '\n\na:before { content: "/* ..." }\n\n' - }, - { - kss: '// Comment\n// Styleguide 2', - code: '\n\n' - }, - { - kss: '// Comment\n// Styleguide 2.0', - code: '\n\n\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); +// Comment +// Styleguide 2 + */ + }), + result = [ + { + kss: '', + code: 'a:before { content: "// Comment inside content" }\n\n' + }, + { + kss: '// Comment\n// Styleguide 2', + code: '' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); }); }); From 4eb354d8c5aa994a4e23b70f1fe123da91b99e50 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:40:42 +0200 Subject: [PATCH 06/10] Detach tests for pure splitter --- test/kss-splitter.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index 156c47f0..b730a10f 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -7,25 +7,27 @@ var gulp = require('gulp'), describe('KSS splitter', function() { - it('Split 2 blocks of comments', function(){ - var str = multiline(function() { - /* + describe('Splitter module', function() { + it('Split 2 blocks of singleline comments', function(){ + var str = multiline(function() { + /* // Comment1 // Comment1 // Comment2 // Comment2 - */ - }), - result = [ - { type: 'comment', content: '// Comment1\n// Comment1' }, - { type: 'code', content: '\n\n' }, - { type: 'comment', content: '// Comment2\n// Comment2' } - ], - split = kssSplitter.pureSplitter(str); + */ + }), + result = [ + { type: 'comment', content: '// Comment1\n// Comment1' }, + { type: 'code', content: '\n\n' }, + { type: 'comment', content: '// Comment2\n// Comment2' } + ], + split = kssSplitter.pureSplitter(str); - expect(split).eql(result); + expect(split).eql(result); + }); }); it('should parse single KSS block', function() { From 9c4e857b0194a740a303f35a9a1d49ff25999542 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:41:44 +0200 Subject: [PATCH 07/10] Detach tests fo singleline comment blocks --- test/kss-splitter.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index b730a10f..1ca0165c 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -30,23 +30,25 @@ describe('KSS splitter', function() { }); }); - it('should parse single KSS block', function() { - var str = multiline(function() { - /* + describe('Singleline comment declarations', function() { + it('should parse single KSS block', function() { + var str = multiline(function() { + /* // Comment // Styleguide 1.0 .a { b: c } - */ - }), - result = [ - { - 'kss': '// Comment\n// Styleguide 1.0', - 'code': '\n\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); + */ + }), + result = [ + { + 'kss': '// Comment\n// Styleguide 1.0', + 'code': '\n\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); }); it('should be agnostic to spaces in reference declaration', function(){ From 30cc8f84f32297881d356ab59748b0132f8c2718 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:45:42 +0200 Subject: [PATCH 08/10] Tests for single line blocks of code in one place --- test/kss-splitter.js | 246 ++++++++++++++++++++++--------------------- 1 file changed, 124 insertions(+), 122 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index 1ca0165c..3c2be28a 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -49,30 +49,29 @@ describe('KSS splitter', function() { kssBlocks = kssSplitter.getBlocks(str); expect(kssBlocks).eql(result); }); - }); - it('should be agnostic to spaces in reference declaration', function(){ - var str = multiline(function() { - /* + it('should be agnostic to spaces in reference declaration', function(){ + var str = multiline(function() { + /* // Comment //Styleguide 1.0 .a { b: c } - */ - }), - result = [ - { - 'kss': '// Comment\n//Styleguide 1.0 ', - 'code': '\n\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment\n//Styleguide 1.0 ', + 'code': '\n\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should take multiline code', function(){ - var str = multiline(function() { - /* + it('should take multiline code', function(){ + var str = multiline(function() { + /* // Comment //Styleguide 1.0 @@ -80,21 +79,21 @@ describe('KSS splitter', function() { $a: b; .x { y: z } - */ - }), - result = [ - { - 'kss': '// Comment\n//Styleguide 1.0 ', - 'code': '\n\n.a { b: c }\n$a: b;\n\n.x { y: z }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment\n//Styleguide 1.0 ', + 'code': '\n\n.a { b: c }\n$a: b;\n\n.x { y: z }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should allow code blocks to have comments', function(){ - var str = multiline(function() { - /* + it('should allow code blocks to have not KSS comments', function(){ + var str = multiline(function() { + /* // Comment //Styleguide 1.0 @@ -103,21 +102,21 @@ $a: b; // Simple comment .x { y: z } - */ - }), - result = [ - { - 'kss': '// Comment\n//Styleguide 1.0 ', - 'code': '\n\n.a { b: c }\n\n// Simple comment\n\n.x { y: z }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment\n//Styleguide 1.0 ', + 'code': '\n\n.a { b: c }\n\n// Simple comment\n\n.x { y: z }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should parse several blocks', function(){ - var str = multiline(function() { - /* + it('should parse several blocks', function(){ + var str = multiline(function() { + /* // Comment1 // Styleguide 1.0 @@ -127,25 +126,25 @@ $a: b; // Styleguide 2.0 .x { y: z } - */ - }), - result = [ - { - 'kss': '// Comment1\n// Styleguide 1.0', - 'code': '\n\n.a { b: c }\n\n' - }, - { - 'kss': '// Comment2\n// Styleguide 2.0', - 'code': '\n\n.x { y: z }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment1\n// Styleguide 1.0', + 'code': '\n\n.a { b: c }\n\n' + }, + { + 'kss': '// Comment2\n// Styleguide 2.0', + 'code': '\n\n.x { y: z }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should allow blocks with no code', function(){ - var str = multiline(function() { - /* + it('should allow blocks with no code', function(){ + var str = multiline(function() { + /* // Comment1 // Styleguide 1.0 @@ -158,29 +157,29 @@ $a: b; // Styleguide 3.0 .x { y: z } - */ - }), - result = [ - { - 'kss': '// Comment1\n// Styleguide 1.0', - 'code': '\n\n.a { b: c }\n\n' - }, - { - 'kss': '// Comment2\n// Styleguide 2.0', - 'code': '\n\n' - }, - { - 'kss': '// Comment3\n// Styleguide 3.0', - 'code': '\n\n.x { y: z }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment1\n// Styleguide 1.0', + 'code': '\n\n.a { b: c }\n\n' + }, + { + 'kss': '// Comment2\n// Styleguide 2.0', + 'code': '\n\n' + }, + { + 'kss': '// Comment3\n// Styleguide 3.0', + 'code': '\n\n.x { y: z }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should take any reference number', function(){ - var str = multiline(function() { - /* + it('should take any reference number', function(){ + var str = multiline(function() { + /* // Comment // Styleguide 1 @@ -191,51 +190,54 @@ $a: b; // Comment // Styleguide 5.1.2.6 - */ - }), - result = [ - { - 'kss': '// Comment\n// Styleguide 1', - 'code': '\n\n.a { b: c }\n\n' - }, - { - 'kss': '// Comment\n// Styleguide 1.1', - 'code': '\n\n' - }, - { - 'kss': '// Comment\n// Styleguide 5.1.2.6', - 'code': '' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment\n// Styleguide 1', + 'code': '\n\n.a { b: c }\n\n' + }, + { + 'kss': '// Comment\n// Styleguide 1.1', + 'code': '\n\n' + }, + { + 'kss': '// Comment\n// Styleguide 5.1.2.6', + 'code': '' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should take code before first KSS block', function() { - var str = multiline(function() { - /* + it('should take code before first KSS block', function() { + var str = multiline(function() { + /* .x { y: x } // Comment // Styleguide 1.0 .a { b: c } - */ - }), - result = [ - { - kss: '', - code: '.x { y: x }\n\n' - }, - { - 'kss': '// Comment\n// Styleguide 1.0', - 'code': '\n\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); + */ + }), + result = [ + { + kss: '', + code: '.x { y: x }\n\n' + }, + { + 'kss': '// Comment\n// Styleguide 1.0', + 'code': '\n\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); + }); + it('should parse single KSS block in multiline comments', function() { var str = '' + '/* Comment\n' + From d8d368241bafe75413035130ea08a7b2575e7503 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:49:53 +0200 Subject: [PATCH 09/10] Tests for multiline declaration --- test/kss-splitter.js | 183 ++++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index 3c2be28a..18e713f6 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -238,107 +238,108 @@ $a: b; }); - it('should parse single KSS block in multiline comments', function() { - var str = '' + -'/* Comment\n' + -'Styleguide 1.0\n' + -'*/\n' + -'\n' + -'.a { b: c }', - result = [ - { - 'kss': '/* Comment\nStyleguide 1.0\n*/', - 'code': '\n\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + describe('Multiline comment declarations', function() { + + it('should parse single KSS block in multiline comments', function() { + var str = '' + + '/* Comment\n' + + 'Styleguide 1.0\n' + + '*/\n' + + '\n' + + '.a { b: c }', + result = [ + { + 'kss': '/* Comment\nStyleguide 1.0\n*/', + 'code': '\n\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should parse multiline KSS with no ending linebreak', function() { - var str = '' + -'/* Comment\n' + -'Styleguide 1.0 */' + -'\n' + -'.a { b: c }', - result = [ - { - 'kss': '/* Comment\nStyleguide 1.0 */', - 'code': '\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); - it('should parse multiline KSS with string prefixes', function() { - var str = '' + -'/* Comment\n' + -' * Styleguide 1.0\n' + -'*/' + -'\n' + -'.a { b: c }', - result = [ - { - 'kss': '/* Comment\n * Styleguide 1.0\n*/', - 'code': '\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + it('should parse multiline KSS with no ending linebreak', function() { + var str = '' + + '/* Comment\n' + + 'Styleguide 1.0 */' + + '\n' + + '.a { b: c }', + result = [ + { + 'kss': '/* Comment\nStyleguide 1.0 */', + 'code': '\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); + it('should parse multiline KSS with string prefixes', function() { + var str = '' + + '/* Comment\n' + + ' * Styleguide 1.0\n' + + '*/' + + '\n' + + '.a { b: c }', + result = [ + { + 'kss': '/* Comment\n * Styleguide 1.0\n*/', + 'code': '\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should allow code blocks to have multiline comments', function(){ - var str = multiline(function() { - /* + it('should allow code blocks to have multiline comments', function(){ + var str = multiline(function() { + /* // Comment //Styleguide 1.0 .a { b: c } - */}) + -'\n\n/* Simple comment */\n\n' + -multiline(function() { - /* + */}) + + '\n\n/* Simple comment */\n\n' + + multiline(function() { + /* .x { y: z } - */ - }), - result = [ - { - 'kss': '// Comment\n//Styleguide 1.0 ', - 'code': '\n\n.a { b: c }\n\n/* Simple comment */\n\n.x { y: z }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); + */ + }), + result = [ + { + 'kss': '// Comment\n//Styleguide 1.0 ', + 'code': '\n\n.a { b: c }\n\n/* Simple comment */\n\n.x { y: z }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); - it('should parse several KSS blocks with multiline comments', function(){ - var str = '/*\n' + -'Comment1\n' + -'Styleguide 1.0\n' + -'*/\n' + -'.a { b: c }\n' + -'\n' + -'/*\n' + -'Comment2\n' + -'Styleguide 2.0\n' + -'*/' - '', - result = [ - { - 'kss': '/*\nComment1\nStyleguide 1.0\n*/', - 'code': '\n.a { b: c }\n\n' - }, - { - 'kss': '/*\nComment2\nStyleguide 2.0\n*/', - 'code': '' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); + it('should parse several KSS blocks with multiline comments', function(){ + var str = '/*\n' + + 'Comment1\n' + + 'Styleguide 1.0\n' + + '*/\n' + + '.a { b: c }\n' + + '\n' + + '/*\n' + + 'Comment2\n' + + 'Styleguide 2.0\n' + + '*/' + '', + result = [ + { + 'kss': '/*\nComment1\nStyleguide 1.0\n*/', + 'code': '\n.a { b: c }\n\n' + }, + { + 'kss': '/*\nComment2\nStyleguide 2.0\n*/', + 'code': '' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); }); - /* TODO: Parser does not work with code after 2nd code block */ - it('should return array of blocks', function() { var str = multiline(function() { /* From 2ce75a64970eda054ff1f59475e0b529117a33e1 Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Wed, 12 Nov 2014 15:52:24 +0200 Subject: [PATCH 10/10] Move test under proper "describe" --- test/kss-splitter.js | 84 ++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/test/kss-splitter.js b/test/kss-splitter.js index 18e713f6..350d046b 100644 --- a/test/kss-splitter.js +++ b/test/kss-splitter.js @@ -142,6 +142,48 @@ $a: b; expect(kssBlocks).eql(result); }); + it('should parse several blocks 2', function() { + var str = multiline(function() { + /* +@import "test"; +// Comment +// Styleguide 1.0 + +.a { b: c } + +// Comment +// Styleguide 2 + +// Comment +// Styleguide 2.0 + + +.a { b: c } + + */ + }), + result = [ + { + kss: '', + code: '@import "test";\n' + }, + { + kss: '// Comment\n// Styleguide 1.0', + code: '\n\n.a { b: c }\n\n' + }, + { + kss: '// Comment\n// Styleguide 2', + code: '\n\n' + }, + { + kss: '// Comment\n// Styleguide 2.0', + code: '\n\n\n.a { b: c }' + } + ], + kssBlocks = kssSplitter.getBlocks(str); + expect(kssBlocks).eql(result); + }); + it('should allow blocks with no code', function(){ var str = multiline(function() { /* @@ -340,48 +382,6 @@ $a: b; }); }); - it('should return array of blocks', function() { - var str = multiline(function() { - /* -@import "test"; -// Comment -// Styleguide 1.0 - -.a { b: c } - -// Comment -// Styleguide 2 - -// Comment -// Styleguide 2.0 - - -.a { b: c } - - */ - }), - result = [ - { - kss: '', - code: '@import "test";\n' - }, - { - kss: '// Comment\n// Styleguide 1.0', - code: '\n\n.a { b: c }\n\n' - }, - { - kss: '// Comment\n// Styleguide 2', - code: '\n\n' - }, - { - kss: '// Comment\n// Styleguide 2.0', - code: '\n\n\n.a { b: c }' - } - ], - kssBlocks = kssSplitter.getBlocks(str); - expect(kssBlocks).eql(result); - }); - describe('tricky CSS content', function() { it('should swallow content property with multiline comment', function() {