✨ Special handling of json field
This commit is contained in:
parent
0da5efcafe
commit
16a0a9d20b
4 changed files with 112 additions and 30 deletions
|
|
@ -52,7 +52,6 @@ func TestEntryMarshal(t *testing.T) {
|
|||
[]string{"@age 41", "@cool true", "@name Jim"},
|
||||
nil,
|
||||
},
|
||||
/* uncomment when implemented
|
||||
{
|
||||
"json-field",
|
||||
"Title J",
|
||||
|
|
@ -62,7 +61,6 @@ func TestEntryMarshal(t *testing.T) {
|
|||
[]string{"@age 41", "@cool true", "@name Jim"},
|
||||
nil,
|
||||
},
|
||||
*/
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -72,7 +70,7 @@ func TestEntryMarshal(t *testing.T) {
|
|||
|
||||
func getEntryMarshalTestRunner(title string, date time.Time, fields []Meta, first string, lines []string, err error) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
en := Entry{title, date, fields}
|
||||
en := Entry{title, date, fields, false}
|
||||
o, er := en.MarshalText()
|
||||
assert.Equal(t, err, er)
|
||||
if first == "" {
|
||||
|
|
@ -127,16 +125,14 @@ func TestEntryUnmarshal(t *testing.T) {
|
|||
[]Meta{{"me", json.RawMessage(`{"name":"Dan","coder":true}`)}},
|
||||
nil,
|
||||
},
|
||||
/* uncomment when implemented
|
||||
{
|
||||
"json-field",
|
||||
"@begin " + whens + " - Some Guy\n" + `@json {"name":"Dan","coder":true} @end`,
|
||||
"A Title",
|
||||
"Some Guy",
|
||||
when,
|
||||
[]Meta{{"name", "Dan"}, {"coder", true}},
|
||||
nil,
|
||||
},
|
||||
*/
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -171,7 +167,7 @@ func getEntryUnmarshalTestRunner(in string, title string, date time.Time, fields
|
|||
break
|
||||
}
|
||||
}
|
||||
assert.Truef(t, got, "Couldn't find field %+v", f)
|
||||
assert.Truef(t, got, "Couldn't find field %+v. We have %+v", f, e.Fields)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,6 +208,7 @@ func TestEntryJsonMarshal(t *testing.T) {
|
|||
{"empty-date", "A Title", time.Time{}, simple, "", ErrorMissingDate},
|
||||
{"obj-field", "A Title", when, []Meta{{"obj", json.RawMessage(`{"foo":"bar","title":"Sub-title"}`)}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","title":"Sub-title"}}`, nil},
|
||||
{"date-field", "A Title", when, []Meta{{"when", when.Add(time.Hour)}}, `{"title":"A Title","date":"` + whens + `","when":"` + when.Add(time.Hour).Format(time.RFC3339) + `"}`, nil},
|
||||
{"json-field", "A Title", when, []Meta{{"json", json.RawMessage(`{"age": 41, "cool": true, "name": "Jim"}`)}}, `{"title":"A Title","date":"` + whens + `","age":41,"cool": true, "name": "Jim"}`, nil},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -221,7 +218,7 @@ func TestEntryJsonMarshal(t *testing.T) {
|
|||
|
||||
func getEntryJsonMarshalTestRunner(title string, date time.Time, fields []Meta, out string, err error) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
e := Entry{title, date, fields}
|
||||
e := Entry{title, date, fields, false}
|
||||
o, er := json.Marshal(e)
|
||||
if err == nil {
|
||||
assert.JSONEq(t, out, string(o))
|
||||
|
|
@ -275,6 +272,22 @@ func TestEntryJsonUnmarshal(t *testing.T) {
|
|||
[]Meta{{"posted", when.Add(-time.Hour)}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"json-field",
|
||||
`{"title":"A Title","date":"` + whens + `","json":{"age": 41, "cool": true, "name": "Jim"}}`,
|
||||
"A Title",
|
||||
when,
|
||||
[]Meta{{"age", int64(41)}, {"cool", true}, {"name", "Jim"}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"json-field-embed",
|
||||
`{"title":"A Title","date":"` + whens + `","json":"{\"age\": 41, \"cool\": true, \"name\": \"Jim\"}"}`,
|
||||
"A Title",
|
||||
when,
|
||||
[]Meta{{"age", int64(41)}, {"cool", true}, {"name", "Jim"}},
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue