github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/values_test.go (about)

     1  package runtime
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/arnodel/golua/luastrings"
     7  )
     8  
     9  func TestStringNormPos(t *testing.T) {
    10  	type args struct {
    11  		s string
    12  		p int
    13  	}
    14  	tests := []struct {
    15  		name string
    16  		args args
    17  		want int
    18  	}{
    19  		{
    20  			name: "start from left",
    21  			args: args{
    22  				s: "hello",
    23  				p: 1,
    24  			},
    25  			want: 1,
    26  		},
    27  		{
    28  			name: "end from left",
    29  			args: args{
    30  				s: "hello",
    31  				p: 5,
    32  			},
    33  			want: 5,
    34  		},
    35  		{
    36  			name: "start from right",
    37  			args: args{
    38  				s: "hello",
    39  				p: -1,
    40  			},
    41  			want: 5,
    42  		},
    43  		{
    44  			name: "end from right",
    45  			args: args{
    46  				s: "hello",
    47  				p: -5,
    48  			},
    49  			want: 1,
    50  		},
    51  	}
    52  	for _, tt := range tests {
    53  		t.Run(tt.name, func(t *testing.T) {
    54  			if got := luastrings.StringNormPos(tt.args.s, tt.args.p); got != tt.want {
    55  				t.Errorf("StringNormPos() = %v, want %v", got, tt.want)
    56  			}
    57  		})
    58  	}
    59  }