github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/shell/autocomplete/sort_test.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package autocomplete
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/lmorg/murex/test/count"
    10  )
    11  
    12  func TestSortCompletions(t *testing.T) {
    13  	count.Tests(t, 1)
    14  
    15  	test := []string{
    16  		"cc", "-b:", "c", "bb:", "-a", "b:", "dd", "-bb", "d", "aa:", "a:",
    17  	}
    18  
    19  	expected := []string{
    20  		"a:", "aa:", "b:", "bb:", "c", "cc", "d", "dd", "-a", "-b:", "-bb",
    21  	}
    22  
    23  	sortCompletions(test)
    24  
    25  	passed := true
    26  	for i := range test {
    27  		passed = passed && test[i] == expected[i]
    28  	}
    29  
    30  	if !passed {
    31  		t.Error("Expected splice does not match actual splice")
    32  		t.Log("  Expected:", expected)
    33  		t.Log("  Actual:  ", test)
    34  	}
    35  }
    36  
    37  type testIsLtT struct {
    38  	a string
    39  	b string
    40  	r bool
    41  }
    42  
    43  func TestIsLt(t *testing.T) {
    44  	tests := []testIsLtT{
    45  		{
    46  			a: "foobara",
    47  			b: "foobar:",
    48  			r: false,
    49  		},
    50  		{
    51  			a: "foobar:",
    52  			b: "foobara",
    53  			r: true,
    54  		},
    55  		{
    56  			a: "-foobara",
    57  			b: "foobar:",
    58  			r: false,
    59  		},
    60  		{
    61  			a: "-foobar:",
    62  			b: "foobara",
    63  			r: false,
    64  		},
    65  		{
    66  			a: "foobara",
    67  			b: "-foobar:",
    68  			r: true,
    69  		},
    70  		{
    71  			a: "foobar:",
    72  			b: "-foobara",
    73  			r: true,
    74  		},
    75  	}
    76  
    77  	count.Tests(t, len(tests))
    78  
    79  	for i, test := range tests {
    80  		if isLt(test.a, test.b) != test.r {
    81  			t.Errorf("Test %d failed:", i)
    82  			t.Logf("  a:  `%s`", test.a)
    83  			t.Logf("  b:  `%s`", test.b)
    84  			t.Logf("  exp: %v", test.r)
    85  			t.Logf("  act: %v", isLt(test.a, test.b))
    86  		}
    87  	}
    88  }
    89  
    90  func TestNoColon(t *testing.T) {
    91  	count.Tests(t, 2)
    92  
    93  	if noColon("foobar") != "foobar" {
    94  		t.Errorf(`noColon("foobar") != "foobar": %s`, noColon("foobar"))
    95  	}
    96  
    97  	if noColon("foobar:") != "foobar" {
    98  		t.Errorf(`noColon("foobar:") != "foobar": %s`, noColon("foobar:"))
    99  	}
   100  }