github.com/jhump/golang-x-tools@v0.0.0-20220218190644-4958d6d39439/go/buildutil/util_windows_test.go (about)

     1  // Copyright 2015 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 buildutil_test
     6  
     7  import (
     8  	"fmt"
     9  	"go/build"
    10  	"path/filepath"
    11  	"runtime"
    12  	"strings"
    13  	"testing"
    14  
    15  	"github.com/jhump/golang-x-tools/go/buildutil"
    16  )
    17  
    18  func testContainingPackageCaseFold(file, want string) error {
    19  	bp, err := buildutil.ContainingPackage(&build.Default, ".", file)
    20  	if err != nil {
    21  		return err
    22  	}
    23  	if got := bp.ImportPath; got != want {
    24  		return fmt.Errorf("ContainingPackage(%q) = %s, want %s", file, got, want)
    25  	}
    26  	return nil
    27  }
    28  
    29  func TestContainingPackageCaseFold(t *testing.T) {
    30  	path := filepath.Join(runtime.GOROOT(), `src\fmt\print.go`)
    31  	err := testContainingPackageCaseFold(path, "fmt")
    32  	if err != nil {
    33  		t.Error(err)
    34  	}
    35  	vol := filepath.VolumeName(path)
    36  	if len(vol) != 2 || vol[1] != ':' {
    37  		t.Fatalf("GOROOT path has unexpected volume name: %v", vol)
    38  	}
    39  	rest := path[len(vol):]
    40  	err = testContainingPackageCaseFold(strings.ToUpper(vol)+rest, "fmt")
    41  	if err != nil {
    42  		t.Error(err)
    43  	}
    44  	err = testContainingPackageCaseFold(strings.ToLower(vol)+rest, "fmt")
    45  	if err != nil {
    46  		t.Error(err)
    47  	}
    48  }