| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | import encoding.xml |
| 5 | |
| 6 | fn test_valid_parsing() { |
| 7 | path := os.join_path(os.dir(@FILE), 'attributes.xml') |
| 8 | |
| 9 | expected := xml.XMLDocument{ |
| 10 | root: xml.XMLNode{ |
| 11 | name: 'book' |
| 12 | attributes: { |
| 13 | 'category': 'web' |
| 14 | } |
| 15 | children: [ |
| 16 | xml.XMLNode{ |
| 17 | name: 'title' |
| 18 | attributes: { |
| 19 | 'lang': 'en' |
| 20 | 'code:type': 'const char*' |
| 21 | } |
| 22 | children: ['Learning XML'] |
| 23 | }, |
| 24 | xml.XMLNode{ |
| 25 | name: 'author' |
| 26 | attributes: { |
| 27 | 'attr': ' surrounding spaces ' |
| 28 | } |
| 29 | children: ['Erik T. Ray'] |
| 30 | }, |
| 31 | xml.XMLNode{ |
| 32 | name: 'year' |
| 33 | children: ['2003'] |
| 34 | }, |
| 35 | xml.XMLNode{ |
| 36 | name: 'price' |
| 37 | children: ['39.95'] |
| 38 | }, |
| 39 | ] |
| 40 | } |
| 41 | } |
| 42 | actual := xml.XMLDocument.from_file(path)! |
| 43 | |
| 44 | assert expected == actual, 'Parsed XML document should be equal to expected XML document' |
| 45 | } |
| 46 | |