mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add specs for wtf.ChecklistItem
This commit is contained in:
parent
5ebab79e2c
commit
857702e971
@ -1,10 +1,13 @@
|
|||||||
package wtf
|
package wtf
|
||||||
|
|
||||||
|
// ChecklistItem is a module for creating generic checklist implementations
|
||||||
|
// See 'Todo' for an implementation example
|
||||||
type ChecklistItem struct {
|
type ChecklistItem struct {
|
||||||
Checked bool
|
Checked bool
|
||||||
Text string
|
Text string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckMark returns the string used to indicate a ChecklistItem is checked or unchecked
|
||||||
func (item *ChecklistItem) CheckMark() string {
|
func (item *ChecklistItem) CheckMark() string {
|
||||||
if item.Checked {
|
if item.Checked {
|
||||||
return Config.UString("wtf.mods.todo.checkedIcon", "x")
|
return Config.UString("wtf.mods.todo.checkedIcon", "x")
|
||||||
@ -13,6 +16,8 @@ func (item *ChecklistItem) CheckMark() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Toggle changes the checked state of the ChecklistItem
|
||||||
|
// If checked, it is unchecked. If unchecked, it is checked
|
||||||
func (item *ChecklistItem) Toggle() {
|
func (item *ChecklistItem) Toggle() {
|
||||||
item.Checked = !item.Checked
|
item.Checked = !item.Checked
|
||||||
}
|
}
|
||||||
|
42
wtftests/checklist_item_test.go
Normal file
42
wtftests/checklist_item_test.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package wtftests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
. "github.com/senorprogrammer/wtf/wtf"
|
||||||
|
. "github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* -------------------- CheckMark -------------------- */
|
||||||
|
|
||||||
|
func TestCheckMark(t *testing.T) {
|
||||||
|
loadConfig()
|
||||||
|
|
||||||
|
item := ChecklistItem{}
|
||||||
|
Equal(t, " ", item.CheckMark())
|
||||||
|
|
||||||
|
item = ChecklistItem{Checked: true}
|
||||||
|
Equal(t, "x", item.CheckMark())
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Toggle -------------------- */
|
||||||
|
|
||||||
|
func TestToggle(t *testing.T) {
|
||||||
|
loadConfig()
|
||||||
|
|
||||||
|
item := ChecklistItem{}
|
||||||
|
Equal(t, false, item.Checked)
|
||||||
|
|
||||||
|
item.Toggle()
|
||||||
|
Equal(t, true, item.Checked)
|
||||||
|
|
||||||
|
item.Toggle()
|
||||||
|
Equal(t, false, item.Checked)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- helpers -------------------- */
|
||||||
|
|
||||||
|
func loadConfig() {
|
||||||
|
Config, _ = config.ParseYamlFile("../_sample_configs/simple_config.yml")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user