1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
// This file is dual licensed under CC0 and The Gonum License.
//
// Copyright ©2017 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Copyright ©2017 Robin Eklind.
// This file is made available under a Creative Commons CC0 1.0
// Universal Public Domain Dedication.
package ast_test
import (
"bytes"
"os"
"testing"
"gonum.org/v1/gonum/graph/formats/dot"
"gonum.org/v1/gonum/graph/formats/dot/ast"
)
func TestParseFile(t *testing.T) {
golden := []struct {
in string
out string
}{
{in: "../internal/testdata/empty.dot"},
{in: "../internal/testdata/graph.dot"},
{in: "../internal/testdata/digraph.dot"},
{in: "../internal/testdata/strict.dot"},
{in: "../internal/testdata/multi.dot"},
{in: "../internal/testdata/named_graph.dot"},
{in: "../internal/testdata/node_stmt.dot"},
{in: "../internal/testdata/edge_stmt.dot"},
{in: "../internal/testdata/attr_stmt.dot"},
{in: "../internal/testdata/attr.dot"},
{
in: "../internal/testdata/subgraph.dot",
out: "../internal/testdata/subgraph.golden",
},
{
in: "../internal/testdata/semi.dot",
out: "../internal/testdata/semi.golden",
},
{
in: "../internal/testdata/empty_attr.dot",
out: "../internal/testdata/empty_attr.golden",
},
{
in: "../internal/testdata/attr_lists.dot",
out: "../internal/testdata/attr_lists.golden",
},
{
in: "../internal/testdata/attr_sep.dot",
out: "../internal/testdata/attr_sep.golden",
},
{in: "../internal/testdata/subgraph_vertex.dot"},
{in: "../internal/testdata/port.dot"},
}
for _, g := range golden {
file, err := dot.ParseFile(g.in)
if err != nil {
t.Errorf("%q: unable to parse file; %v", g.in, err)
continue
}
// If no output path is specified, the input is already golden.
out := g.in
if len(g.out) > 0 {
out = g.out
}
buf, err := os.ReadFile(out)
if err != nil {
t.Errorf("%q: unable to read file; %v", g.in, err)
continue
}
got := file.String()
// Remove trailing newline.
want := string(bytes.TrimSpace(buf))
if got != want {
t.Errorf("%q: graph mismatch; expected %q, got %q", g.in, want, got)
}
}
}
// Verify that all statements implement the Stmt interface.
var (
_ ast.Stmt = (*ast.NodeStmt)(nil)
_ ast.Stmt = (*ast.EdgeStmt)(nil)
_ ast.Stmt = (*ast.AttrStmt)(nil)
_ ast.Stmt = (*ast.Attr)(nil)
_ ast.Stmt = (*ast.Subgraph)(nil)
)
// Verify that all vertices implement the Vertex interface.
var (
_ ast.Vertex = (*ast.Node)(nil)
_ ast.Vertex = (*ast.Subgraph)(nil)
)
|