✨ Drop command
This commit is contained in:
parent
a062e71a29
commit
cc9e8f6167
6 changed files with 214 additions and 23 deletions
|
|
@ -20,6 +20,10 @@ type Entry struct {
|
|||
skipMissing bool
|
||||
}
|
||||
|
||||
func PartialEntry() Entry {
|
||||
return Entry{skipMissing: true}
|
||||
}
|
||||
|
||||
type metaRes struct {
|
||||
out []byte
|
||||
err error
|
||||
|
|
@ -68,7 +72,7 @@ func (e Entry) MarshalText() ([]byte, error) {
|
|||
}
|
||||
ch := e.getFieldMarshalChan()
|
||||
buff := &bytes.Buffer{}
|
||||
buff.WriteString("@begin ")
|
||||
buff.WriteString("\n@begin ")
|
||||
buff.WriteString(e.Date.Format(DateFormat))
|
||||
buff.WriteString(" - ")
|
||||
buff.WriteString(e.Title)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Type assertions
|
||||
|
|
@ -17,6 +18,19 @@ var _ encoding.TextUnmarshaler = new(Entry)
|
|||
var _ json.Marshaler = Entry{}
|
||||
var _ json.Unmarshaler = new(Entry)
|
||||
|
||||
func TestPartialEntry(t *testing.T) {
|
||||
e := PartialEntry()
|
||||
assert.True(t, e.skipMissing)
|
||||
err := json.Unmarshal([]byte(`{"a":42}`), &e)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", e.Title)
|
||||
assert.Equal(t, time.Time{}, e.Date)
|
||||
require.Len(t, e.Fields, 1)
|
||||
f := e.Fields[0]
|
||||
assert.Equal(t, "a", f.Key)
|
||||
assert.Equal(t, int64(42), f.Value)
|
||||
}
|
||||
|
||||
func TestEntryMarshal(t *testing.T) {
|
||||
when := time.Now()
|
||||
whens := when.Format(DateFormat)
|
||||
|
|
@ -77,12 +91,12 @@ func getEntryMarshalTestRunner(title string, date time.Time, fields []Meta, firs
|
|||
return
|
||||
}
|
||||
if len(lines) == 0 {
|
||||
assert.Equal(t, first, string(o))
|
||||
assert.Equal(t, "\n"+first, string(o))
|
||||
return
|
||||
}
|
||||
|
||||
os := string(o)
|
||||
assert.Regexp(t, "^"+first, os)
|
||||
assert.Regexp(t, "^\n"+first, os)
|
||||
for _, line := range lines {
|
||||
assert.Regexp(t, "(?m)^"+line, os)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue