github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/state/state_test.go (about)

     1  package state_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/lang/state"
     7  	"github.com/lmorg/murex/test/count"
     8  )
     9  
    10  func TestStateVar(t *testing.T) {
    11  	count.Tests(t, 4)
    12  
    13  	var s state.State
    14  	fs := s.Get()
    15  	if fs != state.Undefined {
    16  		t.Errorf("Invalid initialised value: %s", fs.String())
    17  	}
    18  
    19  	s.Set(state.Executing)
    20  
    21  	fs = s.Get()
    22  	if fs != state.Executing {
    23  		t.Errorf("Invalid executing value: %s", fs.String())
    24  	}
    25  
    26  	if s.String() != fs.String() {
    27  		t.Errorf("Stringer mismatch: '%s' != '%s'", s.String(), fs.String())
    28  	}
    29  }
    30  
    31  func TestStateNew(t *testing.T) {
    32  	count.Tests(t, 4)
    33  
    34  	s := new(state.State)
    35  	fs := s.Get()
    36  	if fs != state.Undefined {
    37  		t.Errorf("Invalid initialised value: %s", fs.String())
    38  	}
    39  
    40  	s.Set(state.Executing)
    41  
    42  	fs = s.Get()
    43  	if fs != state.Executing {
    44  		t.Errorf("Invalid executing value: %s", fs.String())
    45  	}
    46  
    47  	if s.String() != fs.String() {
    48  		t.Errorf("Stringer mismatch: '%s' != '%s'", s.String(), fs.String())
    49  	}
    50  }