-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from reworkcss/refactoring
Small refactoring + error reporting
- Loading branch information
Showing
15 changed files
with
136 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
{ | ||
"name": "rework-calc", | ||
"version": "0.2.2", | ||
"description": "Adding calc() support to rework", | ||
"main": "index.js", | ||
"description": "calc() support for Rework", | ||
"dependencies": { | ||
"balanced-match": "^0.1.0", | ||
"rework-visit": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.15.1", | ||
"rework": "^1.0.0", | ||
"chai": "~1.8.1" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha -R spec" | ||
"test": "mocha --no-colors", | ||
"watch": "mocha --slow 30 --reporter spec --watch" | ||
}, | ||
"repository": "git://github.com/rework/rework-calc.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/reworkcss/rework-calc.git" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"css", | ||
"rework", | ||
"rework-plugins", | ||
"css", | ||
"calculation", | ||
"calc" | ||
], | ||
"author": "Joakim Bengtson <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"mocha": "~1.15.1", | ||
"rework": "~0.18.3", | ||
"chai": "~1.8.1" | ||
} | ||
] | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
div { | ||
width: calc(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
div { | ||
/* missing closing ')' */ | ||
width: calc(10px - 5px; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var calc = require('../index'), | ||
rework = require('rework'), | ||
expect = require('chai').expect, | ||
read = require('fs').readFileSync; | ||
|
||
function fixture(name){ | ||
return read('test/fixtures/' + name + '.css', 'utf8').trim(); | ||
} | ||
|
||
function compareFixtures(name){ | ||
return expect( | ||
rework(fixture(name + '.in')) | ||
.use(calc) | ||
.toString().trim() | ||
).to.equal(fixture(name + '.out')); | ||
} | ||
|
||
describe('rework-calc', function() { | ||
it('throws an error when a calc function is empty', function () { | ||
var output = function () { | ||
return rework(fixture('substitution-empty')).use(calc).toString(); | ||
}; | ||
expect(output).to.Throw(Error, 'rework-calc: calc() must contain a non-whitespace string'); | ||
}); | ||
|
||
it('throws an error when a calc function is malformed', function () { | ||
var output = function () { | ||
return rework(fixture('substitution-malformed')).use(calc).toString(); | ||
}; | ||
expect(output).to.Throw(Error, 'rework-calc: missing closing ")" in the value "calc(10px - 5px"'); | ||
}); | ||
|
||
|
||
it('should calculate expressions with only one unit involved', function() { | ||
compareFixtures('calc'); | ||
}); | ||
|
||
it('should calculate expressions with percents correctly', function () { | ||
compareFixtures('calc-percent'); | ||
}); | ||
|
||
it('should use CSS3 Calc function as fallback for expressions with multiple units', function () { | ||
compareFixtures('calc-complex'); | ||
}); | ||
|
||
it('should handle vendor prefixed expressions', function () { | ||
compareFixtures('calc-prefix'); | ||
}); | ||
}); |