mirror of
https://github.com/golang/go
synced 2024-11-18 15:24:41 -07:00
e10d6c9a84
Printf(%q) aka strconv.AppendQuote depends on the Unicode tables du jour, which means gen_test breaks after a Go release in which Unicode evolves. This change uses a very dumb quotation function that emits only ASCII and is independent of the Go release. Perhaps an even better fix would have been to parse the generated file. Change-Id: I197942f1c36a8b53d6a37be4bb2b1e63a208f7e2 Reviewed-on: https://go-review.googlesource.com/119157 Reviewed-by: Ian Lance Taylor <iant@golang.org>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package static
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"strconv"
|
|
"testing"
|
|
"unicode"
|
|
)
|
|
|
|
func TestStaticIsUpToDate(t *testing.T) {
|
|
oldBuf, err := ioutil.ReadFile("static.go")
|
|
if err != nil {
|
|
t.Errorf("error while reading static.go: %v\n", err)
|
|
}
|
|
|
|
newBuf, err := Generate()
|
|
if err != nil {
|
|
t.Errorf("error while generating static.go: %v\n", err)
|
|
}
|
|
|
|
if bytes.Compare(oldBuf, newBuf) != 0 {
|
|
t.Error(`static.go is stale. Run:
|
|
$ go generate golang.org/x/tools/godoc/static
|
|
$ git diff
|
|
to see the differences.`)
|
|
|
|
}
|
|
}
|
|
|
|
// TestAppendQuote ensures that AppendQuote produces a valid literal.
|
|
func TestAppendQuote(t *testing.T) {
|
|
var in, out bytes.Buffer
|
|
for r := rune(0); r < unicode.MaxRune; r++ {
|
|
in.WriteRune(r)
|
|
}
|
|
appendQuote(&out, in.Bytes())
|
|
in2, err := strconv.Unquote(out.String())
|
|
if err != nil {
|
|
t.Fatalf("AppendQuote produced invalid string literal: %v", err)
|
|
}
|
|
if got, want := in2, in.String(); got != want {
|
|
t.Fatal("AppendQuote modified string") // no point printing got/want: huge
|
|
}
|
|
}
|