2018-04-28 13:20:38 -06:00
|
|
|
// 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"
|
2019-03-06 02:28:10 -07:00
|
|
|
"runtime"
|
2018-06-15 13:06:09 -06:00
|
|
|
"strconv"
|
2018-04-28 13:20:38 -06:00
|
|
|
"testing"
|
2018-06-15 13:06:09 -06:00
|
|
|
"unicode"
|
2018-04-28 13:20:38 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStaticIsUpToDate(t *testing.T) {
|
2019-03-06 02:28:10 -07:00
|
|
|
if runtime.GOOS == "android" {
|
|
|
|
t.Skip("files not available on android")
|
|
|
|
}
|
2018-04-28 13:20:38 -06:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-11-20 20:43:00 -07:00
|
|
|
if !bytes.Equal(oldBuf, newBuf) {
|
2018-06-13 15:17:30 -06:00
|
|
|
t.Error(`static.go is stale. Run:
|
|
|
|
$ go generate golang.org/x/tools/godoc/static
|
|
|
|
$ git diff
|
|
|
|
to see the differences.`)
|
|
|
|
|
2018-04-28 13:20:38 -06:00
|
|
|
}
|
|
|
|
}
|
2018-06-15 13:06:09 -06:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|