()
| 1108 | |
| 1109 | #[test] |
| 1110 | fn read_str_advance_basic() { |
| 1111 | // fixstr "hi" |
| 1112 | let mut off = 0; |
| 1113 | let buf = encode(&json!("hi")); |
| 1114 | assert_eq!(read_str_advance(&buf, &mut off), Some("hi")); |
| 1115 | assert_eq!(off, buf.len()); |
| 1116 | |
| 1117 | // Sequential reads |
| 1118 | let buf = encode(&json!(["one", "two"])); |
| 1119 | let (count, mut off) = array_header(&buf, 0).unwrap(); |
| 1120 | assert_eq!(count, 2); |
| 1121 | assert_eq!(read_str_advance(&buf, &mut off), Some("one")); |
| 1122 | assert_eq!(read_str_advance(&buf, &mut off), Some("two")); |
| 1123 | assert_eq!(off, buf.len()); |
| 1124 | |
| 1125 | // Non-string returns None. |
| 1126 | let mut off = 0; |
| 1127 | assert_eq!(read_str_advance(&[NIL], &mut off), None); |
| 1128 | assert_eq!(off, 0); |
| 1129 | } |
| 1130 | |
| 1131 | /// Empty buffer must return `None` for all functions that can. |
| 1132 | #[test] |
nothing calls this directly
no test coverage detected