v2 / vlib / v / tests / result_with_index_expr_test.v
25 lines · 21 sloc · 713 bytes · 2d33a7f2819dd5fc1f4aa3b3ca0bcc660810d7af
Raw
1import x.json2
2
3struct SomeStruct {
4 title string
5}
6
7fn test_result_with_index() {
8 resp := '{
9 "userId": 1,
10 "id": 1,
11 "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
12 "body": "quia et suscipitsuscipit recusandae consequuntur expedita et cumreprehenderit molestiae ut ut quas totamnostrum rerum est autem sunt rem eveniet architecto"
13}'
14 raw_data := json2.decode[json2.Any](resp)!
15
16 data := raw_data as map[string]json2.Any
17
18 mut ss := map[int]SomeStruct{}
19 s := SomeStruct{
20 title: data['title']!.str()
21 }
22 ss[data['id']!.int()] = s
23 t := ss[data['id']!.int()]
24 assert t.title == 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
25}
26