Files
gonum/graph/formats/dot/internal/lexer/lexer_test.go
2017-05-23 00:03:03 -06:00

55 lines
1.2 KiB
Go

// 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"
"gonum.org/v1/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)
}
}
}