23 lines
375 B
Go
23 lines
375 B
Go
|
package pkg
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestStrUse(t *testing.T) {
|
||
|
const NoModify = "Don't edit this string. "
|
||
|
str := fmt.Sprintf(NoModify+"%s", "Do something")
|
||
|
|
||
|
bs := S2B(str)
|
||
|
bs[0] = 'L'
|
||
|
t.Log(str)
|
||
|
|
||
|
// 不可以对字面量量声明的字符串进行这种修改
|
||
|
t.Run("painc", func(t *testing.T) {
|
||
|
bs = S2B(NoModify)
|
||
|
bs[0] = 'L'
|
||
|
t.Log(NoModify)
|
||
|
})
|
||
|
}
|