GoPLS Viewer

Home|gopls/godoc/static/gen_test.go
1// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package static
6
7import (
8    "bytes"
9    "io/ioutil"
10    "runtime"
11    "strconv"
12    "testing"
13    "unicode"
14)
15
16func TestStaticIsUpToDate(t *testing.T) {
17    if runtime.GOOS == "android" {
18        t.Skip("files not available on android")
19    }
20    oldBuferr := ioutil.ReadFile("static.go")
21    if err != nil {
22        t.Errorf("error while reading static.go: %v\n"err)
23    }
24
25    newBuferr := Generate()
26    if err != nil {
27        t.Errorf("error while generating static.go: %v\n"err)
28    }
29
30    if !bytes.Equal(oldBufnewBuf) {
31        t.Error(`static.go is stale.  Run:
32  $ go generate golang.org/x/tools/godoc/static
33  $ git diff
34to see the differences.`)
35
36    }
37}
38
39// TestAppendQuote ensures that AppendQuote produces a valid literal.
40func TestAppendQuote(t *testing.T) {
41    var inout bytes.Buffer
42    for r := rune(0); r < unicode.MaxRuner++ {
43        in.WriteRune(r)
44    }
45    appendQuote(&outin.Bytes())
46    in2err := strconv.Unquote(out.String())
47    if err != nil {
48        t.Fatalf("AppendQuote produced invalid string literal: %v"err)
49    }
50    if gotwant := in2in.String(); got != want {
51        t.Fatal("AppendQuote modified string"// no point printing got/want: huge
52    }
53}
54
MembersX
TestStaticIsUpToDate
TestStaticIsUpToDate.oldBuf
TestStaticIsUpToDate.newBuf
TestAppendQuote.r
strconv
TestAppendQuote
TestStaticIsUpToDate.t
TestStaticIsUpToDate.err
TestAppendQuote.t
TestAppendQuote.in
TestAppendQuote.got
runtime
TestAppendQuote.out
TestAppendQuote.in2
TestAppendQuote.err
TestAppendQuote.want
testing
Members
X