2015-10-31 16:09:38 +00:00
|
|
|
import javascript from '../../../src/js/parser/javascript/parser.js';
|
2014-12-20 02:35:03 +00:00
|
|
|
import Snap from 'snapsvg';
|
|
|
|
|
2014-12-21 16:24:23 +00:00
|
|
|
describe('parser/javascript/literal.js', function() {
|
2014-12-20 02:35:03 +00:00
|
|
|
|
|
|
|
it('parses "x" as a Literal', function() {
|
|
|
|
var parser = new javascript.Parser('x');
|
|
|
|
expect(parser.__consume__terminal()).toEqual(jasmine.objectContaining({
|
|
|
|
type: 'literal',
|
2014-12-22 20:11:37 +00:00
|
|
|
literal: 'x',
|
|
|
|
ordinal: 120
|
2014-12-20 02:35:03 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('parses "\\x" as a Literal', function() {
|
|
|
|
var parser = new javascript.Parser('\\x');
|
|
|
|
expect(parser.__consume__terminal()).toEqual(jasmine.objectContaining({
|
|
|
|
type: 'literal',
|
2014-12-22 20:11:37 +00:00
|
|
|
literal: 'x',
|
|
|
|
ordinal: 120
|
2014-12-20 02:35:03 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#_render', function() {
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
var parser = new javascript.Parser('a');
|
|
|
|
this.node = parser.__consume__terminal();
|
|
|
|
this.node.state = {};
|
|
|
|
|
|
|
|
this.svg = Snap(document.createElement('svg'));
|
|
|
|
this.node.container = this.svg.group();
|
|
|
|
spyOn(this.node, 'renderLabel').and.callThrough();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a label', function() {
|
|
|
|
this.node._render();
|
2014-12-21 06:54:12 +00:00
|
|
|
expect(this.node.renderLabel).toHaveBeenCalledWith(['\u201c', 'a', '\u201d']);
|
2014-12-20 02:35:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the class of the first and third tspan to "quote"', function(done) {
|
|
|
|
this.node._render()
|
|
|
|
.then(label => {
|
|
|
|
expect(label.selectAll('tspan')[0].hasClass('quote')).toBeTruthy();
|
|
|
|
expect(label.selectAll('tspan')[2].hasClass('quote')).toBeTruthy();
|
2015-03-14 21:11:14 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-12-20 02:35:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the edge radius of the rect', function(done) {
|
|
|
|
this.node._render()
|
|
|
|
.then(label => {
|
|
|
|
expect(label.select('rect').attr()).toEqual(jasmine.objectContaining({
|
|
|
|
rx: '3',
|
|
|
|
ry: '3'
|
|
|
|
}));
|
2015-03-14 21:11:14 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-12-20 02:35:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#merge', function() {
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
var parser = new javascript.Parser('a');
|
|
|
|
this.node = parser.__consume__terminal();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('appends to the literal value', function() {
|
|
|
|
this.node.merge({ literal: 'b' });
|
|
|
|
expect(this.node.literal).toEqual('ab');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|