Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 22, 2024
1 parent 41d5d11 commit e2cf891
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions vlib/json/tests/json_decode_struct_with_default_test.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module main

import json

pub struct Response {
Expand All @@ -11,14 +9,26 @@ pub:

pub struct Result {
pub:
id int @[json: defid]
author string @[json: author]
definition string @[json: definition]
id int @[json: defid]
author string @[json: author]
definition string @[json: definition]
link string @[json: permalink]
thumbs_down int @[json: thumbs_down]
thumbs_up int @[json: thumbs_up]
word string @[json: word]
date string @[json: written_on]
audio_samples []string @[json: sound_urls]
example string @[json: example]
}

pub fn define(word string) !&Response {
resp := '{"list":[{"defid":3439287}]}'
response := json.decode(Response, resp) or { return err }
return &response
}

fn test_main() {
resp := '{"list": [{"defid":123, "author": "", "definition": "" }]}'
response := json.decode(Response, resp)!
response := define('')!
assert response.results.len > 0
assert response.results[0].id == 123
assert response.results[0].id == 3439287
}

0 comments on commit e2cf891

Please sign in to comment.