mirror of
https://github.com/golang/go
synced 2024-11-18 07:44:51 -07:00
207d3de1fa
Updates golang/go#35718 Change-Id: I10bfd5421cd44bb58b8bcaa6e9205040c25f51be Reviewed-on: https://go-review.googlesource.com/c/tools/+/208257 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
54 lines
1.2 KiB
Go
54 lines
1.2 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"
|
|
"runtime"
|
|
"strconv"
|
|
"testing"
|
|
"unicode"
|
|
)
|
|
|
|
func TestStaticIsUpToDate(t *testing.T) {
|
|
if runtime.GOOS == "android" {
|
|
t.Skip("files not available on android")
|
|
}
|
|
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.Equal(oldBuf, newBuf) {
|
|
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
|
|
}
|
|
}
|