github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/godebug/godebug_test.go (about)

     1  // Copyright 2021 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  
     5  package godebug_test
     6  
     7  import (
     8  	. "internal/godebug"
     9  	"testing"
    10  )
    11  
    12  func TestGet(t *testing.T) {
    13  	foo := New("foo")
    14  	tests := []struct {
    15  		godebug string
    16  		setting *Setting
    17  		want    string
    18  	}{
    19  		{"", New(""), ""},
    20  		{"", foo, ""},
    21  		{"foo=bar", foo, "bar"},
    22  		{"foo=bar,after=x", foo, "bar"},
    23  		{"before=x,foo=bar,after=x", foo, "bar"},
    24  		{"before=x,foo=bar", foo, "bar"},
    25  		{",,,foo=bar,,,", foo, "bar"},
    26  		{"foodecoy=wrong,foo=bar", foo, "bar"},
    27  		{"foo=", foo, ""},
    28  		{"foo", foo, ""},
    29  		{",foo", foo, ""},
    30  		{"foo=bar,baz", New("loooooooong"), ""},
    31  	}
    32  	for _, tt := range tests {
    33  		t.Setenv("GODEBUG", tt.godebug)
    34  		got := tt.setting.Value()
    35  		if got != tt.want {
    36  			t.Errorf("get(%q, %q) = %q; want %q", tt.godebug, tt.setting.Name(), got, tt.want)
    37  		}
    38  	}
    39  }