Adding tests for Root nodes

This commit is contained in:
Jeff Avallone
2014-12-22 20:35:49 -05:00
parent f842b424cc
commit e3eedb17af
3 changed files with 195 additions and 42 deletions
+22 -41
View File
@@ -3,62 +3,43 @@ import _ from 'lodash';
export default {
type: 'root',
flagLabels: {
i: 'Ignore Case',
g: 'Global',
m: 'Multiline'
},
_render() {
var flagLabels = [];
var flagText;
if (this.flags.global) {
flagLabels.push('Global');
if (this.flags.length > 0) {
flagText = this.container.text(0, 0, `Flags: ${this.flags.join(', ')}`);
}
if (this.flags.ignore_case) {
flagLabels.push('Ignore Case');
}
if (this.flags.multiline) {
flagLabels.push('Multiline');
}
if (flagLabels.length > 0) {
this.flagText = this.container.text(0, 0, `Flags: ${flagLabels.join(', ')}`);
}
this.start = this.container.circle()
.addClass('pin')
.attr({ r: 5 });
this.end = this.container.circle()
.addClass('pin')
.attr({ r: 5 });
return this.regexp.render(this.container.group())
.then(() => {
var box,
offset = 0;
var box;
if (this.flagText) {
offset = this.flagText.getBBox().height;
if (flagText) {
this.regexp.transform(Snap.matrix()
.translate(10, flagText.getBBox().height));
} else {
this.regexp.transform(Snap.matrix()
.translate(10, 0));
}
this.regexp.transform(Snap.matrix()
.translate(10, offset));
box = this.regexp.getBBox();
this.start.transform(Snap.matrix()
.translate(0, box.ay));
this.end.transform(Snap.matrix()
.translate(box.x2 + 10, box.ay));
this.container.prepend(
this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`));
this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`);
this.container.circle(0, box.ay, 5);
this.container.circle(box.x2 + 10, box.ay, 5);
});
},
setup() {
var flagsStr = this.properties.flags.textValue;
this.flags = {
global: /g/.test(flagsStr),
ignore_case: /i/.test(flagsStr),
multiline: /m/.test(flagsStr)
};
this.flags = _(this.properties.flags.textValue).unique().sort().map(flag => {
return this.flagLabels[flag];
}).value();
this.regexp = this.properties.regexp
}
+1 -1
View File
@@ -14,7 +14,7 @@ path {
stroke: $black;
}
circle.pin {
circle {
fill: $gray;
stroke-width: 2px;
stroke: $black;