| 752 | |
| 753 | #[test] |
| 754 | fn test_basic() { |
| 755 | let a = r#" |
| 756 | {"hello": "world", "foo": 2, "bar": 45} |
| 757 | |
| 758 | {"foo": "bar"} |
| 759 | |
| 760 | {"fiz": null} |
| 761 | |
| 762 | {"a": true, "b": false, "c": null} |
| 763 | |
| 764 | {"a": "", "": "a"} |
| 765 | |
| 766 | {"a": "b", "object": {"nested": "hello", "foo": 23}, "b": {}, "c": {"foo": null }} |
| 767 | |
| 768 | {"a": ["", "foo", ["bar", "c"]], "b": {"1": []}, "c": {"2": [1, 2, 3]} } |
| 769 | "#; |
| 770 | let mut decoder = TapeDecoder::new(16, 2); |
| 771 | decoder.decode(a.as_bytes()).unwrap(); |
| 772 | assert!(!decoder.has_partial_row()); |
| 773 | assert_eq!(decoder.num_buffered_rows(), 7); |
| 774 | |
| 775 | let finished = decoder.finish().unwrap(); |
| 776 | assert!(!decoder.has_partial_row()); |
| 777 | assert_eq!(decoder.num_buffered_rows(), 7); // didn't call clear() yet |
| 778 | assert_eq!( |
| 779 | finished.elements, |
| 780 | &[ |
| 781 | TapeElement::Null, |
| 782 | TapeElement::StartObject(8), // {"hello": "world", "foo": 2, "bar": 45} |
| 783 | TapeElement::String(0), // "hello" |
| 784 | TapeElement::String(1), // "world" |
| 785 | TapeElement::String(2), // "foo" |
| 786 | TapeElement::Number(3), // 2 |
| 787 | TapeElement::String(4), // "bar" |
| 788 | TapeElement::Number(5), // 45 |
| 789 | TapeElement::EndObject(1), |
| 790 | TapeElement::StartObject(12), // {"foo": "bar"} |
| 791 | TapeElement::String(6), // "foo" |
| 792 | TapeElement::String(7), // "bar" |
| 793 | TapeElement::EndObject(9), |
| 794 | TapeElement::StartObject(16), // {"fiz": null} |
| 795 | TapeElement::String(8), // "fiz |
| 796 | TapeElement::Null, // null |
| 797 | TapeElement::EndObject(13), |
| 798 | TapeElement::StartObject(24), // {"a": true, "b": false, "c": null} |
| 799 | TapeElement::String(9), // "a" |
| 800 | TapeElement::True, // true |
| 801 | TapeElement::String(10), // "b" |
| 802 | TapeElement::False, // false |
| 803 | TapeElement::String(11), // "c" |
| 804 | TapeElement::Null, // null |
| 805 | TapeElement::EndObject(17), |
| 806 | TapeElement::StartObject(30), // {"a": "", "": "a"} |
| 807 | TapeElement::String(12), // "a" |
| 808 | TapeElement::String(13), // "" |
| 809 | TapeElement::String(14), // "" |
| 810 | TapeElement::String(15), // "a" |
| 811 | TapeElement::EndObject(25), |