-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90675b6
commit cf0437d
Showing
8 changed files
with
217 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extern crate ringbuffer; | ||
|
||
use ringbuffer::ConstGenericRingBuffer; | ||
|
||
fn main() { | ||
let _ = ConstGenericRingBuffer::<i32, 0>::new(); | ||
//~^ note: the above error was encountered while instantiating `fn ringbuffer::ConstGenericRingBuffer::<i32, 0>::new::<0>` | ||
// ringbuffer can't be zero length | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/compile-fail/test_const_generic_array_zero_length_new.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extern crate ringbuffer; | ||
|
||
use ringbuffer::{ConstGenericRingBuffer, RingBuffer}; | ||
|
||
fn main() { | ||
let mut buf = ConstGenericRingBuffer::new::<0>(); | ||
//~^ note: the above error was encountered while instantiating `fn ringbuffer::ConstGenericRingBuffer::<i32, 0>::new::<0>` | ||
// ringbuffer can't be zero length | ||
buf.push(5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extern crate compiletest_rs as compiletest; | ||
|
||
use std::path::PathBuf; | ||
|
||
#[cfg(test)] | ||
mod conversions; | ||
|
||
fn run_mode(mode: &'static str) { | ||
let mut config = compiletest::Config::default(); | ||
|
||
config.mode = mode.parse().expect("Invalid mode"); | ||
config.src_base = PathBuf::from(format!("tests/{}", mode)); | ||
config.link_deps(); // Populate config.target_rustcflags with dependencies on the path | ||
config.clean_rmeta(); // If your tests import the parent crate, this helps with E0464 | ||
|
||
compiletest::run_tests(&config); | ||
} | ||
|
||
#[test] | ||
#[cfg_attr(miri, ignore)] | ||
fn compile_test() { | ||
run_mode("compile-fail"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
extern crate alloc; | ||
|
||
use alloc::collections::{LinkedList, VecDeque}; | ||
use alloc::string::ToString; | ||
use core::ops::Deref; | ||
use ringbuffer::RingBuffer; | ||
use ringbuffer::{AllocRingBuffer, ConstGenericRingBuffer, GrowableAllocRingBuffer}; | ||
use std::vec; | ||
|
||
macro_rules! convert_test { | ||
($name: ident: $from: expr => $to: ty) => { | ||
#[test] | ||
fn $name() { | ||
let a = $from; | ||
|
||
let mut b: $to = a.into(); | ||
assert_eq!(b.to_vec(), vec!['1', '2']); | ||
b.push('3'); | ||
assert_eq!(b, b); | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! convert_tests { | ||
( | ||
[$($name: ident: $from: expr),* $(,)?] | ||
=> $to: ty | ||
) => { | ||
$( | ||
convert_test!($name: $from => $to); | ||
)* | ||
}; | ||
} | ||
|
||
convert_tests!( | ||
[ | ||
alloc_from_vec: vec!['1', '2'], | ||
alloc_from_ll: {let mut l = LinkedList::new(); l.push_back('1'); l.push_back('2'); l}, | ||
alloc_from_vd: {let mut l = VecDeque::new(); l.push_back('1'); l.push_back('2'); l}, | ||
alloc_from_str: "12".to_string(), | ||
alloc_from_str_slice: "12", | ||
alloc_from_slice: {let a: &[char] = &['1', '2']; a}, | ||
alloc_from_const_slice: {let a: &[char; 2] = &['1', '2']; a}, | ||
alloc_from_arr: {let a: [char; 2] = ['1', '2']; a}, | ||
|
||
alloc_from_cgrb: {let a = ConstGenericRingBuffer::from(['1', '2']); a}, | ||
alloc_from_garb: {let a = GrowableAllocRingBuffer::from(['1', '2']); a}, | ||
] => AllocRingBuffer::<_> | ||
); | ||
|
||
convert_tests!( | ||
[ | ||
growable_alloc_from_vec: vec!['1', '2'], | ||
growable_alloc_from_ll: {let mut l = LinkedList::new(); l.push_back('1'); l.push_back('2'); l}, | ||
growable_alloc_from_vd: {let mut l = VecDeque::new(); l.push_back('1'); l.push_back('2'); l}, | ||
growable_alloc_from_str: "12".to_string(), | ||
growable_alloc_from_str_slice: "12", | ||
growable_alloc_from_slice: {let a: &[char] = &['1', '2']; a}, | ||
growable_alloc_from_const_slice: {let a: &[char; 2] = &['1', '2']; a}, | ||
growable_alloc_from_arr: {let a: [char; 2] = ['1', '2']; a}, | ||
|
||
growable_alloc_from_cgrb: {let a = ConstGenericRingBuffer::from(['1', '2']); a}, | ||
growable_alloc_from_arb: {let a = AllocRingBuffer::from(['1', '2']); a}, | ||
] => GrowableAllocRingBuffer::<_> | ||
); | ||
|
||
convert_tests!( | ||
[ | ||
const_from_vec: vec!['1', '2'], | ||
const_from_ll: {let mut l = LinkedList::new(); l.push_back('1'); l.push_back('2'); l}, | ||
const_from_vd: {let mut l = VecDeque::new(); l.push_back('1'); l.push_back('2'); l}, | ||
const_from_str: "12".to_string(), | ||
const_from_str_slice: "12", | ||
const_from_slice: {let a: &[char] = &['1', '2']; a}, | ||
const_from_const_slice: {let a: &[char; 2] = &['1', '2']; a}, | ||
const_from_arr: {let a: [char; 2] = ['1', '2']; a}, | ||
|
||
const_from_garb: {let a = GrowableAllocRingBuffer::from(['1', '2']); a}, | ||
const_from_arb: {let a = AllocRingBuffer::from(['1', '2']); a}, | ||
] => ConstGenericRingBuffer::<_, 2> | ||
); | ||
|
||
#[test] | ||
fn test_extra_conversions_growable() { | ||
let a: &mut [i32; 2] = &mut [1, 2]; | ||
let a = GrowableAllocRingBuffer::from(a); | ||
assert_eq!(a.to_vec(), vec![1, 2]); | ||
|
||
let a: &mut [i32] = &mut [1, 2]; | ||
let a = GrowableAllocRingBuffer::from(a); | ||
assert_eq!(a.to_vec(), vec![1, 2]); | ||
|
||
let mut b = VecDeque::<i32>::new(); | ||
b.push_back(1); | ||
b.push_back(2); | ||
assert_eq!(a.deref(), &b); | ||
assert_eq!(a.as_ref(), &b); | ||
} | ||
|
||
#[test] | ||
fn test_extra_conversions_alloc() { | ||
let a: &mut [i32; 2] = &mut [1, 2]; | ||
let a = AllocRingBuffer::from(a); | ||
assert_eq!(a.to_vec(), vec![1, 2]); | ||
|
||
let a: &mut [i32] = &mut [1, 2]; | ||
let a = AllocRingBuffer::from(a); | ||
assert_eq!(a.to_vec(), vec![1, 2]); | ||
} | ||
|
||
#[test] | ||
fn test_extra_conversions_const() { | ||
let a: &mut [i32; 2] = &mut [1, 2]; | ||
let a = ConstGenericRingBuffer::<_, 2>::from(a); | ||
assert_eq!(a.to_vec(), vec![1, 2]); | ||
|
||
let a: &mut [i32] = &mut [1, 2]; | ||
let a = ConstGenericRingBuffer::<_, 2>::from(a); | ||
assert_eq!(a.to_vec(), vec![1, 2]); | ||
} | ||
|
||
#[test] | ||
fn test_const_generic_new_parameter() { | ||
// Can we specify size only on the method? | ||
let mut a = ConstGenericRingBuffer::new::<2>(); | ||
a.push(5); | ||
|
||
// Can we specify size in both positions? | ||
let mut a = ConstGenericRingBuffer::<i32, 50>::new::<50>(); | ||
a.push(5); | ||
|
||
// Can we specify size only on the struct? | ||
let mut a = ConstGenericRingBuffer::<i32, 50>::new(); | ||
a.push(5); | ||
} |
cf0437d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://650594c290e9f30b0bc2007b--ringbuffer.netlify.app