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

     1  package lang
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  	"github.com/lmorg/murex/utils/json"
     8  )
     9  
    10  func TestArgs(t *testing.T) {
    11  	type testT struct {
    12  		NameIn    string
    13  		ParamsIn  []string
    14  		NameOut   string
    15  		ParamsOut []string
    16  	}
    17  
    18  	tests := []testT{
    19  		{
    20  			NameIn:  "bob",
    21  			NameOut: "bob",
    22  		},
    23  		{
    24  			NameIn:    "bob",
    25  			ParamsIn:  []string{"bob"},
    26  			NameOut:   "bob",
    27  			ParamsOut: []string{"bob"},
    28  		},
    29  		{
    30  			NameIn:    "bob",
    31  			ParamsIn:  []string{"exec"},
    32  			NameOut:   "bob",
    33  			ParamsOut: []string{"exec"},
    34  		},
    35  
    36  		{
    37  			NameIn:  "exec",
    38  			NameOut: "exec",
    39  		},
    40  		{
    41  			NameIn:   "exec",
    42  			ParamsIn: []string{"exec"},
    43  			NameOut:  "exec",
    44  		},
    45  		{
    46  			NameIn:   "exec",
    47  			ParamsIn: []string{"bob"},
    48  			NameOut:  "bob",
    49  		},
    50  	}
    51  
    52  	count.Tests(t, len(tests))
    53  
    54  	for i, test := range tests {
    55  		nameAct, paramsAct := args(test.NameIn, test.ParamsIn)
    56  
    57  		if len(test.ParamsIn) == 0 {
    58  			test.ParamsIn = []string{}
    59  		}
    60  
    61  		if len(test.ParamsOut) == 0 {
    62  			test.ParamsOut = []string{}
    63  		}
    64  
    65  		if nameAct != test.NameOut ||
    66  			json.LazyLogging(paramsAct) != json.LazyLogging(test.ParamsOut) {
    67  			t.Errorf("Test %d failed:", i)
    68  			t.Logf("  Name:       `%s`", test.NameIn)
    69  			t.Logf("  Params:      %s", json.LazyLogging(test.ParamsIn))
    70  			t.Logf("  exp name:   `%s`", test.NameOut)
    71  			t.Logf("  exp params:  %s", json.LazyLogging(test.ParamsOut))
    72  			t.Logf("  act name:   `%s`", nameAct)
    73  			t.Logf("  act params:  %s", json.LazyLogging(paramsAct))
    74  		}
    75  	}
    76  }