1// run
2
3// Copyright 2012 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Issue 5704: Conversions of empty strings to byte
8// or rune slices return empty but non-nil slices.
9
10package main
11
12type (
13	mystring string
14	mybytes  []byte
15	myrunes  []rune
16)
17
18func checkBytes(s []byte, arg string) {
19	if len(s) != 0 {
20		panic("len(" + arg + ") != 0")
21	}
22	if s == nil {
23		panic(arg + " == nil")
24	}
25}
26
27func checkRunes(s []rune, arg string) {
28	if len(s) != 0 {
29		panic("len(" + arg + ") != 0")
30	}
31	if s == nil {
32		panic(arg + " == nil")
33	}
34}
35
36func main() {
37	checkBytes([]byte(""), `[]byte("")`)
38	checkBytes([]byte(mystring("")), `[]byte(mystring(""))`)
39	checkBytes(mybytes(""), `mybytes("")`)
40	checkBytes(mybytes(mystring("")), `mybytes(mystring(""))`)
41
42	checkRunes([]rune(""), `[]rune("")`)
43	checkRunes([]rune(mystring("")), `[]rune(mystring(""))`)
44	checkRunes(myrunes(""), `myrunes("")`)
45	checkRunes(myrunes(mystring("")), `myrunes(mystring(""))`)
46}
47