Skip to content

Commit

Permalink
Add tests for windows linebreak support #530
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pelkonen committed Mar 30, 2015
1 parent 019c4cb commit bbb76fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/modules/kss-additional-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ function trimLinebreaks(str) {
return str.replace(/^[\r\n]+|[\r\n]+$/g, '');
}

function standardizeLinebreaks(str) {
// Replace windows and mac line endings to unix line endings convention
if (!str) {
return str;
}
return str.replace(/\r?\n|\r/g, '\n');
}

// A list of params which need values parsing
var ComplexParams = [
'sg-angular-directive'
Expand All @@ -23,6 +31,7 @@ module.exports = {
additionalKssParams = {},
_this = this;

comment = standardizeLinebreaks(comment);
comment = trimLinebreaks(comment);

comment.split('\n\n').forEach(function(markUpBlock) {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/modules/kss-additional-params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe('Parsing KSS additional params', function() {
expect(params).eql(result);
});

it('should parse windows linebreaks correctly', function() {
// jscs:disable
var str = "/*\r\n// sg-param:\r\n// Value\r\n*/\r\n";
var str2 = "/*\r// sg-param:\r// Value\r*/\r";
// jscs:enable
result = { 'sg-param': ' Value' },
expect(kssAdditionalParams.get(str)).eql(result);
expect(kssAdditionalParams.get(str2)).eql(result);
});

it('Should parse from multiline-commented block', function() {
var str = '' +
'/*\n' +
Expand Down

0 comments on commit bbb76fb

Please sign in to comment.