2014-12-20 02:49:11 +00:00
|
|
|
import javascript from 'src/js/parser/javascript/parser.js';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import Snap from 'snapsvg';
|
|
|
|
|
2014-12-21 16:24:23 +00:00
|
|
|
describe('parser/javascript/escape.js', function() {
|
2014-12-20 02:49:11 +00:00
|
|
|
|
|
|
|
_.forIn({
|
2014-12-22 17:44:19 +00:00
|
|
|
'\\b': { label: 'word boundary', ordinal: -1 },
|
|
|
|
'\\B': { label: 'non-word boundary', ordinal: -1 },
|
|
|
|
'\\d': { label: 'digit', ordinal: -1 },
|
|
|
|
'\\D': { label: 'non-digit', ordinal: -1 },
|
|
|
|
'\\f': { label: 'form feed', ordinal: 0x0c },
|
|
|
|
'\\n': { label: 'line feed', ordinal: 0x0a },
|
|
|
|
'\\r': { label: 'carriage return', ordinal: 0x0d },
|
|
|
|
'\\s': { label: 'white space', ordinal: -1 },
|
|
|
|
'\\S': { label: 'non-white space', ordinal: -1 },
|
|
|
|
'\\t': { label: 'tab', ordinal: 0x09 },
|
|
|
|
'\\v': { label: 'vertical tab', ordinal: 0x0b },
|
|
|
|
'\\w': { label: 'word', ordinal: -1 },
|
|
|
|
'\\W': { label: 'non-word', ordinal: -1 },
|
|
|
|
'\\0': { label: 'null', ordinal: 0 },
|
|
|
|
'\\1': { label: 'Back reference (group = 1)', ordinal: -1 },
|
|
|
|
'\\2': { label: 'Back reference (group = 2)', ordinal: -1 },
|
|
|
|
'\\3': { label: 'Back reference (group = 3)', ordinal: -1 },
|
|
|
|
'\\4': { label: 'Back reference (group = 4)', ordinal: -1 },
|
|
|
|
'\\5': { label: 'Back reference (group = 5)', ordinal: -1 },
|
|
|
|
'\\6': { label: 'Back reference (group = 6)', ordinal: -1 },
|
|
|
|
'\\7': { label: 'Back reference (group = 7)', ordinal: -1 },
|
|
|
|
'\\8': { label: 'Back reference (group = 8)', ordinal: -1 },
|
|
|
|
'\\9': { label: 'Back reference (group = 9)', ordinal: -1 },
|
|
|
|
'\\012': { label: 'octal: 12', ordinal: 10 },
|
2014-12-22 20:11:20 +00:00
|
|
|
'\\cx': { label: 'ctrl-X', ordinal: 24 },
|
2014-12-22 17:44:19 +00:00
|
|
|
'\\xab': { label: '0xAB', ordinal: 0xab },
|
|
|
|
'\\uabcd': { label: 'U+ABCD', ordinal: 0xabcd }
|
|
|
|
}, (content, str) => {
|
2014-12-20 02:49:11 +00:00
|
|
|
it(`parses "${str}" as an Escape`, function() {
|
|
|
|
var parser = new javascript.Parser(str);
|
2014-12-22 17:44:19 +00:00
|
|
|
expect(parser.__consume__terminal()).toEqual(jasmine.objectContaining(content));
|
2014-12-20 02:49:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#_render', function() {
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
var parser = new javascript.Parser('\\b');
|
|
|
|
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();
|
|
|
|
expect(this.node.renderLabel).toHaveBeenCalledWith('word boundary');
|
|
|
|
});
|
|
|
|
|
|
|
|
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'
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
.done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|