2014-09-19 08:07:31 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var expect = require('expect.js');
|
2021-03-15 13:52:59 +00:00
|
|
|
var gradients = require('../build/node');
|
2014-09-19 08:07:31 +00:00
|
|
|
|
2014-09-20 09:37:41 +00:00
|
|
|
function pprint(ast) {
|
|
|
|
console.log(JSON.stringify(ast, true, 2));
|
|
|
|
}
|
|
|
|
|
2014-09-19 08:07:31 +00:00
|
|
|
describe('lib/stringify.js', function () {
|
|
|
|
var subject;
|
|
|
|
|
|
|
|
it('should exist', function () {
|
|
|
|
expect(typeof gradients.stringify).to.equal('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('serialization', function() {
|
|
|
|
|
|
|
|
it('if tree is null', function() {
|
|
|
|
expect(gradients.stringify(null)).to.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serialize a simple gradient', function() {
|
|
|
|
var gradientDef = 'linear-gradient(black, white)';
|
|
|
|
expect(gradients.stringify(gradients.parse(gradientDef))).to.equal(gradientDef);
|
|
|
|
});
|
|
|
|
|
2014-09-19 17:36:13 +00:00
|
|
|
it('should serialize gradient with hex', function() {
|
|
|
|
var gradientDef = 'linear-gradient(#fff, white)';
|
|
|
|
expect(gradients.stringify(gradients.parse(gradientDef))).to.equal(gradientDef);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serialize gradient with rgb', function() {
|
|
|
|
var gradientDef = 'linear-gradient(rgb(1, 2, 3), white)';
|
|
|
|
expect(gradients.stringify(gradients.parse(gradientDef))).to.equal(gradientDef);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serialize gradient with rgba', function() {
|
|
|
|
var gradientDef = 'linear-gradient(rgba(1, 2, 3, .0), white)';
|
|
|
|
expect(gradients.stringify(gradients.parse(gradientDef))).to.equal(gradientDef);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serialize gradient with deg', function() {
|
|
|
|
var gradientDef = 'linear-gradient(45deg, #fff, transparent)';
|
|
|
|
expect(gradients.stringify(gradients.parse(gradientDef))).to.equal(gradientDef);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should serialize gradient with directional', function() {
|
|
|
|
var gradientDef = 'linear-gradient(to left, #fff, transparent)';
|
|
|
|
expect(gradients.stringify(gradients.parse(gradientDef))).to.equal(gradientDef);
|
|
|
|
});
|
|
|
|
|
2014-09-20 09:37:41 +00:00
|
|
|
describe('all metric values', function() {
|
|
|
|
[
|
|
|
|
'px',
|
|
|
|
'em',
|
|
|
|
'%'
|
|
|
|
].forEach(function(metric) {
|
|
|
|
var expectedResult;
|
|
|
|
|
|
|
|
describe('stringify color stop for metric '+ metric, function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
expectedResult = 'linear-gradient(blue 10.3' + metric + ', transparent)';
|
|
|
|
var ast = gradients.parse(expectedResult);
|
|
|
|
subject = gradients.stringify(ast);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should result as expected', function() {
|
|
|
|
expect(subject).to.equal(expectedResult);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('different radial declarations', function() {
|
|
|
|
[
|
|
|
|
'ellipse farthest-corner',
|
|
|
|
'ellipse cover',
|
|
|
|
'circle cover',
|
|
|
|
'center bottom, ellipse cover',
|
2016-01-10 12:25:58 +00:00
|
|
|
'circle at 87.23px -58.3px',
|
|
|
|
'farthest-corner, red, blue',
|
|
|
|
'farthest-corner at 87.23px -58.3px, red, blue'
|
2014-09-20 09:37:41 +00:00
|
|
|
].forEach(function(declaration) {
|
|
|
|
|
|
|
|
it('should parse ' + declaration + ' declaration', function() {
|
|
|
|
var expectedResult = 'radial-gradient(' + declaration + ', red, blue)';
|
|
|
|
var ast = gradients.parse(expectedResult);
|
|
|
|
subject = gradients.stringify(ast);
|
|
|
|
|
|
|
|
expect(subject).to.equal(expectedResult);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-19 08:07:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|