Drop command

This commit is contained in:
Dan Jones 2024-02-11 13:50:27 -06:00
commit cc9e8f6167
6 changed files with 214 additions and 23 deletions

View file

@ -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)
}