Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for windows linebreak support, PR #530 #535

Merged
merged 1 commit into from
Mar 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 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,17 @@ describe('Parsing KSS additional params', function() {
expect(params).eql(result);
});

it('should parse windows linebreaks correctly', function() {
// jscs:disable
/*jshint -W109 */
var str = "/*\r\n// sg-param:\r\n// Value\r\n*/\r\n",
str2 = "/*\r// sg-param:\r// Value\r*/\r",
result = { 'sg-param': ' Value' };
// jscs:enable
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