mirror of
https://github.com/gonum/gonum.git
synced 2025-11-02 21:24:03 +08:00
graph: imported graph as a subtree
This commit is contained in:
54
graph/formats/dot/internal/lexer/lexer_test.go
Normal file
54
graph/formats/dot/internal/lexer/lexer_test.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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 lexer_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/gonum/graph/formats/dot"
|
||||
)
|
||||
|
||||
func TestParseFile(t *testing.T) {
|
||||
golden := []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{
|
||||
in: "testdata/tokens.dot",
|
||||
out: "testdata/tokens.golden",
|
||||
},
|
||||
}
|
||||
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 := ioutil.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user