blob: f25804ca824325d9bab55765a604f79d5faabc1d [file] [log] [blame]
// 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 gen
import (
"bytes"
"strconv"
"testing"
"unicode"
)
// 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
}
}