Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mscgenjs

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mscgenjs - npm Package Compare versions

Comparing version 1.2.10 to 1.3.0

npm-shrinkwrap.json

10

package.json
{
"name": "mscgenjs",
"version": "1.2.10",
"version": "1.3.0",
"description": "Implementation of MscGen in JavaScript",

@@ -16,7 +16,7 @@ "main": "index.js",

"istanbul": "0.4.2",
"js-makedepend": "0.2.0",
"jscs": "2.9.0",
"jsdom": "8.0.2",
"js-makedepend": "0.2.1",
"jscs": "2.10.1",
"jsdom": "8.0.4",
"jshint": "2.9.1",
"lodash-cli": "4.2.1",
"lodash-cli": "4.5.1",
"mocha": "2.4.5",

@@ -23,0 +23,0 @@ "npm-check-updates": "2.5.8",

@@ -131,4 +131,4 @@ # mscgen_js - core package

[mscgenjs.wikum.xu]: wikum/xu.md
[pegjs]: http://majda.cz/en/
[pegjs.author]: http://pegjs.majda.cz/
[pegjs]: http://pegjs.org
[pegjs.author]: http://majda.cz/about
[pegjs.license]: wikum/licenses/license.pegjs.md

@@ -135,0 +135,0 @@ [phantomjs]: https://www.npmjs.com/package/phantomjs

@@ -130,7 +130,8 @@ /* jshint undef:true */

pChart.arcRowHeight = parseInt(pOptions.arcgradient, 10) + DEFAULT_ARCROW_HEIGHT;
pChart.arcGradient = parseInt(pOptions.arcgradient, 10) + DEFAULT_ARC_GRADIENT;
pChart.arcGradient = parseInt(pOptions.arcgradient, 10) + DEFAULT_ARC_GRADIENT;
}
if (pOptions.wordwraparcs && pOptions.wordwraparcs === "true") {
pChart.wordWrapArcs = true;
if (pOptions.wordwraparcs){
pChart.wordWrapArcs = pOptions.wordwraparcs;
}
}

@@ -171,2 +172,3 @@ }

"horizontaltransform" : (entities.getDims().interEntitySpacing + lDepthCorrection - entities.getDims().width) / 2,
"autoscale" : !!pAST.options && !!pAST.options.width && pAST.options.width === "auto", //!!pAST.options.autoscale && pAST.options.autoscale === true,
"verticaltransform" : PAD_VERTICAL,

@@ -194,3 +196,3 @@ "scale" : 1

}
if (pOptions.width) {
if (pOptions.width && pOptions.width !== "auto") {
utl.scaleCanvasToWidth(pOptions.width, pCanvas);

@@ -205,4 +207,11 @@ }

body.setAttribute("transform", "translate(" + pCanvas.horizontaltransform + "," + pCanvas.verticaltransform + ")" + " scale(" + pCanvas.scale + "," + pCanvas.scale + ")");
lSvgElement.setAttribute("width", pCanvas.width.toString());
lSvgElement.setAttribute("height", pCanvas.height.toString());
if (!!pCanvas.autoscale && pCanvas.autoscale===true){
lSvgElement.setAttribute("width", "100%");
lSvgElement.setAttribute("height", "100%");
lSvgElement.setAttribute("viewBox", "0 0 " + pCanvas.width.toString() + " " + pCanvas.height.toString());
} else {
lSvgElement.setAttribute("width", pCanvas.width.toString());
lSvgElement.setAttribute("height", pCanvas.height.toString());
}
}

@@ -209,0 +218,0 @@

@@ -8,7 +8,4 @@ /*

/* jshint node:true */
/* jshint undef:true */
/* jshint unused:strict */
/* jshint indent:4 */
/* istanbul ignore else */
/* istanbul ignore else */
if ( typeof define !== 'function') {

@@ -42,2 +39,9 @@ var define = require('amdefine')(module);

function optionIsValid(pOption) {
if (!!pOption.value && typeof(pOption.value) === "string" ){
return pOption.value.toLowerCase() !== "auto";
}
return true;
}
function renderComments() {

@@ -61,2 +65,3 @@ /* rendering comments within comments, that are eventually output

"renderAttributefn" : renderAttribute,
"optionIsValidfn": optionIsValid,
"renderKindfn" : renderKind,

@@ -63,0 +68,0 @@ "supportedOptions" : ["hscale", "width", "arcgradient", "wordwraparcs"],

@@ -50,2 +50,9 @@ /*

function optionIsValid(pOption) {
if (!!pOption.value && typeof(pOption.value) === "string" ){
return pOption.value.toLowerCase() !== "auto";
}
return true;
}
return {

@@ -56,2 +63,3 @@ render : function(pAST, pMinimal) {

"renderAttributefn" : renderAttribute,
"optionIsValidfn": optionIsValid,
"renderKindfn" : renderKind,

@@ -58,0 +66,0 @@ "supportedOptions" : ["hscale", "width", "arcgradient", "wordwraparcs"],

@@ -27,2 +27,3 @@ /*

"renderOptionfn" : renderOption,
"optionIsValidfn": optionIsValid,
"renderEntityNamefn" : renderEntityName,

@@ -109,7 +110,9 @@ "renderKindfn" : renderKind,

function extractSupportedOptions(pOptions, pSupportedOptions) {
return pSupportedOptions.filter(function(pSupportedOption){
return !!pOptions[pSupportedOption];
}).map(function(pSupportedOption){
return {name: pSupportedOption, value: pOptions[pSupportedOption]};
});
return pSupportedOptions
.filter(function(pSupportedOption){
return undefined !== pOptions[pSupportedOption];
})
.map(function(pSupportedOption){
return {name: pSupportedOption, value: pOptions[pSupportedOption]};
});
}

@@ -123,2 +126,11 @@

function isMscGenKeyword(pString){
return ["box", "abox", "rbox", "note", "msc", "hscale", "width", "arcgradient",
"wordwraparcs", "label", "color", "idurl", "id", "url",
"linecolor", "textcolor",
"textbgcolor", "arclinecolor",
"arctextcolor", "arctextbgcolor",
"arcskip"].indexOf(pString) > -1;
}
function renderEntityName(pString) {

@@ -128,5 +140,5 @@ function isQuotable(pString) {

if (!!lMatchResult) {
return lMatchResult.length !== 1;
return (lMatchResult.length !== 1)||isMscGenKeyword(pString);
} else {
return true && pString !== "*";
return pString !== "*";
}

@@ -139,7 +151,16 @@ }

function renderOption(pOption) {
return pOption.name + "=\"" + utl.escapeString(pOption.value) + "\"";
return pOption.name + "=" +
(typeof pOption.value === "string"?
"\"" + utl.escapeString(pOption.value) + "\"":
pOption.value.toString());
}
function optionIsValid(/*pOption*/){
return true;
}
function renderOptions(pOptions) {
var lOptions = extractSupportedOptions(pOptions, gConfig.supportedOptions);
var lOptions =
extractSupportedOptions(pOptions, gConfig.supportedOptions)
.filter(gConfig.optionIsValidfn);
var lRetVal = "";

@@ -146,0 +167,0 @@ if (lOptions.length > 0){

@@ -133,3 +133,3 @@ {

"arcgradient": "17",
"wordwraparcs": "true"
"wordwraparcs": true
},

@@ -152,3 +152,3 @@ "entities": [

"arcgradient": "17",
"wordwraparcs": "true",
"wordwraparcs": true,
"watermark": "not in mscgen, available in xù and msgenny"

@@ -212,3 +212,3 @@ },

"options": {
"wordwraparcs": "true"
"wordwraparcs": true
},

@@ -262,2 +262,58 @@ "entities": []

},
"astWorwraparcsfalse": {
"meta": {
"extendedOptions": false,
"extendedArcTypes": false,
"extendedFeatures": false
},
"options": {
"wordwraparcs": false
},
"entities": []
},
"astBoxArcs": {
"meta": {
"extendedOptions": false,
"extendedArcTypes": false,
"extendedFeatures": false
},
"entities": [
{
"name": "a"
},
{
"name": "b"
},
{
"name": "c"
},
{
"name": "d"
}
],
"arcs": [
[
{
"kind": "note",
"from": "a",
"to": "a"
},
{
"kind": "box",
"from": "b",
"to": "b"
},
{
"kind": "abox",
"from": "c",
"to": "c"
},
{
"kind": "rbox",
"from": "d",
"to": "d"
}
]
]
},
"astMixedAttributes": {

@@ -1706,3 +1762,49 @@ "meta": {

]
},
"auto": {
"meta": {
"extendedOptions": true,
"extendedArcTypes": false,
"extendedFeatures": true
},
"options": {
"width": "auto"
},
"entities": []
},
"fixedwidth": {
"meta": {
"extendedOptions": true,
"extendedArcTypes": false,
"extendedFeatures": true
},
"options": {
"width": 800
},
"entities": []
},
"unicodeentityname": {
"meta": {
"extendedOptions": false,
"extendedArcTypes": false,
"extendedFeatures": false
},
"entities": [
{
"name": "序"
}
]
},
"entityWithMscGenKeywordAsName": {
"meta": {
"extendedOptions": false,
"extendedArcTypes": false,
"extendedFeatures": false
},
"entities": [
{
"name": "note"
}
]
}
}

@@ -9,3 +9,3 @@ {

"width": "300",
"wordwraparcs": "true"
"wordwraparcs": true
},

@@ -12,0 +12,0 @@ "entities": [

@@ -16,3 +16,3 @@ {

"arcgradient": "18",
"wordwraparcs": "false"
"wordwraparcs": false
},

@@ -19,0 +19,0 @@ "entities": [

@@ -16,3 +16,3 @@ {

"arcgradient": "18",
"wordwraparcs": "false",
"wordwraparcs": false,
"watermark": "This humongous fictive chart contains all arcs possible in msgenny. It can be used for spot checks, but also for performance checks. 序列圖!"

@@ -19,0 +19,0 @@ },

@@ -14,3 +14,3 @@ {

"arcgradient": "18",
"wordwraparcs": "false",
"wordwraparcs": false,
"watermark": "This humongous fictive chart contains all arcs possible in xù. It can be used for spot checks, but also for performance checks."

@@ -17,0 +17,0 @@ },

@@ -14,3 +14,3 @@ {

"options": {
"wordwraparcs": "true"
"wordwraparcs": true
},

@@ -17,0 +17,0 @@ "entities": [

var parser = require("../../parse/mscgenparser_node");
var tst = require("../testutensils");
var fix = require("../astfixtures.json");
var pairs = require("./mscgenPairs");
var fs = require("fs");

@@ -9,155 +9,35 @@ var path = require("path");

describe('parse/mscgenparser', function() {
describe('#parse()', function() {
describe('#parse() - happy day values', function() {
it('should render a simple AST', function() {
var lAST = parser.parse('msc { a,"b space"; a => "b space" [label="a simple script"];}');
expect(lAST).to.deep.equal(fix.astSimple);
it("should correctly parse naked reals", function() {
var lAST = parser.parse('msc{HSCAle=481.1337;a;}');
expect(lAST.options.hscale).to.equal("481.1337");
});
it('should render a simple AST - regardless of start marker case', function() {
var lAST = parser.parse('MsC { a,"b space"; a => "b space" [label="a simple script"];}');
expect(lAST).to.be.deep.equal(fix.astSimple);
it("should correctly parse quoted cardinals", function() {
var lAST = parser.parse('msc{width="481";a;}');
expect(lAST.options.width).to.equal("481");
});
it('should ignore c++ style one line comments', function() {
var lAST = parser.parse('msc { a,"b space"; a => "b space" [label="a simple script"];}//ignored');
expect(lAST).to.deep.equal(fix.astSimple);
it("should correctly parse quoted reals", function() {
var lAST = parser.parse('msc{width="481.1337";a;}');
expect(lAST.options.width).to.equal("481.1337");
});
it("should produce an (almost empty) AST for empty input", function() {
var lAST = parser.parse("msc{}");
expect(lAST).to.deep.equal(fix.astEmpty);
});
describe('#parse() - happy day ASTs - ', function(){
pairs.programASTPairs.forEach(function(pPair){
it(pPair.title, function(){
expect(parser.parse(pPair.program)).to.deep.equal(pPair.ast);
});
});
it("should produce an AST even when non entity arcs are its only content", function() {
var lAST = parser.parse('msc{--- [label="start"]; ... [label="no entities ..."]; ---[label="end"];}');
expect(lAST).to.deep.equal(fix.astNoEntities);
});
describe('#parse() - syntax errors - ', function(){
pairs.syntaxErrors.forEach(function(pPair){
it(pPair.title, function() {
tst.assertSyntaxError(pPair.program, parser, pPair.error);
});
});
it("should produce lowercase for upper/ mixed case arc kinds", function() {
var lAST = parser.parse('msc { a, b, c, d; a NoTE a, b BOX b, c aBox c, d rbOX d;}');
expect(lAST).to.deep.equal(fix.astBoxArcs);
});
it("should produce lowercase for upper/ mixed case options", function() {
var lAST = parser.parse('msc{HSCAle=1.2, widtH=800, ARCGRADIENT="17",woRDwrAParcS="oN";a;}');
expect(lAST).to.deep.equal(fix.astOptionsMscgen);
});
it("should produce lowercase for upper/ mixed case attributes", function() {
var lAST = parser.parse('msc{a [LaBEL="miXed", teXTBGcolOR="orange"]; a NOte a [LINEcolor="red", TEXTColoR="blue", ArcSkip="4"];}');
expect(lAST).to.deep.equal(fix.astMixedAttributes);
});
it("should translate *colour to *color", function() {
var lAST = parser.parse('msc { a [textcolOUr="green", textBGColour="cyan", linecolour="#ABCDEF"];}');
expect(lAST).to.deep.equal(fix.astColourColor);
});
it("should parse all possible attributes", function(){
var lAST = parser.parse('msc {\n\
a [label="Label for A", idurl="http://localhost/idurl", id="Just and id", url="http://localhost/url", linecolor="#ABCDEF", textcolor="green", textbgcolor="cyan", arclinecolor="violet", arctextcolor="pink", arctextbgcolor="brown"];\n\
\n\
a <<=>> a [label="Label for a <<=>> a", idurl="http://localhost/idurl", id="Just and id", url="http://localhost/url", linecolor="#ABCDEF", textcolor="green", textbgcolor="cyan"];\n\
}');
expect(lAST).to.deep.equal(fix.astAllAttributes);
});
it("should generate arcs to all other arcs with both bare and quoted *", function(){
expect(
parser.parse('msc {arcgradient="18"; "ω","ɑ","β","ɣ"; "ɑ" -> * [label="ɑ -> *"]; * <- "β" [label="* <- β"]; "ɣ" <-> * [label="ɣ <-> *"];}')
).to.deep.equal(fix.astAsteriskBoth);
expect(
parser.parse('msc {arcgradient="18"; "ω","ɑ","β","ɣ"; "ɑ" -> "*" [label="ɑ -> *"]; "*" <- "β" [label="* <- β"]; "ɣ" <-> "*" [label="ɣ <-> *"];}')
).to.deep.equal(fix.astAsteriskBoth);
});
it("should produce only 'true' or 'false' for all variants of wordwraparcs", function() {
expect(parser.parse('msc { wordwraparcs=true;}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs="true";}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs=on;}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs="on";}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs=1;}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs="1";}')).to.deep.equal(fix.astWorwraparcstrue);
});
it("should throw a SyntaxError on an invalid program", function() {
tst.assertSyntaxError('a', parser);
});
it("should throw a SyntaxError on asterisks on both sides for uni-directional arrows", function(){
tst.assertSyntaxError('msc{a,b,c; * -> *;}', parser);
tst.assertSyntaxError('msc{a,b,c; * <- *;}', parser);
});
it("should throw a SyntaxError on asterisks on both sides for bi-directional arrows", function(){
tst.assertSyntaxError('msc{a,b,c; * <-> *;}', parser);
});
it("should throw a SyntaxError for asterisks on LHS on bi-directional arrows", function(){
tst.assertSyntaxError('msc{a,b,c; * <-> a;}', parser);
});
it("should throw a SyntaxError on a program with only the start token", function() {
tst.assertSyntaxError('msc', parser);
});
it("should throw a SyntaxError on a program with shizzle after the closing statement", function() {
tst.assertSyntaxError('msc{a;} shizzle after the closing statement', parser);
});
it("unicode is cool. But not yet for unquoted entity names", function() {
tst.assertSyntaxError('msc{序;}', parser);
});
it("unicode is cool for quoted entity names", function() {
var lFixture = {
"meta": {
"extendedOptions": false,
"extendedArcTypes": false,
"extendedFeatures": false
},
"entities": [
{
"name": "序"
}
]
};
expect(parser.parse('msc{"序";}')).to.deep.equal(lFixture);
});
it("should throw a SyntaxError on an invalid program", function() {
tst.assertSyntaxError('msc{a}', parser);
});
it("should throw a SyntaxError on an invalid arc type", function() {
tst.assertSyntaxError('msc{a, b; a xx b;}', parser);
});
it("should throw a SyntaxError on an invalid option", function() {
tst.assertSyntaxError('msc{wordwarparcs="true"; a, b; a -> b;}', parser);
});
it("should throw a SyntaxError on an invalid value for an option", function() {
tst.assertSyntaxError('msc{wordwraparcs=\u0181; a, b; a -> b;}', parser);
});
it("should throw a SyntaxError on a missing semi colon after the options list", function() {
tst.assertSyntaxError('msc{wordwraparcs="true" a, b; a -> b;}', parser);
});
it("should throw a SyntaxError on a missing semi colon", function() {
tst.assertSyntaxError('msc{wordwraparcs="true"; a, b; a -> b}', parser);
});
it("should throw a SyntaxError for a * on the RHS of x-", function() {
tst.assertSyntaxError('msc{a,b,c; b x- *;}', parser);
});
it("should throw a SyntaxError for a * on the LHS of -x", function() {
tst.assertSyntaxError('msc{a,b,c; * -x b;}', parser);
});
it("should throw a SyntaxError on a missing program closer", function() {
tst.assertSyntaxError('msc{wordwraparcs="true"; a, b; a -> b;', parser);
});
it("should throw a SyntaxError on a invalid entity attribute", function() {
tst.assertSyntaxError('msc{a[invalidentitityattribute="invalid"];}', parser);
});
it("should throw a SyntaxError on a missing closing bracket on an entity", function() {
tst.assertSyntaxError('msc{a[label="missing closing bracket";}', parser);
});
it("should throw a SyntaxError on a invalid arc attribute", function() {
tst.assertSyntaxError('msc{a, b; a -> b[invalidearcattribute="invalid"];}', parser);
});
it("should throw a SyntaxError on a missing closing bracket", function() {
tst.assertSyntaxError('msc{a, b; a -> b[label="missing closing bracket";}', parser);
});
it("should throw a SyntaxError on a missing closing bracket", function() {
tst.assertSyntaxError('msc{a, b; a -> b[label="missingmscbracket"];', parser);
});
it ("should complain about an undeclared entity in a from", function(){
tst.assertSyntaxError("msc{a,b,c;d=>a;}", parser, "EntityNotDefinedError");
});
it ("should complain about an undeclared entity in a to", function(){
tst.assertSyntaxError("msc{a,b,c;b=>f;}", parser, "EntityNotDefinedError");
});
it("should throw a SyntaxError when a keyword is used for an entityt name", function(){
tst.assertSyntaxError("msc{a,note,b,c; a => note;}", parser);
});
});
describe('#parse() - file based tests', function() {
describe('#parse() - file based tests - ', function() {
it("should parse all possible arcs", function() {

@@ -164,0 +44,0 @@ var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/test01_all_possible_arcs_mscgen.mscin'), {

@@ -125,2 +125,14 @@ var parser = require("../../parse/msgennyparser_node");

});
it("should correctly parse naked reals", function() {
var lAST = parser.parse('HSCAle=481.1337;a;');
expect(lAST.options.hscale).to.equal("481.1337");
});
it("should correctly parse quoted cardinals", function() {
var lAST = parser.parse('width="481";a;');
expect(lAST.options.width).to.equal("481");
});
it("should correctly parse quoted reals", function() {
var lAST = parser.parse('width="481.1337";a;');
expect(lAST.options.width).to.equal("481.1337");
});
it("should keep the labeled name of an entity", function(){

@@ -138,3 +150,2 @@ var lAST = parser.parse('"實體": This is the label for 實體;');

});
it('should produce wordwraparcs="true" for true, "true", on, "on", 1 and "1"', function() {

@@ -147,2 +158,8 @@ expect(parser.parse('wordwraparcs=true;')).to.deep.equal(fix.astWorwraparcstrue);

expect(parser.parse('wordwraparcs="1";')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('wordwraparcs=false;')).to.deep.equal(fix.astWorwraparcsfalse);
expect(parser.parse('wordwraparcs="false";')).to.deep.equal(fix.astWorwraparcsfalse);
expect(parser.parse('wordwraparcs=off;')).to.deep.equal(fix.astWorwraparcsfalse);
expect(parser.parse('wordwraparcs="off";')).to.deep.equal(fix.astWorwraparcsfalse);
expect(parser.parse('wordwraparcs=0;')).to.deep.equal(fix.astWorwraparcsfalse);
expect(parser.parse('wordwraparcs="0";')).to.deep.equal(fix.astWorwraparcsfalse);
});

@@ -239,2 +256,20 @@ it("should throw a SyntaxError on an invalid program", function() {

});
it("should throw a SyntaxError when passing a boolean to something expecting numbers", function(){
tst.assertSyntaxError("wordwraparcs=true, width=true; a;", parser);
});
it("should throw a SyntaxError when passing a boolean-like string to something expecting numbers", function(){
tst.assertSyntaxError('wordwraparcs=true, width="true"; a;', parser);
});
it("should throw a SyntaxError when passing a non-number like string to something expecting numbers", function(){
tst.assertSyntaxError('wordwraparcs=true, hscale="general string"; a;', parser);
});
it("should throw a SyntaxError when passing a number to something expecting booleans", function(){
tst.assertSyntaxError("wordwraparcs=481; a;", parser);
});
it("should throw a SyntaxError when passing a number-like string to something expecting booleans", function(){
tst.assertSyntaxError('wordwraparcs="481"; a;', parser);
});
it("should throw a SyntaxError when passing a non boolean-like string to something expecting booleans", function(){
tst.assertSyntaxError('wordwraparcs="general string"; a;', parser);
});
});

@@ -259,2 +294,10 @@

});
it('should accept "auto" as a valid width', function(){
var lAST = parser.parse('arcgradient= 20, width= auTo ; a,b,c,d,e,f; c =>> *: Hello everyone;');
expect(lAST.options.width).to.equal("auto");
});
it('should accept "AUTO" as a valid width', function(){
var lAST = parser.parse('arcgradient= 20, width="AUTO"; a,b,c,d,e,f; c =>> *: Hello everyone;');
expect(lAST.options.width).to.equal("auto");
});
it("should throw a SyntaxError on an inline expression without {}", function() {

@@ -275,3 +318,25 @@ tst.assertSyntaxError('a loop b', parser);

});
it("should throw a SyntaxError when passing a boolean to something expecting size", function(){
tst.assertSyntaxError("width=true; a;", parser);
});
it("should throw a SyntaxError when passing a boolean-like string to something expecting size", function(){
tst.assertSyntaxError('width="true"; a;', parser);
});
it("should throw a SyntaxError when passing a non-number like string to something expecting size", function(){
tst.assertSyntaxError('width="general string"; a;', parser);
});
it("should throw a SyntaxError when passing a boolean to something expecting a string", function(){
tst.assertSyntaxError("watermark=true; a;", parser);
});
it("should throw a SyntaxError when passing a cardinal to something expecting a string", function(){
tst.assertSyntaxError("watermark= 481; a;", parser);
});
it("should throw a SyntaxError when passing a real to something expecting a string", function(){
tst.assertSyntaxError("watermark= 481.1337; a;", parser);
});
it("should throw a SyntaxError when passing a size to something expecting a string", function(){
tst.assertSyntaxError("watermark = auto; a;", parser);
});
});

@@ -278,0 +343,0 @@ describe('#parse() - file based tests', function(){

var parser = require("../../parse/xuparser_node");
var tst = require("../testutensils");
var fix = require("../astfixtures.json");
var pairs = require("./mscgenPairs");
var fs = require("fs");

@@ -11,109 +12,56 @@ var path = require("path");

it('should render a simple AST', function() {
var lAST = parser.parse('msc { a,"b space"; a => "b space" [label="a simple script"];}');
expect(lAST).to.be.deep.equal(fix.astSimple);
it("should correctly parse naked reals", function() {
var lAST = parser.parse('xu{HSCAle=481.1337;a;}');
expect(lAST.options.hscale).to.equal("481.1337");
});
it('should render a simple AST - regardless of start marker case', function() {
var lAST = parser.parse('MsC { a,"b space"; a => "b space" [label="a simple script"];}');
expect(lAST).to.be.deep.equal(fix.astSimple);
it("should correctly parse quoted cardinals", function() {
var lAST = parser.parse('xu{width="481";a;}');
expect(lAST.options.width).to.equal("481");
});
it('should render a simple AST - also with xu as start marker', function() {
var lAST = parser.parse('xu { a,"b space"; a => "b space" [label="a simple script"];}');
expect(lAST).to.be.deep.equal(fix.astSimple);
it("should correctly parse quoted reals", function() {
var lAST = parser.parse('xu{width="481.1337";a;}');
expect(lAST.options.width).to.equal("481.1337");
});
it('should ignore c++ style one line comments', function() {
var lAST = parser.parse('msc { a,"b space"; a => "b space" [label="a simple script"];}//ignored');
expect(lAST).to.deep.equal(fix.astSimple);
});
describe('#parse() - happy day ASTs - ', function(){
pairs.programASTPairs.forEach(function(pPair){
it(pPair.title, function(){
expect(parser.parse(pPair.program)).to.deep.equal(pPair.ast);
});
});
it("should produce an (almost empty) AST for empty input", function() {
var lAST = parser.parse("msc{}");
expect(lAST).to.deep.equal(fix.astEmpty);
});
describe('#parse() - syntax errors - ', function(){
pairs.syntaxErrors.forEach(function(pPair){
it(pPair.title, function() {
tst.assertSyntaxError(pPair.program, parser, pPair.error);
});
});
it("should produce an AST even when non entity arcs are its only content", function() {
var lAST = parser.parse('msc{--- [label="start"]; ... [label="no entities ..."]; ---[label="end"];}');
expect(lAST).to.deep.equal(fix.astNoEntities);
});
describe('#parse() - inline expressions - ', function(){
it("should throw a SyntaxError on _that's not an inline expression_ arc type", function() {
tst.assertSyntaxError('msc{a, b; a => b{|||;};}', parser);
});
it("should produce lowercase for upper/ mixed case arc kinds", function() {
var lAST = parser.parse('msc { a, b, c, d; a NoTE a, b BOX b, c aBox c, d rbOX d;}');
expect(lAST).to.deep.equal(fix.astBoxArcs);
});
describe('#parse() - file based tests', function(){
it("should parse all possible arcs", function() {
var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/test01_all_possible_arcs.xu'), {"encoding":"utf8"});
var lAST = parser.parse(lTextFromFile.toString());
tst.assertequalToFileJSON(path.join(__dirname, '../fixtures/test01_all_possible_arcs.json'), lAST);
});
it("should produce lowercase for upper/ mixed case options", function() {
var lAST = parser.parse('msc{HSCAle=1.2, widtH=800, ARCGRADIENT="17",woRDwrAParcS="oN", WATERmark="not in mscgen, available in xù and msgenny" ;a;}');
expect(lAST).to.deep.equal(fix.astOptions);
it("should parse stuff with colors", function() {
var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/rainbow.mscin'), {"encoding":"utf8"});
var lAST = parser.parse(lTextFromFile.toString());
tst.assertequalToFileJSON(path.join(__dirname, '../fixtures/rainbow.json'), lAST);
});
it("should produce lowercase for upper/ mixed case attributes", function() {
var lAST = parser.parse('msc{a [LaBEL="miXed", teXTBGcolOR="orange"]; a NOte a [LINEcolor="red", TEXTColoR="blue", ArcSkip="4"];}');
expect(lAST).to.deep.equal(fix.astMixedAttributes);
it("strings, ids and urls", function() {
var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/test10_stringsandurls.mscin'), {"encoding":"utf8"});
var lAST = parser.parse(lTextFromFile.toString());
tst.assertequalToFileJSON(path.join(__dirname, '../fixtures/test10_stringsandurls.json'), lAST);
});
it("should translate *colour to *color", function() {
var lAST = parser.parse('msc { a [textcolOUr="green", textBGColour="cyan", linecolour="#ABCDEF"];}');
expect(lAST).to.deep.equal(fix.astColourColor);
});
it("should parse all possible attributes", function(){
var lAST = parser.parse('msc {\n\
a [label="Label for A", idurl="http://localhost/idurl", id="Just and id", url="http://localhost/url", linecolor="#ABCDEF", textcolor="green", textbgcolor="cyan", arclinecolor="violet", arctextcolor="pink", arctextbgcolor="brown"];\n\
\n\
a <<=>> a [label="Label for a <<=>> a", idurl="http://localhost/idurl", id="Just and id", url="http://localhost/url", linecolor="#ABCDEF", textcolor="green", textbgcolor="cyan"];\n\
}');
expect(lAST).to.deep.equal(fix.astAllAttributes);
});
it("should generate arcs to all other arcs with both bare and quoted *", function(){
expect(
parser.parse('msc {arcgradient="18"; "ω","ɑ","β","ɣ"; "ɑ" -> * [label="ɑ -> *"]; * <- "β" [label="* <- β"]; "ɣ" <-> * [label="ɣ <-> *"];}')
).to.deep.equal(fix.astAsteriskBoth);
expect(
parser.parse('msc {arcgradient="18"; "ω","ɑ","β","ɣ"; "ɑ" -> "*" [label="ɑ -> *"]; "*" <- "β" [label="* <- β"]; "ɣ" <-> "*" [label="ɣ <-> *"];}')
).to.deep.equal(fix.astAsteriskBoth);
});
it("should produce only 'true' or 'false' for all variants of wordwraparcs", function() {
expect(parser.parse('msc { wordwraparcs=true;}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs="true";}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs=on;}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs="on";}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs=1;}')).to.deep.equal(fix.astWorwraparcstrue);
expect(parser.parse('msc { wordwraparcs="1";}')).to.deep.equal(fix.astWorwraparcstrue);
});
it("should throw a SyntaxError on an invalid program", function() {
tst.assertSyntaxError('a', parser);
});
it("unicode is cool. But not yet for unquoted entity names", function() {
tst.assertSyntaxError('msc{序;}', parser);
});
it("unicode is cool for quoted entity names", function() {
var lFixture = {
"meta": {
"extendedOptions": false,
"extendedArcTypes": false,
"extendedFeatures": false
},
"entities": [
{
"name": "序"
}
]
};
expect(parser.parse('msc{"序";}')).to.deep.equal(lFixture);
});
it("should throw a SyntaxError on an invalid program", function() {
tst.assertSyntaxError('msc{a}', parser);
});
it("should throw a SyntaxError on asterisks on both sides for uni-directional arrows", function(){
tst.assertSyntaxError('msc{a,b,c; * -> *;}', parser);
tst.assertSyntaxError('msc{a,b,c; * <- *;}', parser);
});
it("should throw a SyntaxError on asterisks on both sides for bi-directional arrows", function(){
tst.assertSyntaxError('msc{a,b,c; * <-> *;}', parser);
});
it("should throw a SyntaxError for asterisks on LHS on bi-directional arrows", function(){
tst.assertSyntaxError('msc{a,b,c; * <-> a;}', parser);
});
it("should throw a SyntaxError on a program with only the start token", function() {
tst.assertSyntaxError('msc', parser);
});
it("should throw a SyntaxError on a program with shizzle after the closing statement", function() {
tst.assertSyntaxError('msc{a;} shizzle after the closing statement', parser);
});
it("should throw a SyntaxError on an invalid arc type", function() {
tst.assertSyntaxError('msc{a, b; a xx b;}', parser);
});
});
describe('#parse() - xu specific extensions', function() {
it("should accept empty inline expressions", function() {

@@ -147,65 +95,3 @@ var lFixture = {

});
it("should throw a SyntaxError on _that's not an inline expression_ arc type", function() {
tst.assertSyntaxError('msc{a, b; a => b{|||;};}', parser);
});
it("should throw a SyntaxError on an invalid option", function() {
tst.assertSyntaxError('msc{wordwarparcs="true"; a, b; a -> b;}', parser);
});
it("should throw a SyntaxError on an invalid value for an option", function() {
tst.assertSyntaxError('msc{wordwraparcs=\u0181; a, b; a -> b;}', parser);
});
it("should throw a SyntaxError on a missing semi colon after the options list", function() {
tst.assertSyntaxError('msc{wordwraparcs="true" a, b; a -> b;}', parser);
});
it("should throw a SyntaxError on a missing semi colon", function() {
tst.assertSyntaxError('msc{wordwraparcs="true"; a, b; a -> b}', parser);
});
it("should throw a SyntaxError for a * on the RHS of x-", function() {
tst.assertSyntaxError('msc{a,b,c; b x- *;}', parser);
});
it("should throw a SyntaxError for a * on the LHS of -x", function() {
tst.assertSyntaxError('msc{a,b,c; * -x b;}', parser);
});
it("should throw a SyntaxError on a missing program closer", function() {
tst.assertSyntaxError('msc{wordwraparcs="true"; a, b; a -> b;', parser);
});
it("should throw a SyntaxError on a invalid entity attribute", function() {
tst.assertSyntaxError('msc{a[invalidentitityattribute="invalid"];}', parser);
});
it("should throw a SyntaxError on a missing closing bracket on an entity", function() {
tst.assertSyntaxError('msc{a[label="missing closing bracket";}', parser);
});
it("should throw a SyntaxError on a invalid arc attribute", function() {
tst.assertSyntaxError('msc{a, b; a -> b[invalidearcattribute="invalid"];}', parser);
});
it("should throw a SyntaxError on a missing closing bracket", function() {
tst.assertSyntaxError('msc{a, b; a -> b[label="missing closing bracket";}', parser);
});
it ("should complain about an undeclared entity in a from", function(){
tst.assertSyntaxError("msc{a,b,c;d=>a;}", parser, "EntityNotDefinedError");
});
it ("should complain about an undeclared entity in a to", function(){
tst.assertSyntaxError("msc{a,b,c;b=>f;}", parser, "EntityNotDefinedError");
});
});
describe('#parse() - file based tests', function(){
it("should parse all possible arcs", function() {
var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/test01_all_possible_arcs.xu'), {"encoding":"utf8"});
var lAST = parser.parse(lTextFromFile.toString());
tst.assertequalToFileJSON(path.join(__dirname, '../fixtures/test01_all_possible_arcs.json'), lAST);
});
it("should parse stuff with colors", function() {
var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/rainbow.mscin'), {"encoding":"utf8"});
var lAST = parser.parse(lTextFromFile.toString());
tst.assertequalToFileJSON(path.join(__dirname, '../fixtures/rainbow.json'), lAST);
});
it("strings, ids and urls", function() {
var lTextFromFile = fs.readFileSync(path.join(__dirname, '../fixtures/test10_stringsandurls.mscin'), {"encoding":"utf8"});
var lAST = parser.parse(lTextFromFile.toString());
tst.assertequalToFileJSON(path.join(__dirname, '../fixtures/test10_stringsandurls.json'), lAST);
});
});
describe('#parse() - xu specific extensions', function() {
it('should render an AST, with an alt in it', function() {

@@ -220,2 +106,10 @@ var lAST = parser.parse('msc { a,b,c; a => b; b alt c { b => c; c >> b; };}');

});
it('should accept AUTO as a valid width', function(){
var lAST = parser.parse('xu{ arcgradient=20, width=AUTO; a,b,c,d,e,f; c =>> * [label="Hello everyone"];}');
expect(lAST.options.width).to.equal("auto");
});
it('should accept "AUTO" as a valid width', function(){
var lAST = parser.parse('xu{ arcgradient=20, width="AUTO"; a,b,c,d,e,f; c =>> * [label="Hello everyone"];}');
expect(lAST.options.width).to.equal("auto");
});
it("should throw a SyntaxError on a missing closing bracket", function() {

@@ -242,3 +136,15 @@ tst.assertSyntaxError('msc {a,b; a loop b {', parser);

});
it("should throw a SyntaxError when passing a boolean to something expecting a string", function(){
tst.assertSyntaxError("msc{watermark=true; a;}", parser);
});
it("should throw a SyntaxError when passing a cardinal to something expecting a string", function(){
tst.assertSyntaxError("msc{watermark=481; a;}", parser);
});
it("should throw a SyntaxError when passing a real to something expecting a string", function(){
tst.assertSyntaxError("msc{watermark=481.1337; a;}", parser);
});
it("should throw a SyntaxError when passing a size to something expecting a string", function(){
tst.assertSyntaxError("msc{watermark=auto; a;}", parser);
});
});
});

@@ -72,2 +72,6 @@ /* jshint unused: true */

});
it('should render with a viewBox instead of a width & height', function() {
processAndCompare(path.join(__dirname, '../../fixtures/astautoscale.svg'), //
path.join(__dirname, '../../fixtures/astautoscale.json'), true);
});
});

@@ -74,0 +78,0 @@ });

@@ -73,3 +73,28 @@ var assert = require("assert");

});
it("Does not render width when that equals 'auto'", function(){
var lProgram = renderer.render(fix.auto, true);
var lExpectedProgram =
' * \\msc\n\
* \\endmsc';
assert.equal(lProgram, lExpectedProgram);
});
it("Render width when that is a number", function(){
var lProgram = renderer.render(fix.fixedwidth, true);
var lExpectedProgram =
' * \\msc\n\
* width=800;\n\
* \n\
* \\endmsc';
assert.equal(lProgram, lExpectedProgram);
});
it("Puts entities with mscgen keyword for a name in quotes", function(){
var lProgram = renderer.render(fix.entityWithMscGenKeywordAsName, true);
var lExpectedProgram =
' * \\msc\n\
* "note";\n\
* \n\
* \\endmsc';
assert.equal(lProgram, lExpectedProgram);
});
});
});

@@ -42,3 +42,3 @@ var assert = require("assert");

var lProgram = renderer.render(fix.astOptionsMscgen);
var lExpectedProgram = 'msc {\n hscale="1.2",\n width="800",\n arcgradient="17",\n wordwraparcs="true";\n\n a;\n\n}';
var lExpectedProgram = 'msc {\n hscale="1.2",\n width="800",\n arcgradient="17",\n wordwraparcs=true;\n\n a;\n\n}';
assert.equal(lProgram, lExpectedProgram);

@@ -56,3 +56,3 @@ });

var lProgram = renderer.render(fix.astOptions, true);
var lExpectedProgram = 'msc{hscale="1.2",width="800",arcgradient="17",wordwraparcs="true";a;}';
var lExpectedProgram = 'msc{hscale="1.2",width="800",arcgradient="17",wordwraparcs=true;a;}';
assert.equal(lProgram, lExpectedProgram);

@@ -115,2 +115,12 @@ });

});
it("Does not render width when that equals 'auto'", function(){
var lProgram = renderer.render(fix.auto, true);
var lExpectedProgram = "msc{}";
assert.equal(lProgram, lExpectedProgram);
});
it("Puts entities with mscgen keyword for a name in quotes", function(){
var lProgram = renderer.render(fix.entityWithMscGenKeywordAsName, true);
var lExpectedProgram = 'msc{"note";}';
assert.equal(lProgram, lExpectedProgram);
});
});

@@ -117,0 +127,0 @@ describe('#renderAST() - file based tests', function(){

@@ -42,3 +42,3 @@ var assert = require("assert");

var lProgram = renderer.render(fix.astOptions);
var lExpectedProgram = 'hscale="1.2",\nwidth="800",\narcgradient="17",\nwordwraparcs="true",\nwatermark="not in mscgen, available in xù and msgenny";\n\na;\n\n';
var lExpectedProgram = 'hscale="1.2",\nwidth="800",\narcgradient="17",\nwordwraparcs=true,\nwatermark="not in mscgen, available in xù and msgenny";\n\na;\n\n';
assert.equal(lProgram, lExpectedProgram);

@@ -116,2 +116,7 @@ });

});
it("Does not put entities with mscgen keyword for a name in quotes", function(){
var lProgram = renderer.render(fix.entityWithMscGenKeywordAsName, true);
var lExpectedProgram = 'note;\n\n';
assert.equal(lProgram, lExpectedProgram);
});
});

@@ -118,0 +123,0 @@

@@ -43,3 +43,3 @@ var assert = require("assert");

var lProgram = renderer.render(fix.astOptionsMscgen);
var lExpectedProgram = 'msc {\n hscale="1.2",\n width="800",\n arcgradient="17",\n wordwraparcs="true";\n\n a;\n\n}';
var lExpectedProgram = 'msc {\n hscale="1.2",\n width="800",\n arcgradient="17",\n wordwraparcs=true;\n\n a;\n\n}';
assert.equal(lProgram, lExpectedProgram);

@@ -59,3 +59,3 @@ });

var lProgram = renderer.render(fix.astOptions, true);
var lExpectedProgram = 'msc{hscale="1.2",width="800",arcgradient="17",wordwraparcs="true",watermark="not in mscgen, available in xù and msgenny";a;}';
var lExpectedProgram = 'msc{hscale="1.2",width="800",arcgradient="17",wordwraparcs=true,watermark="not in mscgen, available in xù and msgenny";a;}';
assert.equal(lProgram, lExpectedProgram);

@@ -146,2 +146,7 @@ });

});
it("Puts entities with mscgen keyword for a name in quotes", function(){
var lProgram = renderer.render(fix.entityWithMscGenKeywordAsName, true);
var lExpectedProgram = 'msc{"note";}';
assert.equal(lProgram, lExpectedProgram);
});
});

@@ -148,0 +153,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc