mirror of
https://github.com/gonum/gonum.git
synced 2025-10-09 17:10:16 +08:00
graph/encoding/dot: (un)quote attributes if needed during (un)marshal
This commit is contained in:

committed by
Dan Kortschak

parent
9b1d387736
commit
24f0d081ca
@@ -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.
|
||||
{
|
||||
|
Reference in New Issue
Block a user