1
1
mirror of https://github.com/walles/moar.git synced 2024-10-05 16:07:54 +03:00

Add (failing) compressed-files tests

This commit is contained in:
Johan Walles 2019-06-23 21:30:11 +02:00
parent 70500056af
commit e640c7d856
5 changed files with 22 additions and 6 deletions

View File

@ -73,6 +73,8 @@ func (p *_Pager) Quit() {
}
func (p *_Pager) _OnKey(logger *log.Logger, key tcell.Key) {
// FIXME: Add support for pressing 'h' to get a list of keybindings
// FIXME: Add support for pressing '/' to search
switch key {
case tcell.KeyEscape:
p.Quit()

View File

@ -69,16 +69,18 @@ func _TestGetLines(t *testing.T, reader *Reader) {
}
}
func _GetTestFiles() []string {
func _GetSamplesDir() string {
// From: https://coderwall.com/p/_fmbug/go-get-path-to-current-file
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("Getting current filename failed")
}
samplesDir := path.Join(path.Dir(filename), "../sample-files")
return path.Join(path.Dir(filename), "../sample-files")
}
files, err := ioutil.ReadDir(samplesDir)
func _GetTestFiles() []string {
files, err := ioutil.ReadDir(_GetSamplesDir())
if err != nil {
panic(err)
}
@ -135,6 +137,18 @@ func TestStatusText(t *testing.T) {
assert.Equal(t, statusText, "null: <empty>")
}
// FIXME: Add test for opening .gz files
// FIXME: Add test for opening .xz files
// FIXME: Add test for opening .bz2 files
func _TestCompressedFile(t *testing.T, filename string) {
reader, e := NewReaderFromFilename(_GetSamplesDir() + "/" + filename)
if e != nil {
t.Errorf("Error opening file <%s>: %s", filename, e.Error())
panic(e)
}
assert.Equal(t, reader.GetLines(1, 5).lines, [...]string{"This is a compressed file"})
}
func TestCompressedFiles(t *testing.T) {
_TestCompressedFile(t, "compressed.gz")
_TestCompressedFile(t, "compressed.bz2")
_TestCompressedFile(t, "compressed.xz")
}

Binary file not shown.

Binary file not shown.

Binary file not shown.