Skip to content

Commit

Permalink
Add all serde Record<N> tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSimonetto committed Sep 1, 2022
1 parent 530aec3 commit 80f6b38
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 2 deletions.
117 changes: 116 additions & 1 deletion noodles-bed/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ impl<'de> SeqAccess<'de> for RecordDeserializer<'de> {

#[cfg(test)]
mod serde_tests {
use crate::{record::Name, Record};
use crate::{
record::{Color, Name, Score, Strand},
Record,
};

use super::*;

Expand Down Expand Up @@ -180,4 +183,116 @@ mod serde_tests {

assert_eq!(result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_5_wrapper() {
let input = "sq0\t7\t13\t.\t21";
let result: Record<5> = record_from_str(input).unwrap();

let expected = Record::<5>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(noodles_core::Position::try_from(8).unwrap())
.set_end_position(noodles_core::Position::try_from(13).unwrap())
.set_score(Score::try_from(21).unwrap())
.build()
.unwrap();

assert_eq!(result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_6_wrapper() {
let input = "sq0\t7\t13\t.\t0\t+";
let result: Record<6> = record_from_str(input).unwrap();

let expected = Record::<6>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(noodles_core::Position::try_from(8).unwrap())
.set_end_position(noodles_core::Position::try_from(13).unwrap())
.set_strand(Strand::Forward)
.build()
.unwrap();

assert_eq!(result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_7_wrapper() {
let input = "sq0\t7\t13\t.\t0\t.\t7";
let result: Record<7> = record_from_str(input).unwrap();

let start = noodles_core::Position::try_from(8).unwrap();

let expected = Record::<7>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(noodles_core::Position::try_from(13).unwrap())
.set_thick_start(start)
.build()
.unwrap();

assert_eq!(result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_8_wrapper() {
let input = "sq0\t7\t13\t.\t0\t.\t7\t13";
let result: Record<8> = record_from_str(input).unwrap();

let start = noodles_core::Position::try_from(8).unwrap();
let end = noodles_core::Position::try_from(13).unwrap();

let expected = Record::<8>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(end)
.set_thick_start(start)
.set_thick_end(end)
.build()
.unwrap();

assert_eq!(result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_9_wrapper() {
let input = "sq0\t7\t13\t.\t0\t.\t7\t13\t255,0,0";
let result: Record<9> = record_from_str(input).unwrap();

let start = noodles_core::Position::try_from(8).unwrap();
let end = noodles_core::Position::try_from(13).unwrap();

let expected = Record::<9>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(end)
.set_thick_start(start)
.set_thick_end(end)
.set_color(Color::RED)
.build()
.unwrap();

assert_eq!(result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_12_wrapper() {
let input = "sq0\t7\t13\t.\t0\t.\t7\t13\t0\t1\t2\t0";
let result: Record<12> = record_from_str(input).unwrap();

let start = noodles_core::Position::try_from(8).unwrap();
let end = noodles_core::Position::try_from(13).unwrap();

let expected = Record::<12>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(end)
.set_thick_start(start)
.set_thick_end(end)
.set_blocks(vec![(0, 2)])
.build()
.unwrap();

assert_eq!(result, expected);
}
}
116 changes: 115 additions & 1 deletion noodles-bed/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ impl<'a> ser::SerializeStructVariant for &'a mut Record3Serializer {
}
#[cfg(test)]
mod serde_tests {
use crate::{record::Name, Record};
use crate::{
record::{Color, Name, Score, Strand},
Record,
};

use super::*;

Expand Down Expand Up @@ -422,6 +425,117 @@ mod serde_tests {
assert_eq!(&result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_5_wrapper() {
let record = Record::<5>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(noodles_core::Position::try_from(8).unwrap())
.set_end_position(noodles_core::Position::try_from(13).unwrap())
.set_score(Score::try_from(21).unwrap())
.build()
.unwrap();

let result = record_to_string(record).unwrap();
let expected = "sq0\t7\t13\t.\t21";

assert_eq!(&result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_6_wrapper() {
let record = Record::<6>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(noodles_core::Position::try_from(8).unwrap())
.set_end_position(noodles_core::Position::try_from(13).unwrap())
.set_strand(Strand::Forward)
.build()
.unwrap();

let result = record_to_string(record).unwrap();
let expected = "sq0\t7\t13\t.\t0\t+";

assert_eq!(&result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_7_wrapper() {
let start = noodles_core::Position::try_from(8).unwrap();

let record = Record::<7>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(noodles_core::Position::try_from(13).unwrap())
.set_thick_start(start)
.build()
.unwrap();

let result = record_to_string(record).unwrap();
let expected = "sq0\t7\t13\t.\t0\t.\t7";

assert_eq!(&result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_8_wrapper() {
let start = noodles_core::Position::try_from(8).unwrap();
let end = noodles_core::Position::try_from(13).unwrap();

let record = Record::<8>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(end)
.set_thick_start(start)
.set_thick_end(end)
.build()
.unwrap();

let result = record_to_string(record).unwrap();
let expected = "sq0\t7\t13\t.\t0\t.\t7\t13";

assert_eq!(&result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_9_wrapper() {
let start = noodles_core::Position::try_from(8).unwrap();
let end = noodles_core::Position::try_from(13).unwrap();

let record = Record::<9>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(end)
.set_thick_start(start)
.set_thick_end(end)
.set_color(Color::RED)
.build()
.unwrap();

let result = record_to_string(record).unwrap();
let expected = "sq0\t7\t13\t.\t0\t.\t7\t13\t255,0,0";

assert_eq!(&result, expected);
}

#[test]
fn test_to_string_single_auxiliar_bed_record_12_wrapper() {
let start = noodles_core::Position::try_from(8).unwrap();
let end = noodles_core::Position::try_from(13).unwrap();

let record = Record::<12>::builder()
.set_reference_sequence_name("sq0")
.set_start_position(start)
.set_end_position(end)
.set_thick_start(start)
.set_thick_end(end)
.set_blocks(vec![(0, 2)])
.build()
.unwrap();

let result = record_to_string(record).unwrap();
let expected = "sq0\t7\t13\t.\t0\t.\t7\t13\t0\t1\t2\t0";

assert_eq!(&result, expected);
}
// TODO
// #[test]
// fn test_to_bytes_single_record() { }
Expand Down

0 comments on commit 80f6b38

Please sign in to comment.