Source file src/cmd/compile/internal/ir/dump_test.go

     1  // Copyright 2024 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 ir
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func testMatch(t *testing.T, pkgName, fnName, toMatch string, match bool) {
    12  	if matchPkgFn(pkgName, fnName, toMatch) != match {
    13  		t.Errorf("%v != matchPkgFn(%s, %s, %s)", match, pkgName, fnName, toMatch)
    14  	}
    15  }
    16  
    17  func TestMatchPkgFn(t *testing.T) {
    18  	// "aFunc" matches "aFunc" (in any package)
    19  	// "aPkg.aFunc" matches "aPkg.aFunc"
    20  	// "aPkg/subPkg.aFunc" matches "subPkg.aFunc"
    21  
    22  	match := func(pkgName, fnName, toMatch string) {
    23  		if !matchPkgFn(pkgName, fnName, toMatch) {
    24  			t.Errorf("matchPkgFn(%s, %s, %s) did not match", pkgName, fnName, toMatch)
    25  		}
    26  	}
    27  	match("aPkg", "AFunc", "AFunc")
    28  	match("aPkg", "AFunc", "AFunc")
    29  	match("aPkg", "AFunc", "aPkg.AFunc")
    30  	match("aPkg/sPkg", "AFunc", "aPkg/sPkg.AFunc")
    31  	match("aPkg/sPkg", "AFunc", "sPkg.AFunc")
    32  
    33  	notmatch := func(pkgName, fnName, toMatch string) {
    34  		if matchPkgFn(pkgName, fnName, toMatch) {
    35  			t.Errorf("matchPkgFn(%s, %s, %s) should not match", pkgName, fnName, toMatch)
    36  		}
    37  	}
    38  	notmatch("aPkg", "AFunc", "BFunc")
    39  	notmatch("aPkg", "AFunc", "aPkg.BFunc")
    40  	notmatch("aPkg", "AFunc", "bPkg.AFunc")
    41  	notmatch("aPkg", "AFunc", "aPkg_AFunc")
    42  	notmatch("aPkg/sPkg", "AFunc", "aPkg/ssPkg.AFunc")
    43  	notmatch("aPkg/sPkg", "AFunc", "XPkg.AFunc")
    44  }
    45  

View as plain text