graph/encoding/dot: (un)quote attributes if needed during (un)marshal

This commit is contained in:
Robin Eklind
2019-01-14 04:57:56 +01:00
committed by Dan Kortschak
parent 9b1d387736
commit 24f0d081ca
5 changed files with 288 additions and 74 deletions

View File

@@ -950,6 +950,64 @@ var encodeTests = []struct {
3 -- 4 [color=red];
}`,
},
{
g: undirectedEdgeAttrGraphFrom(powerMethodGraph, map[edge][]encoding.Attribute{
// label attribute not quoted and containing spaces.
{from: 0, to: 2}: {{Key: "label", Value: `hello world`}, {Key: "style", Value: "dashed"}},
{from: 2, to: 4}: {},
{from: 3, to: 4}: {{Key: "label", Value: `foo bar`}},
}),
want: `strict graph {
// Node definitions.
0;
1;
2;
3;
4;
// Edge definitions.
0 -- 1;
0 -- 2 [
label="hello world"
style=dashed
];
0 -- 4;
1 -- 3;
2 -- 3;
2 -- 4;
3 -- 4 [label="foo bar"];
}`,
},
{
g: undirectedEdgeAttrGraphFrom(powerMethodGraph, map[edge][]encoding.Attribute{
// keywords must be quoted if used as attributes.
{from: 0, to: 2}: {{Key: "label", Value: `NODE`}, {Key: "style", Value: "dashed"}},
{from: 2, to: 4}: {},
{from: 3, to: 4}: {{Key: "label", Value: `subgraph`}},
}),
want: `strict graph {
// Node definitions.
0;
1;
2;
3;
4;
// Edge definitions.
0 -- 1;
0 -- 2 [
label="NODE"
style=dashed
];
0 -- 4;
1 -- 3;
2 -- 3;
2 -- 4;
3 -- 4 [label="subgraph"];
}`,
},
// Handling nodes with ports.
{