Skip to main content

htmltoadf/tests/
lists.rs

1#[allow(unused_imports)]
2use super::assert_output_json_eq;
3
4#[allow(unused_imports)]
5use serde_json::json;
6
7#[cfg(test)]
8#[test]
9fn single_level_ul() {
10    assert_output_json_eq(
11        r"
12          <ul>
13            <li>Item One</li>
14            <li>Item Two</li>
15            <li>Item Three</li>
16          </ul>
17        ",
18        json!({
19          "version": 1,
20          "type": "doc",
21          "content": [
22            {
23              "type": "bulletList",
24              "content": [
25                {
26                  "type": "listItem",
27                  "content": [
28                    {
29                      "type": "paragraph",
30                      "content": [
31                        {
32                          "type": "text",
33                          "text": "Item One"
34                        }
35                      ]
36                    }
37                  ]
38                },
39                {
40                  "type": "listItem",
41                  "content": [
42                    {
43                      "type": "paragraph",
44                      "content": [
45                        {
46                          "type": "text",
47                          "text": "Item Two"
48                        }
49                      ]
50                    }
51                  ]
52                },
53                {
54                  "type": "listItem",
55                  "content": [
56                    {
57                      "type": "paragraph",
58                      "content": [
59                        {
60                          "type": "text",
61                          "text": "Item Three"
62                        }
63                      ]
64                    }
65                  ]
66                }
67              ]
68            }
69          ]
70        }),
71    );
72}
73
74#[test]
75fn single_level_ol() {
76    assert_output_json_eq(
77        r"
78          <ol>
79            <li>Item One</li>
80            <li>Item Two</li>
81            <li>Item Three</li>
82          </ol>
83        ",
84        json!({
85          "version": 1,
86          "type": "doc",
87          "content": [
88            {
89              "type": "orderedList",
90              "content": [
91                {
92                  "type": "listItem",
93                  "content": [
94                    {
95                      "type": "paragraph",
96                      "content": [
97                        {
98                          "type": "text",
99                          "text": "Item One"
100                        }
101                      ]
102                    }
103                  ]
104                },
105                {
106                  "type": "listItem",
107                  "content": [
108                    {
109                      "type": "paragraph",
110                      "content": [
111                        {
112                          "type": "text",
113                          "text": "Item Two"
114                        }
115                      ]
116                    }
117                  ]
118                },
119                {
120                  "type": "listItem",
121                  "content": [
122                    {
123                      "type": "paragraph",
124                      "content": [
125                        {
126                          "type": "text",
127                          "text": "Item Three"
128                        }
129                      ]
130                    }
131                  ]
132                }
133              ]
134            }
135          ]
136        }),
137    );
138}
139
140#[test]
141fn nested_1() {
142    assert_output_json_eq(
143        r"
144          <ul>
145            <li>
146              Nested List
147              <ol>
148                <li>Item One</li>
149                <li>Item Two</li>
150                <li>Item Three</li>
151              </ol>
152            </li>
153          </ul>
154        ",
155        json!({
156          "version": 1,
157          "type": "doc",
158          "content": [
159            {
160              "type": "bulletList",
161              "content": [
162                {
163                  "type": "listItem",
164                  "content": [
165                    {
166                      "type": "paragraph",
167                      "content": [
168                        {
169                          "type": "text",
170                          "text": " Nested List "
171                        }
172                      ]
173                    },
174                    {
175                      "type": "orderedList",
176                      "content": [
177                        {
178                          "type": "listItem",
179                          "content": [
180                            {
181                              "type": "paragraph",
182                              "content": [
183                                {
184                                  "type": "text",
185                                  "text": "Item One"
186                                }
187                              ]
188                            }
189                          ]
190                        },
191                        {
192                          "type": "listItem",
193                          "content": [
194                            {
195                              "type": "paragraph",
196                              "content": [
197                                {
198                                  "type": "text",
199                                  "text": "Item Two"
200                                }
201                              ]
202                            }
203                          ]
204                        },
205                        {
206                          "type": "listItem",
207                          "content": [
208                            {
209                              "type": "paragraph",
210                              "content": [
211                                {
212                                  "type": "text",
213                                  "text": "Item Three"
214                                }
215                              ]
216                            }
217                          ]
218                        }
219                      ]
220                    }
221                  ]
222                }
223              ]
224            }
225          ]
226        }),
227    );
228}