Skip to content

Instantly share code, notes, and snippets.

@ignovak
Created July 1, 2013 12:40
Show Gist options
  • Save ignovak/5900429 to your computer and use it in GitHub Desktop.
Save ignovak/5900429 to your computer and use it in GitHub Desktop.
var css = [
["background: url('pic.png');", "background: url('../../common.blocks/pic/pic.png');"],
["background: #fff url('pic.png');", "background: #fff url('../../common.blocks/pic/pic.png');"],
["background: url('pic.png') #fff;", "background: url('../../common.blocks/pic/pic.png') #fff;"],
["background: url('http://ya.ru/pic.png');", "background: url('http://ya.ru/pic.png');"],
["background: url('//ya.ru/pic.png');", "background: url('//ya.ru/pic.png');"],
["background-image: url('pic.png');", "background-image: url('../../common.blocks/pic/pic.png');"],
["background: url('pic.png');background: url('pic.png');", "background: url('../../common.blocks/pic/pic.png');background: url('../../common.blocks/pic/pic.png');"],
["background: url(pic.png);", "background: url(../../common.blocks/pic/pic.png);"],
["background: #fff url(pic.png);", "background: #fff url(../../common.blocks/pic/pic.png);"],
["background: url(pic.png) #fff;", "background: url(../../common.blocks/pic/pic.png) #fff;"],
["background: url(http://ya.ru/pic.png);", "background: url(http://ya.ru/pic.png);"],
["background: url(//ya.ru/pic.png);", "background: url(//ya.ru/pic.png);"],
["background-image: url(pic.png);", "background-image: url(../../common.blocks/pic/pic.png);"],
["background: url(pic.png);background: url(pic.png);", "background: url(../../common.blocks/pic/pic.png);background: url(../../common.blocks/pic/pic.png);"],
["background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20rl(%23l)20fill%3D%22none%22%2F%3E%3C%2Fsvg%3E');", "background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20rl(%23l)20fill%3D%22none%22%2F%3E%3C%2Fsvg%3E');"],
],
count = 0,
CssPreprocessor = require('./lib/preprocess/css-preprocessor'),
preprocessCss = new CssPreprocessor();
preprocessCss.setCssRelativeUrlBuilder(function(path) {
return '../../common.blocks/pic/' + path;
});
css.forEach(function(item) {
check(item[1], preprocessCss._processUrls(item[0], '../../common.blocks/pic/'));
count++;
});
console.log('\033[32m%s tests passed\033[0m', count);
function check(expected, result) {
console.assert(expected == result, '\nexpected: \033[31m' + expected, '\n\nresult: ' + result + '\033[0m')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment