diff --git a/test/bundle-test.js b/test/bundle-test.js index e650598..40b822e 100644 --- a/test/bundle-test.js +++ b/test/bundle-test.js @@ -6,17 +6,17 @@ var expect = chai.expect; var graphlib = graphlibDot.graphlib; -describe("bundle", function() { - it("exports graphlibDot", function() { +describe("bundle", () => { + it("exports graphlibDot", () => { expect(graphlibDot).to.be.an("object"); - ["read", "readMany", "write"].forEach(function(fn) { + ["read", "readMany", "write"].forEach(fn => { expect(graphlibDot[fn]).to.be.a("function"); }); expect(graphlibDot.graphlib).to.be.an("object"); expect(graphlibDot.version).to.be.a("string"); }); - it("can serialize to DOT and back", function() { + it("can serialize to DOT and back", () => { var g = new graphlib.Graph(); g.setNode("a", { label: "a" }); g.setNode("b", { label: "b" }); diff --git a/test/read-many-test.js b/test/read-many-test.js index fc0d0e1..af53e07 100644 --- a/test/read-many-test.js +++ b/test/read-many-test.js @@ -1,8 +1,8 @@ var expect = require("./chai").expect; var readMany = require("..").readMany; -describe("readMany", function() { - it("can read multiple graphs", function() { +describe("readMany", () => { + it("can read multiple graphs", () => { var gs = readMany("digraph {} graph {}"); expect(gs).to.have.length(2); expect(gs[0].isDirected()).to.be.true; diff --git a/test/read-one-test.js b/test/read-one-test.js index 973b4c2..5544785 100644 --- a/test/read-one-test.js +++ b/test/read-one-test.js @@ -1,9 +1,9 @@ var expect = require("./chai").expect; var read = require("..").read; -describe("read", function() { - describe("graph", function() { - it("can read an empty digraph", function() { +describe("read", () => { + describe("graph", () => { + it("can read an empty digraph", () => { var g = read("digraph {}"); expect(g.nodeCount()).to.equal(0); expect(g.edgeCount()).to.equal(0); @@ -12,7 +12,7 @@ describe("read", function() { expect(g.isMultigraph()).to.be.true; }); - it("can read an empty graph", function() { + it("can read an empty graph", () => { var g = read("graph {}"); expect(g.nodeCount()).to.equal(0); expect(g.edgeCount()).to.equal(0); @@ -21,12 +21,12 @@ describe("read", function() { expect(g.isMultigraph()).to.be.true; }); - it("can read a strict graph", function() { + it("can read a strict graph", () => { var g = read("strict digraph {}"); expect(g.isMultigraph()).to.be.false; }); - it("can handle leading and trailing whitespace", function() { + it("can handle leading and trailing whitespace", () => { var g = read(" digraph {} "); expect(g.nodeCount()).to.equal(0); expect(g.edgeCount()).to.equal(0); @@ -34,7 +34,7 @@ describe("read", function() { expect(g.isDirected()).to.be.true; }); - it("safely incorporates the id for the graph", function() { + it("safely incorporates the id for the graph", () => { var g = read("digraph foobar {}"); expect(g.nodeCount()).to.equal(0); expect(g.edgeCount()).to.equal(0); @@ -42,105 +42,105 @@ describe("read", function() { expect(g.isDirected()).to.be.true; }); - it("can read graph attributes", function() { + it("can read graph attributes", () => { var g = read("digraph { foo = bar; }"); expect(g.graph()).eql({ foo: "bar" }); }); - it("can handle various forms of whitespace", function() { + it("can handle various forms of whitespace", () => { var g = read("digraph {\tfoo\r=bar\n; }"); expect(g.graph()).to.eql({ foo: "bar" }); }); }); - describe("comments", function() { - it("ignores single-line comments", function() { + describe("comments", () => { + it("ignores single-line comments", () => { var g = read("digraph { a //comment\n }"); expect(g.hasNode("a")).to.be.true; }); - it("ignores multi-line comments", function() { + it("ignores multi-line comments", () => { var g = read("digraph { a /*comment*/\n }"); expect(g.hasNode("a")).to.be.true; }); }); - describe("nodes", function() { - it("can read a single node graph", function() { + describe("nodes", () => { + it("can read a single node graph", () => { var g = read("digraph { a }"); expect(g.nodeCount()).to.equal(1); expect(g.hasNode("a")).to.be.true; expect(g.edgeCount()).to.equal(0); }); - it("can read a node with an attribute", function() { + it("can read a node with an attribute", () => { var g = read("digraph { a [label=foo]; }"); expect(g.node("a")).to.eql({ label: "foo" }); }); - it("can read a node with a quoted attribute", function() { + it("can read a node with a quoted attribute", () => { var g = read("digraph { a [label=\"foo and bar\"]; }"); expect(g.node("a")).to.eql({ label: "foo and bar" }); }); - it("can read a node with comma-separated attributes", function() { + it("can read a node with comma-separated attributes", () => { var g = read("digraph { a [label=l, foo=f, bar=b]; }"); expect(g.node("a")).to.eql({ label: "l", foo: "f", bar: "b" }); }); - it("can read a node with space-separated attributes", function() { + it("can read a node with space-separated attributes", () => { var g = read("digraph { a [label=l foo=f bar=b]; }"); expect(g.node("a")).to.eql({ label: "l", foo: "f", bar: "b" }); }); - it("can read a node with multiple attr defs", function() { + it("can read a node with multiple attr defs", () => { var g = read("digraph { a [label=l] [foo=1] [foo=2]; }"); expect(g.node("a")).to.eql({ label: "l", foo: "2" }); }); - it("can read nodes with numeric ids", function() { + it("can read nodes with numeric ids", () => { var list = ["12", "-12", "12.34", "-12.34", ".34", "-.34", "12.", "-12."]; var g = read("digraph { " + list.join(";") + " }"); expect(g.nodes().sort()).to.eql(list.sort()); }); - it("can read escaped quotes", function() { + it("can read escaped quotes", () => { expect(read("digraph { \"\\\"a\\\"\" }").nodes()).to.eql(["\"a\""]); }); - it("preserves non-quote escapes", function() { + it("preserves non-quote escapes", () => { expect(read("digraph { \"foo\\-bar\" }").nodes()).to.eql(["foo\\-bar"]); }); - it("can read quoted unicode", function() { + it("can read quoted unicode", () => { var g = read("digraph { \"♖♘♗♕♔♗♘♖\" }"); expect(g.nodes()).to.eql(["♖♘♗♕♔♗♘♖"]); }); - it("fails to read unquoted unicode", function() { - expect(function() { read("digraph { ♖♘♗♕♔♗♘♖ }"); }).to.throw(); + it("fails to read unquoted unicode", () => { + expect(() => read("digraph { ♖♘♗♕♔♗♘♖ }")).to.throw(); }); - it("treats a number id followed by a letter as two nodes", function() { + it("treats a number id followed by a letter as two nodes", () => { // Yes this is what the language specifies! var g = read("digraph { 123a }"); expect(g.nodes().sort()).to.eql(["123", "a"]); }); - it("ignores node ports", function() { + it("ignores node ports", () => { var g = read("digraph { a:port }"); expect(g.node("a")).to.eql({}); }); var compass = ["n", "ne", "e", "se", "s", "sw", "w", "nw", "c", "_"]; - it("ignores node compass", function() { + it("ignores node compass", () => { compass.forEach(c => { expect(read("digraph { a:" + c + " }").node("a")).to.eql({}); expect(read("digraph { a : " + c + " }").node("a")).to.eql({}); }); }); - it("ignores node port compass", function() { + it("ignores node port compass", () => { compass.forEach(c => { expect(read("digraph { a:port:" + c + " }").node("a")).to.eql({}); expect(read("digraph { a : port : " + c + " }").node("a")).to.eql({}); @@ -148,40 +148,40 @@ describe("read", function() { }); }); - describe("edges", function() { - it("can read an unlabelled undirected edge", function() { + describe("edges", () => { + it("can read an unlabelled undirected edge", () => { var g = read("strict graph { a -- b }"); expect(g.edgeCount()).to.equal(1); expect(g.edge("a", "b")).to.eql({}); }); - it("fails if reading an undirected edge in a directed graph", function() { - expect(function() { read("graph { a -> b }"); }).to.throw(); + it("fails if reading an undirected edge in a directed graph", () => { + expect(() => read("graph { a -> b }")).to.throw(); }); - it("can read an unlabelled directed edge", function() { + it("can read an unlabelled directed edge", () => { var g = read("strict digraph { a -> b }"); expect(g.edgeCount()).to.equal(1); expect(g.edge("a", "b")).to.eql({}); }); - it("fails if reading a directed edge in an undirected graph", function() { - expect(function() { read("digraph { a -- b }"); }).to.throw(); + it("fails if reading a directed edge in an undirected graph", () => { + expect(() => read("digraph { a -- b }")).to.throw(); }); - it("can read an edge with attributes", function() { + it("can read an edge with attributes", () => { var g = read("strict digraph { a -> b [label=foo]; }"); expect(g.edge("a", "b")).to.eql({ label: "foo" }); }); - it("can assign attributes to a path of nodes", function() { + it("can assign attributes to a path of nodes", () => { var g = read("strict digraph { a -> b -> c [label=foo]; }"); expect(g.edge("a", "b")).to.eql({ label: "foo" }); expect(g.edge("b", "c")).to.eql({ label: "foo" }); expect(g.edgeCount()).to.equal(2); }); - it("assigns multiple labels if an edge is defined multiple times", function() { + it("assigns multiple labels if an edge is defined multiple times", () => { var g = read("digraph { a -> b [x=1 z=3]; a -> b [y=2 z=4] }"); var results = g.nodeEdges("a", "b").map(edge => { return g.edge(edge); @@ -193,34 +193,34 @@ describe("read", function() { expect(g.edgeCount()).to.equal(2); }); - it("updates an edge if it is defined multiple times in strict mode", function() { + it("updates an edge if it is defined multiple times in strict mode", () => { var g = read("strict digraph { a -> b [x=1 z=3]; a -> b [y=2 z=4] }"); expect(g.edge("a", "b")).to.eql({ x: "1", y: "2", z: "4" }); expect(g.edgeCount()).to.equal(1); }); }); - describe("subgraphs", function() { - it("ignores empty subgraphs", function() { + describe("subgraphs", () => { + it("ignores empty subgraphs", () => { expect(read("digraph { subgraph X {} }").nodes()).to.be.empty; expect(read("digraph { subgraph {} }").nodes()).to.be.empty; expect(read("digraph { {} }").nodes()).to.be.empty; }); - it("reads nodes in a subgraph", function() { + it("reads nodes in a subgraph", () => { var g = read("digraph { subgraph X { a; b }; c }"); expect(g.nodes().sort()).to.eql(["X", "a", "b", "c"]); expect(g.children().sort()).to.eql(["X", "c"]); expect(g.children("X").sort()).to.eql(["a", "b"]); }); - it("assigns a node to the first subgraph in which it appears", function() { + it("assigns a node to the first subgraph in which it appears", () => { var g = read("digraph { subgraph X { a }; subgraph Y { a; b } }"); expect(g.parent("a")).to.equal("X"); expect(g.parent("b")).to.equal("Y"); }); - it("reads edges in a subgraph", function() { + it("reads edges in a subgraph", () => { var g = read("strict digraph { subgraph X { a; b; a -> b } }"); expect(g.nodes().sort()).to.eql(["X", "a", "b"]); expect(g.children("X").sort()).to.eql(["a", "b"]); @@ -228,39 +228,39 @@ describe("read", function() { expect(g.edgeCount()).to.equal(1); }); - it("assigns graph attributes to the subgraph in which they appear", function() { + it("assigns graph attributes to the subgraph in which they appear", () => { var g = read("strict digraph { subgraph X { foo=bar; a } }"); expect(g.graph()).to.eql({}); expect(g.node("X")).to.eql({ foo: "bar" }); }); - it("reads anonymous subgraphs #1", function() { + it("reads anonymous subgraphs #1", () => { var g = read("digraph { subgraph { a } }"); expect(g.parent("a")).to.not.be.undefined; expect(g.parent(g.parent("a"))).to.be.undefined; }); - it("reads anonymous subgraphs #2", function() { + it("reads anonymous subgraphs #2", () => { var g = read("digraph { { a } }"); expect(g.parent("a")).to.not.be.undefined; expect(g.parent(g.parent("a"))).to.be.undefined; }); - it("reads subgraphs as the LHS of an edge statement", function() { + it("reads subgraphs as the LHS of an edge statement", () => { var g = read("digraph { {a; b} -> c }"); expect(g.hasEdge("a", "c")).to.be.true; expect(g.hasEdge("b", "c")).to.be.true; expect(g.edgeCount()).to.equal(2); }); - it("reads subgraphs as the RHS of an edge statement", function() { + it("reads subgraphs as the RHS of an edge statement", () => { var g = read("digraph { a -> { b; c } }"); expect(g.hasEdge("a", "b")).to.be.true; expect(g.hasEdge("a", "c")).to.be.true; expect(g.edgeCount()).to.equal(2); }); - it("handles subgraphs with edges as an LHS of another edge statment", function() { + it("handles subgraphs with edges as an LHS of another edge statment", () => { var g = read("digraph { {a -> b} -> c }"); expect(g.hasEdge("a", "b")).to.be.true; expect(g.hasEdge("a", "c")).to.be.true; @@ -268,7 +268,7 @@ describe("read", function() { expect(g.edgeCount()).to.equal(3); }); - it("reads subgraphs as both the LHS and RHS side of an edge statement", function() { + it("reads subgraphs as both the LHS and RHS side of an edge statement", () => { var g = read("digraph { { a; b } -> { c; d } }"); expect(g.hasEdge("a", "c")).to.be.true; expect(g.hasEdge("a", "d")).to.be.true; @@ -277,7 +277,7 @@ describe("read", function() { expect(g.edgeCount()).to.equal(4); }); - it("applies edges attributes when using subgraphs as LHS or RHS", function() { + it("applies edges attributes when using subgraphs as LHS or RHS", () => { var g = read("strict digraph { { a; b } -> { c; d } [foo=bar] }"); expect(g.edge("a", "c")).to.eql({ foo: "bar" }); expect(g.edge("a", "d")).to.eql({ foo: "bar" }); @@ -287,50 +287,50 @@ describe("read", function() { }); }); - describe("defaults", function() { - it("adds default attributes to nodes", function() { + describe("defaults", () => { + it("adds default attributes to nodes", () => { var g = read("digraph { node [color=black]; a [label=foo]; b [label=bar] }"); expect(g.node("a")).to.eql({ color: "black", label: "foo" }); expect(g.node("b")).to.eql({ color: "black", label: "bar" }); }); - it("can apply multiple node defaults", function() { + it("can apply multiple node defaults", () => { var g = read("digraph { node[color=black]; node[shape=box]; a [label=foo] }"); expect(g.node("a")).to.eql({ color: "black", shape: "box", label: "foo" }); }); - it("only applies defaults already visited", function() { + it("only applies defaults already visited", () => { var g = read("digraph { node[color=black]; a; node[shape=box]; b; }"); expect(g.node("a")).to.eql({ color: "black" }); expect(g.node("b")).to.eql({ color: "black", shape: "box" }); }); - it("only applies defaults to nodes created in the subgraph", function() { + it("only applies defaults to nodes created in the subgraph", () => { var g = read("digraph { a; { node[color=black]; a; b; } }"); expect(g.node("a")).to.eql({}); expect(g.node("b")).to.eql({ color: "black" }); }); - it("allows defaults to redefined", function() { + it("allows defaults to redefined", () => { var g = read("digraph { node[color=black]; a; node[color=green]; b; }"); expect(g.node("a")).to.eql({ color: "black" }); expect(g.node("b")).to.eql({ color: "green" }); }); - it("applies defaults to nodes created through an edge statement", function() { + it("applies defaults to nodes created through an edge statement", () => { var g = read("digraph { node[color=black]; a -> b; }"); expect(g.node("a")).to.eql({ color: "black" }); expect(g.node("b")).to.eql({ color: "black" }); }); - it("applies defaults to subgraphs", function() { + it("applies defaults to subgraphs", () => { var g = read("digraph { node[color=black]; { a; { b; c[color=green]; } } }"); expect(g.node("a")).to.eql({ color: "black" }); expect(g.node("b")).to.eql({ color: "black" }); expect(g.node("c")).to.eql({ color: "green" }); }); - it("applies defaults to edges", function() { + it("applies defaults to edges", () => { var g = read("strict digraph { edge[color=black]; a -> b }"); expect(g.node("a")).to.eql({}); expect(g.node("b")).to.eql({}); @@ -338,37 +338,37 @@ describe("read", function() { }); }); - describe("failure cases", function() { - it("fails if the graph block is not closed", function() { - expect(function() { read("digraph {"); }).to.throw(); + describe("failure cases", () => { + it("fails if the graph block is not closed", () => { + expect(() => read("digraph {")).to.throw(); }); - it("fails if an attribute block is not closed", function() { - expect(function() { read("digraph { a [k=v}"); }).to.throw(); + it("fails if an attribute block is not closed", () => { + expect(() => read("digraph { a [k=v}")).to.throw(); }); - it("fails if an attribute is missing a key", function() { - expect(function() { read("digraph { a [=v] }"); }).to.throw(); + it("fails if an attribute is missing a key", () => { + expect(() => read("digraph { a [=v] }")).to.throw(); }); - it("fails if an attribute is missing a value", function() { - expect(function() { read("digraph { a [k=] }"); }).to.throw(); + it("fails if an attribute is missing a value", () => { + expect(() => read("digraph { a [k=] }")).to.throw(); }); - it("fails if an edge is missing an LHS", function() { - expect(function() { read("digraph { -> b }"); }).to.throw(); + it("fails if an edge is missing an LHS", () => { + expect(() => read("digraph { -> b }")).to.throw(); }); - it("fails if an edge is missing an RHS", function() { - expect(function() { read("digraph { a -> }"); }).to.throw(); + it("fails if an edge is missing an RHS", () => { + expect(() => read("digraph { a -> }")).to.throw(); }); - it("fails if a subgraph is left unclosed", function() { - expect(function() { read("digraph { { a "); }).to.throw(); + it("fails if a subgraph is left unclosed", () => { + expect(() => read("digraph { { a ")).to.throw(); }); - it("fails if a new subgraph is opened after a previous one", function() { - expect(function() { read("digraph {} digraph {}"); }).to.throw(); + it("fails if a new subgraph is opened after a previous one", () => { + expect(() => read("digraph {} digraph {}")).to.throw(); }); }); }); diff --git a/test/version-test.js b/test/version-test.js index e151b2c..74e97cc 100644 --- a/test/version-test.js +++ b/test/version-test.js @@ -1,7 +1,7 @@ var expect = require('./chai').expect; -describe('version', function() { - it('should match the version from package.json', function() { +describe('version', () => { + it('should match the version from package.json', () => { var packageVersion = require('../package').version; expect(require('..').version).to.equal(packageVersion); }); diff --git a/test/write-test.js b/test/write-test.js index 3bf38d2..44ac182 100644 --- a/test/write-test.js +++ b/test/write-test.js @@ -3,8 +3,8 @@ var Graph = require("@dagrejs/graphlib").Graph; var read = require("..").read; var write = require("..").write; -describe("write", function() { - it("can write an empty digraph", function() { +describe("write", () => { + it("can write an empty digraph", () => { var str = write(new Graph()); var g = read(str); expect(g.nodeCount()).to.equal(0); @@ -13,7 +13,7 @@ describe("write", function() { expect(g.isDirected()).to.be.true; }); - it("can write an empty undirected graph", function() { + it("can write an empty undirected graph", () => { var str = write(new Graph({ directed: false })); var g = read(str); expect(g.nodeCount()).to.equal(0); @@ -22,7 +22,7 @@ describe("write", function() { expect(g.isDirected()).to.be.false; }); - it("can write a graph label with an object", function() { + it("can write a graph label with an object", () => { var g = new Graph(); g.setGraph({ foo: "bar" }); var str = write(g); @@ -30,7 +30,7 @@ describe("write", function() { expect(g2.graph()).to.eql({ foo: "bar" }); }); - it("can write a node", function() { + it("can write a node", () => { var g = new Graph(); g.setNode("n1"); var str = write(g); @@ -41,7 +41,7 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(0); }); - it("can write a node with attributes", function() { + it("can write a node with attributes", () => { var g = new Graph(); g.setNode("n1", { foo: "bar" }); var str = write(g); @@ -52,7 +52,7 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(0); }); - it("can write an edge", function() { + it("can write an edge", () => { var g = new Graph(); g.setEdge("n1", "n2"); var str = write(g, { strict: true }); @@ -62,7 +62,7 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(1); }); - it("can write an edge with attributes", function() { + it("can write an edge with attributes", () => { var g = new Graph(); g.setEdge("n1", "n2", { foo: "bar" }); var str = write(g, { strict: true }); @@ -72,7 +72,7 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(1); }); - it("can write multi-edges", function() { + it("can write multi-edges", () => { var g = new Graph({ multigraph: true }); g.setEdge("n1", "n2", { foo: "bar" }); g.setEdge("n1", "n2", { foo: "baz" }, "another"); @@ -88,14 +88,14 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(2); }); - it("preserves the strict (non-multigraph) state", function() { + it("preserves the strict (non-multigraph) state", () => { var g = new Graph(); var str = write(g); var g2 = read(str); expect(g2.isMultigraph()).to.be.false; }); - it("can write ids that must be escaped", function() { + it("can write ids that must be escaped", () => { var g = new Graph(); g.setNode("\"n1\""); var str = write(g); @@ -106,7 +106,7 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(0); }); - it("can write subgraphs", function() { + it("can write subgraphs", () => { var g = new Graph({ compound: true }); g.setParent("n1", "root"); var str = write(g); @@ -118,7 +118,7 @@ describe("write", function() { expect(g2.edgeCount()).to.equal(0); }); - it("can write subgraphs with attributes", function() { + it("can write subgraphs with attributes", () => { var g = new Graph({ compound: true }); g.setParent("n1", "root"); g.setNode("root", { foo: "bar" });