mirror of
https://github.com/cheat/cheat.git
synced 2025-12-28 09:52:06 +01:00
Re-wrote from scratch in Golang
- Re-implemented the project in Golang, and deprecated Python entirely - Implemented several new, long-requested features - Refactored cheatsheets into a separate repository
This commit is contained in:
71
internal/sheet/sheet_test.go
Normal file
71
internal/sheet/sheet_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package sheet
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cheat/cheat/internal/mock"
|
||||
)
|
||||
|
||||
// TestSheetSuccess asserts that sheets initialize properly
|
||||
func TestSheetSuccess(t *testing.T) {
|
||||
|
||||
// initialize a sheet
|
||||
sheet, err := New(
|
||||
"foo",
|
||||
mock.Path("sheet/foo"),
|
||||
[]string{"alpha", "bravo"},
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Errorf("failed to load sheet: %v", err)
|
||||
}
|
||||
|
||||
// assert that the sheet loaded correctly
|
||||
if sheet.Title != "foo" {
|
||||
t.Errorf("failed to init title: want: foo, got: %s", sheet.Title)
|
||||
}
|
||||
|
||||
if sheet.Path != mock.Path("sheet/foo") {
|
||||
t.Errorf(
|
||||
"failed to init path: want: %s, got: %s",
|
||||
mock.Path("sheet/foo"),
|
||||
sheet.Path,
|
||||
)
|
||||
}
|
||||
|
||||
wantText := "# To foo the bar:\n foo bar\n"
|
||||
if sheet.Text != wantText {
|
||||
t.Errorf("failed to init text: want: %s, got: %s", wantText, sheet.Text)
|
||||
}
|
||||
|
||||
// NB: tags should sort alphabetically
|
||||
wantTags := []string{"alpha", "bar", "baz", "bravo", "foo"}
|
||||
if !reflect.DeepEqual(sheet.Tags, wantTags) {
|
||||
t.Errorf("failed to init tags: want: %v, got: %v", wantTags, sheet.Tags)
|
||||
}
|
||||
|
||||
if sheet.Syntax != "sh" {
|
||||
t.Errorf("failed to init syntax: want: sh, got: %s", sheet.Syntax)
|
||||
}
|
||||
|
||||
if sheet.ReadOnly != false {
|
||||
t.Errorf("failed to init readonly")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSheetFailure asserts that an error is returned if the sheet cannot be
|
||||
// read
|
||||
func TestSheetFailure(t *testing.T) {
|
||||
|
||||
// initialize a sheet
|
||||
_, err := New(
|
||||
"foo",
|
||||
mock.Path("/does-not-exist"),
|
||||
[]string{"alpha", "bravo"},
|
||||
false,
|
||||
)
|
||||
if err == nil {
|
||||
t.Errorf("failed to return an error on unreadable sheet")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user