##// END OF EJS Templates
rust-revlog: make `IndexEntryBuilder` build a whole entry...
Martin von Zweigbergk -
r49984:2a9a55ff default
parent child Browse files
Show More
@@ -282,6 +282,10 b" impl<'a> IndexEntry<'a> {"
282 BigEndian::read_i32(&self.bytes[16..])
282 BigEndian::read_i32(&self.bytes[16..])
283 }
283 }
284
284
285 pub fn link_revision(&self) -> Revision {
286 BigEndian::read_i32(&self.bytes[20..])
287 }
288
285 pub fn p1(&self) -> Revision {
289 pub fn p1(&self) -> Revision {
286 BigEndian::read_i32(&self.bytes[24..])
290 BigEndian::read_i32(&self.bytes[24..])
287 }
291 }
@@ -302,6 +306,7 b" impl<'a> IndexEntry<'a> {"
302 #[cfg(test)]
306 #[cfg(test)]
303 mod tests {
307 mod tests {
304 use super::*;
308 use super::*;
309 use crate::node::NULL_NODE;
305
310
306 #[cfg(test)]
311 #[cfg(test)]
307 #[derive(Debug, Copy, Clone)]
312 #[derive(Debug, Copy, Clone)]
@@ -314,6 +319,10 b' mod tests {'
314 compressed_len: usize,
319 compressed_len: usize,
315 uncompressed_len: usize,
320 uncompressed_len: usize,
316 base_revision_or_base_of_delta_chain: Revision,
321 base_revision_or_base_of_delta_chain: Revision,
322 link_revision: Revision,
323 p1: Revision,
324 p2: Revision,
325 node: Node,
317 }
326 }
318
327
319 #[cfg(test)]
328 #[cfg(test)]
@@ -328,6 +337,10 b' mod tests {'
328 compressed_len: 0,
337 compressed_len: 0,
329 uncompressed_len: 0,
338 uncompressed_len: 0,
330 base_revision_or_base_of_delta_chain: 0,
339 base_revision_or_base_of_delta_chain: 0,
340 link_revision: 0,
341 p1: NULL_REVISION,
342 p2: NULL_REVISION,
343 node: NULL_NODE,
331 }
344 }
332 }
345 }
333
346
@@ -374,6 +387,26 b' mod tests {'
374 self
387 self
375 }
388 }
376
389
390 pub fn with_link_revision(&mut self, value: Revision) -> &mut Self {
391 self.link_revision = value;
392 self
393 }
394
395 pub fn with_p1(&mut self, value: Revision) -> &mut Self {
396 self.p1 = value;
397 self
398 }
399
400 pub fn with_p2(&mut self, value: Revision) -> &mut Self {
401 self.p2 = value;
402 self
403 }
404
405 pub fn with_node(&mut self, value: Node) -> &mut Self {
406 self.node = value;
407 self
408 }
409
377 pub fn build(&self) -> Vec<u8> {
410 pub fn build(&self) -> Vec<u8> {
378 let mut bytes = Vec::with_capacity(INDEX_ENTRY_SIZE);
411 let mut bytes = Vec::with_capacity(INDEX_ENTRY_SIZE);
379 if self.is_first {
412 if self.is_first {
@@ -396,6 +429,11 b' mod tests {'
396 bytes.extend(
429 bytes.extend(
397 &self.base_revision_or_base_of_delta_chain.to_be_bytes(),
430 &self.base_revision_or_base_of_delta_chain.to_be_bytes(),
398 );
431 );
432 bytes.extend(&self.link_revision.to_be_bytes());
433 bytes.extend(&self.p1.to_be_bytes());
434 bytes.extend(&self.p2.to_be_bytes());
435 bytes.extend(self.node.as_bytes());
436 bytes.extend(vec![0u8; 12]);
399 bytes
437 bytes
400 }
438 }
401 }
439 }
@@ -514,6 +552,56 b' mod tests {'
514 }
552 }
515
553
516 #[test]
554 #[test]
555 fn link_revision_test() {
556 let bytes = IndexEntryBuilder::new().with_link_revision(123).build();
557
558 let entry = IndexEntry {
559 bytes: &bytes,
560 offset_override: None,
561 };
562
563 assert_eq!(entry.link_revision(), 123);
564 }
565
566 #[test]
567 fn p1_test() {
568 let bytes = IndexEntryBuilder::new().with_p1(123).build();
569
570 let entry = IndexEntry {
571 bytes: &bytes,
572 offset_override: None,
573 };
574
575 assert_eq!(entry.p1(), 123);
576 }
577
578 #[test]
579 fn p2_test() {
580 let bytes = IndexEntryBuilder::new().with_p2(123).build();
581
582 let entry = IndexEntry {
583 bytes: &bytes,
584 offset_override: None,
585 };
586
587 assert_eq!(entry.p2(), 123);
588 }
589
590 #[test]
591 fn node_test() {
592 let node = Node::from_hex("0123456789012345678901234567890123456789")
593 .unwrap();
594 let bytes = IndexEntryBuilder::new().with_node(node).build();
595
596 let entry = IndexEntry {
597 bytes: &bytes,
598 offset_override: None,
599 };
600
601 assert_eq!(*entry.hash(), node);
602 }
603
604 #[test]
517 fn version_test() {
605 fn version_test() {
518 let bytes = IndexEntryBuilder::new()
606 let bytes = IndexEntryBuilder::new()
519 .is_first(true)
607 .is_first(true)
General Comments 0
You need to be logged in to leave comments. Login now