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