github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/testutils/access.gno (about)

     1  package testutils
     2  
     3  // for testing access. see tests/files/access*.go
     4  
     5  // NOTE: non-package variables cannot be overridden, except during init().
     6  var (
     7  	TestVar1 int
     8  	testVar2 int
     9  )
    10  
    11  func init() {
    12  	TestVar1 = 123
    13  	testVar2 = 456
    14  }
    15  
    16  type TestAccessStruct struct {
    17  	PublicField  string
    18  	privateField string
    19  }
    20  
    21  func (tas TestAccessStruct) PublicMethod() string {
    22  	return tas.PublicField + "/" + tas.privateField
    23  }
    24  
    25  func (tas TestAccessStruct) privateMethod() string {
    26  	return tas.PublicField + "/" + tas.privateField
    27  }
    28  
    29  func NewTestAccessStruct(pub, priv string) TestAccessStruct {
    30  	return TestAccessStruct{
    31  		PublicField:  pub,
    32  		privateField: priv,
    33  	}
    34  }
    35  
    36  // see access6.g0 etc.
    37  type PrivateInterface interface {
    38  	privateMethod() string
    39  }
    40  
    41  func PrintPrivateInterface(pi PrivateInterface) {
    42  	println("testutils.PrintPrivateInterface", pi.privateMethod())
    43  }