@@ -1116,6 +1116,7 @@ mod tests {
11161116 assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "target" ) ) ) ;
11171117 assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "target" ) ) ) ;
11181118 assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "root" ) ) ) ;
1119+ assert_eq ! ( de. next( ) . unwrap( ) , Eof ) ;
11191120 }
11201121
11211122 /// Checks that `read_to_end()` behaves correctly after `skip()`
@@ -1203,6 +1204,195 @@ mod tests {
12031204 de. read_to_end ( QName ( b"skip" ) ) . unwrap ( ) ;
12041205
12051206 assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "root" ) ) ) ;
1207+ assert_eq ! ( de. next( ) . unwrap( ) , Eof ) ;
1208+ }
1209+
1210+ /// Checks that replay replayes only part of events
1211+ /// Test for https://github.com/tafia/quick-xml/issues/435
1212+ #[ test]
1213+ fn partial_replay ( ) {
1214+ let mut de = Deserializer :: from_str (
1215+ r#"
1216+ <root>
1217+ <skipped-1/>
1218+ <skipped-2/>
1219+ <inner>
1220+ <skipped-3/>
1221+ <skipped-4/>
1222+ <target-2/>
1223+ </inner>
1224+ <target-1/>
1225+ </root>
1226+ "# ,
1227+ ) ;
1228+
1229+ // Initial conditions - both are empty
1230+ assert_eq ! ( de. read, vec![ ] ) ;
1231+ assert_eq ! ( de. write, vec![ ] ) ;
1232+
1233+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "root" ) ) ) ;
1234+
1235+ // Should skip first and second <skipped-N/> elements
1236+ de. skip ( ) . unwrap ( ) ; // skipped-1
1237+ de. skip ( ) . unwrap ( ) ; // skipped-2
1238+ assert_eq ! ( de. read, vec![ ] ) ;
1239+ assert_eq ! (
1240+ de. write,
1241+ vec![
1242+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1243+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1244+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1245+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1246+ ]
1247+ ) ;
1248+
1249+ ////////////////////////////////////////////////////////////////////////////////////////
1250+
1251+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "inner" ) ) ) ;
1252+ assert_eq ! ( de. peek( ) . unwrap( ) , & Start ( BytesStart :: new( "skipped-3" ) ) ) ;
1253+ assert_eq ! (
1254+ de. read,
1255+ vec![
1256+ // This comment here to keep the same formatting of both arrays
1257+ // otherwise rustfmt suggest one-line it
1258+ Start ( BytesStart :: new( "skipped-3" ) ) ,
1259+ ]
1260+ ) ;
1261+ assert_eq ! (
1262+ de. write,
1263+ vec![
1264+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1265+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1266+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1267+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1268+ ]
1269+ ) ;
1270+
1271+ // Should skip third and forth <skipped-N/> elements
1272+ de. skip ( ) . unwrap ( ) ; // skipped-3
1273+ de. skip ( ) . unwrap ( ) ; // skipped-4
1274+ assert_eq ! ( de. read, vec![ ] ) ;
1275+ assert_eq ! (
1276+ de. write,
1277+ vec![
1278+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1279+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1280+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1281+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1282+ // split point
1283+ Start ( BytesStart :: new( "skipped-3" ) ) ,
1284+ End ( BytesEnd :: new( "skipped-3" ) ) ,
1285+ Start ( BytesStart :: new( "skipped-4" ) ) ,
1286+ End ( BytesEnd :: new( "skipped-4" ) ) ,
1287+ ]
1288+ ) ;
1289+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "target-2" ) ) ) ;
1290+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "target-2" ) ) ) ;
1291+ assert_eq ! ( de. peek( ) . unwrap( ) , & End ( BytesEnd :: new( "inner" ) ) ) ;
1292+ assert_eq ! (
1293+ de. read,
1294+ vec![
1295+ // This comment here to keep the same formatting of both arrays
1296+ // otherwise rustfmt suggest one-line it
1297+ End ( BytesEnd :: new( "inner" ) ) ,
1298+ ]
1299+ ) ;
1300+ assert_eq ! (
1301+ de. write,
1302+ vec![
1303+ // checkpoint 1
1304+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1305+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1306+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1307+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1308+ // checkpoint 2
1309+ Start ( BytesStart :: new( "skipped-3" ) ) ,
1310+ End ( BytesEnd :: new( "skipped-3" ) ) ,
1311+ Start ( BytesStart :: new( "skipped-4" ) ) ,
1312+ End ( BytesEnd :: new( "skipped-4" ) ) ,
1313+ ]
1314+ ) ;
1315+
1316+ de. start_replay ( ) ;
1317+ assert_eq ! (
1318+ de. read,
1319+ vec![
1320+ Start ( BytesStart :: new( "skipped-3" ) ) ,
1321+ End ( BytesEnd :: new( "skipped-3" ) ) ,
1322+ Start ( BytesStart :: new( "skipped-4" ) ) ,
1323+ End ( BytesEnd :: new( "skipped-4" ) ) ,
1324+ End ( BytesEnd :: new( "inner" ) ) ,
1325+ ]
1326+ ) ;
1327+ assert_eq ! (
1328+ de. write,
1329+ vec![
1330+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1331+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1332+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1333+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1334+ ]
1335+ ) ;
1336+
1337+ // Replayed events
1338+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "skipped-3" ) ) ) ;
1339+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "skipped-3" ) ) ) ;
1340+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "skipped-4" ) ) ) ;
1341+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "skipped-4" ) ) ) ;
1342+
1343+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "inner" ) ) ) ;
1344+ assert_eq ! ( de. read, vec![ ] ) ;
1345+ assert_eq ! (
1346+ de. write,
1347+ vec![
1348+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1349+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1350+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1351+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1352+ ]
1353+ ) ;
1354+
1355+ ////////////////////////////////////////////////////////////////////////////////////////
1356+
1357+ // New events
1358+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "target-1" ) ) ) ;
1359+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "target-1" ) ) ) ;
1360+
1361+ assert_eq ! ( de. read, vec![ ] ) ;
1362+ assert_eq ! (
1363+ de. write,
1364+ vec![
1365+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1366+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1367+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1368+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1369+ ]
1370+ ) ;
1371+
1372+ de. start_replay ( ) ;
1373+ assert_eq ! (
1374+ de. read,
1375+ vec![
1376+ Start ( BytesStart :: new( "skipped-1" ) ) ,
1377+ End ( BytesEnd :: new( "skipped-1" ) ) ,
1378+ Start ( BytesStart :: new( "skipped-2" ) ) ,
1379+ End ( BytesEnd :: new( "skipped-2" ) ) ,
1380+ ]
1381+ ) ;
1382+ assert_eq ! ( de. write, vec![ ] ) ;
1383+
1384+ // Replayed events
1385+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "skipped-1" ) ) ) ;
1386+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "skipped-1" ) ) ) ;
1387+ assert_eq ! ( de. next( ) . unwrap( ) , Start ( BytesStart :: new( "skipped-2" ) ) ) ;
1388+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "skipped-2" ) ) ) ;
1389+
1390+ assert_eq ! ( de. read, vec![ ] ) ;
1391+ assert_eq ! ( de. write, vec![ ] ) ;
1392+
1393+ // New events
1394+ assert_eq ! ( de. next( ) . unwrap( ) , End ( BytesEnd :: new( "root" ) ) ) ;
1395+ assert_eq ! ( de. next( ) . unwrap( ) , Eof ) ;
12061396 }
12071397
12081398 /// Checks that limiting buffer size works correctly
0 commit comments