github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/testing/vars.go (about)

     1  // Copyright 2021 The ChromiumOS Authors
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package testing
     6  
     7  // Var define an interface for global runtime variable types.
     8  type Var interface {
     9  	// Unmarshal convert a string to Var's value type and set it to Var.
    10  	Unmarshal(data string) error
    11  
    12  	// Name return the name of the variable.
    13  	Name() string
    14  }
    15  
    16  // VarString define a structure for global runtime variables of string type.
    17  type VarString struct {
    18  	name  string // name is the name of the variable.
    19  	value string // Values store value of the variable.
    20  	desc  string // desc is a description of the variable.
    21  }
    22  
    23  // NewVarString creates a new VarString
    24  func NewVarString(name, defaultValue, desc string) *VarString {
    25  	v := VarString{
    26  		name:  name,
    27  		value: defaultValue,
    28  		desc:  desc,
    29  	}
    30  	return &v
    31  }
    32  
    33  // Name returns the name of the variable.
    34  func (v *VarString) Name() string {
    35  	return v.name
    36  }
    37  
    38  // Value returns value of a variable and a flag to indicate whether the value is initialized.
    39  func (v *VarString) Value() string {
    40  	return v.value
    41  }
    42  
    43  // Unmarshal extract a string and set the value of variable type to the variable.
    44  func (v *VarString) Unmarshal(data string) error {
    45  	v.value = data
    46  	return nil
    47  }