Skip to content

Commit

Permalink
cover invalid codec errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-k committed Jan 28, 2025
1 parent c7a1eaa commit ad8f9a0
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
57 changes: 57 additions & 0 deletions bio-seq-derive/tests/fail/invalid_codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use bio_seq::prelude::*;

#[derive(Codec)]
struct NotEnum {
a: (),
c: (),
g: (),
t: (),
}

#[derive(Codec)]
enum NoDiscriminants {
A,
C,
G,
T,
}

#[derive(Codec, PartialEq, Debug, Hash)]
#[bits(2)]
enum BadWidth {
A = 0b000,
C = 0b001,
G = 0b010,
T = 0b100,
X = 0b011,
}

#[derive(Codec, PartialEq, Debug, Hash, Eq, Copy, Clone)]
#[bits(3)]
enum BadDiscriminant {
A = 0b000,
C = 3,
G = 0b010,
T = 0x04,
X = 1.0,
}

// Test whether codec is #[repr(u8)]
/*
#[derive(Codec, Eq, Debug, Hash, PartialEq, Copy, Clone)]
enum NoRepr {
A = 0b11,
C = 0b01,
G = 0b00,
T = 0b10,
}
*/

fn main() {
let _c = NotEnum {
a: (),
c: (),
g: (),
t: (),
};
}
34 changes: 34 additions & 0 deletions bio-seq-derive/tests/fail/invalid_codec.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error: Codec can only be derived for enums
--> tests/fail/invalid_codec.rs:4:1
|
4 | / struct NotEnum {
5 | | a: (),
6 | | c: (),
7 | | g: (),
8 | | t: (),
9 | | }
| |_^

error: Codec derivations require discriminants
--> tests/fail/invalid_codec.rs:13:5
|
13 | A,
| ^

error: Bit width is not large enough encode all variants (min: 3)
--> tests/fail/invalid_codec.rs:20:1
|
20 | #[bits(2)]
| ^^^^^^^^^^

error: Codec derivations require byte or integer discriminants
--> tests/fail/invalid_codec.rs:36:5
|
36 | X = 1.0,
| ^

error[E0308]: mismatched types
--> tests/fail/invalid_codec.rs:36:9
|
36 | X = 1.0,
| ^^^ expected `isize`, found floating-point number
6 changes: 6 additions & 0 deletions bio-seq-derive/tests/fail/non_ascii.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use bio_seq::prelude::*;

fn main() {
let _seq = iupac!("ACNSWGT🤬");
let _seq = dna!("ACG🫣T");
}
11 changes: 11 additions & 0 deletions bio-seq-derive/tests/fail/non_ascii.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: Non-ASCII characters in IUPAC string
--> tests/fail/non_ascii.rs:4:23
|
4 | let _seq = iupac!("ACNSWGT🤬");
| ^^^^^^^^^^^

error: Non-ASCII characters in DNA string
--> tests/fail/non_ascii.rs:5:21
|
5 | let _seq = dna!("ACG🫣T");
| ^^^^^^^^

0 comments on commit ad8f9a0

Please sign in to comment.