github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/man/descriptions_test.go (about)

     1  package man
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  )
     8  
     9  func TestParseLineFlags(t *testing.T) {
    10  	tests := []string{
    11  		`-a`,
    12  		`--foobar`,
    13  		`-a, --foobar`,
    14  		`-f FILE`,
    15  		`-f FILE, --file=FILE`,
    16  		`-e PATTERNS, --regexp=PATTERNS`,
    17  		`-E, --extended-regexp`,
    18  		`--exclude-from=FILE`,
    19  		`--backup[=CONTROL]`,
    20  		`-R, -r, --recursive`,
    21  		`--list-cmds=group[,group...]`,
    22  		`--exec-path[=<path>]`,
    23  		`--config-env=<name>=<envvar>`,
    24  		`--[no]-help`,
    25  		`--help Output a usage message and exit.`,
    26  	}
    27  
    28  	length := len(tests)
    29  	for i := 0; i < length; i++ {
    30  		tests = append(tests, tests[i]+" An autogenerated description")
    31  	}
    32  
    33  	count.Tests(t, len(tests))
    34  
    35  	for i, test := range tests {
    36  		pl := parseLineFlags([]byte(test))
    37  		switch {
    38  		case pl.Position == len(test):
    39  			// success
    40  		case pl.Description != "":
    41  			// success
    42  		default:
    43  			t.Errorf("Could not match %s in test %d: len(test)==%d, result==%d", test, i, len(test), pl.Position)
    44  			if pl.Position < len(test) {
    45  				t.Logf("  scanned so far: '%s'", test[:pl.Position])
    46  			}
    47  		}
    48  	}
    49  }
    50  
    51  /*func TestParseDescriptionsLines(t *testing.T) {
    52  	count.Tests(t, 1)
    53  
    54  	files, err := manPages.ReadDir(".")
    55  	if err != nil {
    56  		t.Error(err.Error())
    57  	}
    58  
    59  	for _, entry := range files {
    60  		file, err := manPages.Open(entry.Name())
    61  		if err != nil {
    62  			t.Errorf("%s: %s", entry.Name(), err.Error())
    63  		}
    64  
    65  		gz, err := gzip.NewReader(file)
    66  		if err != nil {
    67  			t.Errorf("%s: %s", entry.Name(), err.Error())
    68  		}
    69  
    70  		descriptions := make(map[string]string)
    71  		parseDescriptionsLines(streams.NewReader(gz), &descriptions)
    72  		if len(descriptions) == 0 {
    73  			t.Errorf("%d descriptions returned for '%s'", len(descriptions), entry.Name())
    74  		}
    75  
    76  		gz.Close()
    77  		file.Close()
    78  	}
    79  }
    80  */