()
| 1124 | |
| 1125 | #[test] |
| 1126 | fn split_block() { |
| 1127 | let mut layout = Layout::new(); |
| 1128 | |
| 1129 | let e0 = Block::new(0); |
| 1130 | let e1 = Block::new(1); |
| 1131 | let e2 = Block::new(2); |
| 1132 | |
| 1133 | let i0 = Inst::new(0); |
| 1134 | let i1 = Inst::new(1); |
| 1135 | let i2 = Inst::new(2); |
| 1136 | let i3 = Inst::new(3); |
| 1137 | |
| 1138 | layout.append_block(e0); |
| 1139 | layout.append_inst(i0, e0); |
| 1140 | assert_eq!(layout.inst_block(i0), Some(e0)); |
| 1141 | layout.split_block(e1, i0); |
| 1142 | assert_eq!(layout.inst_block(i0), Some(e1)); |
| 1143 | |
| 1144 | { |
| 1145 | let mut cur = LayoutCursor::new(&mut layout); |
| 1146 | assert_eq!(cur.next_block(), Some(e0)); |
| 1147 | assert_eq!(cur.next_inst(), None); |
| 1148 | assert_eq!(cur.next_block(), Some(e1)); |
| 1149 | assert_eq!(cur.next_inst(), Some(i0)); |
| 1150 | assert_eq!(cur.next_inst(), None); |
| 1151 | assert_eq!(cur.next_block(), None); |
| 1152 | |
| 1153 | // Check backwards links. |
| 1154 | assert_eq!(cur.prev_block(), Some(e1)); |
| 1155 | assert_eq!(cur.prev_inst(), Some(i0)); |
| 1156 | assert_eq!(cur.prev_inst(), None); |
| 1157 | assert_eq!(cur.prev_block(), Some(e0)); |
| 1158 | assert_eq!(cur.prev_inst(), None); |
| 1159 | assert_eq!(cur.prev_block(), None); |
| 1160 | } |
| 1161 | |
| 1162 | layout.append_inst(i1, e0); |
| 1163 | layout.append_inst(i2, e0); |
| 1164 | layout.append_inst(i3, e0); |
| 1165 | layout.split_block(e2, i2); |
| 1166 | |
| 1167 | assert_eq!(layout.inst_block(i0), Some(e1)); |
| 1168 | assert_eq!(layout.inst_block(i1), Some(e0)); |
| 1169 | assert_eq!(layout.inst_block(i2), Some(e2)); |
| 1170 | assert_eq!(layout.inst_block(i3), Some(e2)); |
| 1171 | |
| 1172 | { |
| 1173 | let mut cur = LayoutCursor::new(&mut layout); |
| 1174 | assert_eq!(cur.next_block(), Some(e0)); |
| 1175 | assert_eq!(cur.next_inst(), Some(i1)); |
| 1176 | assert_eq!(cur.next_inst(), None); |
| 1177 | assert_eq!(cur.next_block(), Some(e2)); |
| 1178 | assert_eq!(cur.next_inst(), Some(i2)); |
| 1179 | assert_eq!(cur.next_inst(), Some(i3)); |
| 1180 | assert_eq!(cur.next_inst(), None); |
| 1181 | assert_eq!(cur.next_block(), Some(e1)); |
| 1182 | assert_eq!(cur.next_inst(), Some(i0)); |
| 1183 | assert_eq!(cur.next_inst(), None); |
nothing calls this directly
no test coverage detected