Robert Griesemer | de47f68 | 2013-06-21 16:11:13 -0700 | [diff] [blame] | 1 | // run |
| 2 | |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 3 | // Copyright 2012 The Go Authors. All rights reserved. |
Robert Griesemer | de47f68 | 2013-06-21 16:11:13 -0700 | [diff] [blame] | 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 | |
| 10 | package main |
| 11 | |
| 12 | type ( |
| 13 | mystring string |
| 14 | mybytes []byte |
| 15 | myrunes []rune |
| 16 | ) |
| 17 | |
| 18 | func 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 | |
| 27 | func 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 | |
| 36 | func 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 | } |