Skip to content

Commit 8868ddb

Browse files
committed
Implement tests.
1 parent f7e0739 commit 8868ddb

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

test/fixtures/url.css

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@import url("/style.css") print;
2+
@import url("/style.css") projection, tv;
3+
@import '/style.css';
4+
@import "/style.css" screen, projection;
5+
@import url('/style.css') screen and (orientation:landscape);
6+
7+
body {
8+
background: url('/images/bg.png') repeat-x;
9+
}
10+
11+
#logo {
12+
background: url(/images/logo.jpeg);
13+
}
14+
15+
@font-face {
16+
font-family: 'icons';
17+
src: url("/icons/font/icons.eot");
18+
src: url("/icons/font/icons.eot?#iefix")
19+
format('embedded-opentype'),
20+
url("/icons/font/icons.woff")
21+
format('woff'),
22+
url("/icons/font/icons.ttf")
23+
format('truetype'),
24+
url("/icons/font/icons.svg#icons") format('svg');
25+
font-weight: normal;
26+
font-style: normal
27+
}
28+
29+
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
30+
#logo {
31+
background-image: url("/core/[email protected]")
32+
}
33+
}

test/fixtures/url.out.css

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@import url("http://example.com/style.css") print;
2+
@import url("http://example.com/style.css") projection, tv;
3+
@import url("http://example.com/style.css");
4+
@import url("http://example.com/style.css") screen, projection;
5+
@import url("http://example.com/style.css") screen and (orientation:landscape);
6+
7+
body {
8+
background: url("http://example.com/images/bg.png") repeat-x;
9+
}
10+
11+
#logo {
12+
background: url("http://example.com/images/logo.jpeg");
13+
}
14+
15+
@font-face {
16+
font-family: 'icons';
17+
src: url("http://example.com/icons/font/icons.eot");
18+
src: url("http://example.com/icons/font/icons.eot?#iefix")
19+
format('embedded-opentype'),
20+
url("http://example.com/icons/font/icons.woff")
21+
format('woff'),
22+
url("http://example.com/icons/font/icons.ttf")
23+
format('truetype'),
24+
url("http://example.com/icons/font/icons.svg#icons") format('svg');
25+
font-weight: normal;
26+
font-style: normal
27+
}
28+
29+
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
30+
#logo {
31+
background-image: url("http://example.com/core/[email protected]")
32+
}
33+
}

test/fixtures/url.spaces.css

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@import url( "/style.css" ) print;
2+
@import url( "/style.css" ) projection, tv;
3+
@import '/style.css';
4+
@import "/style.css" screen, projection;
5+
@import url( '/style.css' ) screen and (orientation:landscape);
6+
7+
body {
8+
background: url(' /images/bg.png' ) repeat-x;
9+
}
10+
11+
#logo {
12+
background: url( /images/logo.jpeg );
13+
}
14+
15+
@font-face {
16+
font-family: 'icons';
17+
src: url( "/icons/font/icons.eot" );
18+
src: url( "/icons/font/icons.eot?#iefix" )
19+
format('embedded-opentype'),
20+
url( "/icons/font/icons.woff" )
21+
format('woff'),
22+
url( "/icons/font/icons.ttf" )
23+
format('truetype'),
24+
url( "/icons/font/icons.svg#icons" ) format('svg');
25+
font-weight: normal;
26+
font-style: normal
27+
}
28+
29+
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
30+
#logo {
31+
background-image: url( "/core/[email protected]" )
32+
}
33+
}

test/test.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var should = require('should');
2+
var fs = require('fs');
3+
var rewriteCssUrls = require('../');
4+
5+
function fixture (name) {
6+
return fs.readFileSync('test/fixtures/' + name + '.css', 'utf8').trim();
7+
}
8+
9+
describe('rewriteCssUrls(css, fn)', function () {
10+
it('should rewrite urls', function () {
11+
function rewrite (url) {
12+
return 'http://example.com' + url;
13+
}
14+
15+
rewriteCssUrls(fixture('url'), rewrite)
16+
.should.equal(fixture('url.out'));
17+
});
18+
});
19+
20+
describe('rewriteCssUrls(css, fn) spaces inside parentheses', function () {
21+
it('should rewrite urls', function () {
22+
function rewrite (url) {
23+
return 'http://example.com' + url;
24+
}
25+
26+
rewriteCssUrls(fixture('url.spaces'), rewrite)
27+
.should.equal(fixture('url.out'));
28+
});
29+
});

0 commit comments

Comments
 (0)