Skip to content

Commit

Permalink
Testcases for indented syntax
Browse files Browse the repository at this point in the history
sass-graph should understand idented
syntax better.

sass/node-sass#1179
  • Loading branch information
saper committed Sep 25, 2015
1 parent ef9980a commit 42dd71b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
2 changes: 2 additions & 0 deletions test/fixtures-indent/_more.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
p
background: black
2 changes: 2 additions & 0 deletions test/fixtures-indent/components/_sassy.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body
background: purple
2 changes: 2 additions & 0 deletions test/fixtures-indent/sample.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import components/sassy
@import more
39 changes: 26 additions & 13 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@
var assert = require("assert");
var path = require("path");

var fixtures = path.resolve("test/fixtures");
var fixtures = path.resolve(path.join("test", "fixtures")),
sass_fixtures = path.resolve(path.join("test", "fixtures-indent"));
var files = {
'a.scss': path.join(fixtures, 'a.scss'),
'b.scss': path.join(fixtures, 'b.scss'),
'_c.scss': path.join(fixtures, '_c.scss'),
'd.scss': path.join(fixtures, 'd.scss'),
'_e.scss': path.join(fixtures, 'components/_e.scss'),
'_e.scss': path.join(fixtures, 'components', '_e.scss'),
'f.scss': path.join(fixtures, 'f.scss'),
'g.scss': path.join(fixtures, 'g.scss'),
'_h.scss': path.join(fixtures, 'nested/_h.scss'),
'_i.scss': path.join(fixtures, 'nested/_i.scss'),
'i.scss': path.join(fixtures, '_i.scss'),
'j.scss': path.join(fixtures, 'j.scss'),
'k.l.scss': path.join(fixtures, 'components/k.l.scss'),
'k.l.scss': path.join(fixtures, 'components', 'k.l.scss'),
'm.scss': path.join(fixtures, 'm.scss'),
'_n.scss': path.join(fixtures, 'compass/_n.scss'),
'_compass.scss': path.join(fixtures, 'components/_compass.scss')
}
'_compass.scss': path.join(fixtures, 'components', '_compass.scss')
};
var sassfiles = {
'sample.sass': path.join(sass_fixtures, 'sample.sass'),
'_sassy.sass': path.join(sass_fixtures, 'components', '_sassy.sass'),
'_more.sass': path.join(sass_fixtures, '_more.sass')
};

describe('sass-graph', function(){
var sassGraph = require('../sass-graph');

describe('parsing a graph of all scss files', function(){
var graph = sassGraph.parseDir(fixtures, {loadPaths: [fixtures + '/components']});
var graph = sassGraph.parseDir(fixtures, {loadPaths: [path.join(fixtures, 'components')]});

it('should have all files', function(){
assert.equal(Object.keys(files).length, Object.keys(graph.index).length);
Expand Down Expand Up @@ -83,11 +89,9 @@ describe('sass-graph', function(){
});
assert.equal(expectedDescendents.length, descendents.length);
});
});

describe('parseFile', function () {
it('should parse imports with loadPaths', function () {
var graph = sassGraph.parseFile(files['d.scss'], {loadPaths: [fixtures + '/components']} );
var graph = sassGraph.parseFile(files['d.scss'], {loadPaths: [path.join(fixtures, 'components')]} );
var expectedDescendents = [files['_e.scss']];
var descendents = [];
graph.visitDescendents(files['d.scss'], function (imp) {
Expand All @@ -96,19 +100,28 @@ describe('sass-graph', function(){
});
assert.equal(expectedDescendents.length, descendents.length);
});
});

describe('parseFile', function () {
it('should parse sass import', function () {
var graph = sassGraph.parseFile(sassfiles['sample.sass'], {
extensions: ['sass']
});
var expectedDescendents = [sassfiles['_sassy.sass'], sassfiles['_more.sass']];
var descendents = [];
graph.visitDescendents(sassfiles['sample.sass'], function (imp) {
descendents.push(imp);
assert.notEqual(expectedDescendents.indexOf(imp), -1);
});
assert.equal(expectedDescendents.length, descendents.length);
});

it('should thow an error', function () {
try {
var graph = sassGraph.parseFile(files['d.scss']);
} catch (e) {
assert.equal(e, "File to import not found or unreadable: e");
}
});
});

describe('parseFile', function () {
it('should not throw an error for a file with no dependencies with Array having added functions', function () {
try {
Array.prototype.foo = function() {
Expand Down
15 changes: 14 additions & 1 deletion test/test.parse-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ describe('parse-imports', function () {
assert.equal(result[0], "app");
});

it('should parse single import without quotes', function () {
var sass = "@import app";
var result = parseImports(sass);
assert.equal(result.length, 1);
assert.equal(result[0], "app");
});

it('should not parse single import without quotes with SCSS', function () {
var sass = "@import app;";
var result = parseImports(sass);
assert.equal(result.length, 0);
});

it('should parse single import with double quotes', function () {
var scss = '@import "app"; ';
var result = parseImports(scss);
Expand Down Expand Up @@ -70,4 +83,4 @@ describe('parse-imports', function () {
});


});
});

0 comments on commit 42dd71b

Please sign in to comment.