Skip to content

Commit 5e2f575

Browse files
committed
Move tests to separate module
1 parent ac53b24 commit 5e2f575

File tree

8 files changed

+89
-94
lines changed

8 files changed

+89
-94
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
language: rust
22

3+
env:
4+
- RUST_TEST_THREADS=1
5+
36
script:
47
- cargo build -v
58
- cargo test -v

src/encoder.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -166,51 +166,3 @@ fn encode_bson<W: Write + ?Sized>(writer: &mut W, key: &str, val: &Bson) -> Enco
166166
&Bson::Null => Ok(())
167167
}
168168
}
169-
170-
#[cfg(test)]
171-
mod test {
172-
use super::encode_document;
173-
use bson::{Document, Bson};
174-
175-
#[test]
176-
fn test_encode_floating_point() {
177-
let src = 1020.123;
178-
let dst = [18, 0, 0, 0, 1, 107, 101, 121, 0, 68, 139, 108, 231, 251, 224, 143, 64, 0];
179-
180-
let mut doc = Document::new();
181-
doc.insert("key".to_owned(), Bson::FloatingPoint(src));
182-
183-
let mut buf = Vec::new();
184-
encode_document(&mut buf, &doc).unwrap();
185-
186-
assert_eq!(&buf, &dst);
187-
}
188-
189-
#[test]
190-
fn test_encode_utf8_string() {
191-
let src = "test你好吗".to_owned();
192-
let dst = [28, 0, 0, 0, 2, 107, 101, 121, 0, 14, 0, 0, 0, 116, 101, 115, 116, 228, 189, 160, 229, 165, 189, 229, 144, 151, 0, 0];
193-
194-
let mut doc = Document::new();
195-
doc.insert("key".to_owned(), Bson::String(src));
196-
197-
let mut buf = Vec::new();
198-
encode_document(&mut buf, &doc).unwrap();
199-
200-
assert_eq!(&buf, &dst);
201-
}
202-
203-
#[test]
204-
fn test_encode_array() {
205-
let src = vec![Bson::FloatingPoint(1.01), Bson::String("xyz".to_owned())];
206-
let dst = [37, 0, 0, 0, 4, 107, 101, 121, 0, 27, 0, 0, 0, 1, 48, 0, 41, 92, 143, 194, 245, 40, 240, 63, 2, 49, 0, 4, 0, 0, 0, 120, 121, 122, 0, 0, 0];
207-
208-
let mut doc = Document::new();
209-
doc.insert("key".to_owned(), Bson::Array(src));
210-
211-
let mut buf = Vec::new();
212-
encode_document(&mut buf, &doc).unwrap();
213-
214-
assert_eq!(&buf[..], &dst[..]);
215-
}
216-
}

src/ordered.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -193,45 +193,3 @@ impl OrderedDocument {
193193
self.document.remove(key)
194194
}
195195
}
196-
197-
#[cfg(test)]
198-
mod test {
199-
use super::OrderedDocument;
200-
use bson::Bson;
201-
202-
#[test]
203-
fn ordered_insert() {
204-
let mut doc = OrderedDocument::new();
205-
doc.insert("first".to_owned(), Bson::I32(1));
206-
doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
207-
doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
208-
209-
let expected_keys = vec!(
210-
"first".to_owned(),
211-
"second".to_owned(),
212-
"alphanumeric".to_owned(),
213-
);
214-
215-
let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
216-
assert_eq!(expected_keys, keys);
217-
}
218-
219-
#[test]
220-
fn remove() {
221-
let mut doc = OrderedDocument::new();
222-
doc.insert("first".to_owned(), Bson::I32(1));
223-
doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
224-
doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
225-
226-
assert!(doc.remove("second").is_some());
227-
assert!(doc.remove("none").is_none());
228-
229-
let expected_keys = vec!(
230-
"first",
231-
"alphanumeric",
232-
);
233-
234-
let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
235-
assert_eq!(expected_keys, keys);
236-
}
237-
}

tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
extern crate bson;
22
extern crate rustc_serialize;
33

4-
mod oid;
4+
mod modules;

tests/modules/encoder.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extern crate bson;
2+
3+
use bson::{Document, Bson, encode_document};
4+
5+
#[test]
6+
fn test_encode_floating_point() {
7+
let src = 1020.123;
8+
let dst = [18, 0, 0, 0, 1, 107, 101, 121, 0, 68, 139, 108, 231, 251, 224, 143, 64, 0];
9+
10+
let mut doc = Document::new();
11+
doc.insert("key".to_owned(), Bson::FloatingPoint(src));
12+
13+
let mut buf = Vec::new();
14+
encode_document(&mut buf, &doc).unwrap();
15+
16+
assert_eq!(&buf, &dst);
17+
}
18+
19+
#[test]
20+
fn test_encode_utf8_string() {
21+
let src = "test你好吗".to_owned();
22+
let dst = [28, 0, 0, 0, 2, 107, 101, 121, 0, 14, 0, 0, 0, 116, 101, 115, 116, 228, 189, 160, 229, 165, 189, 229, 144, 151, 0, 0];
23+
24+
let mut doc = Document::new();
25+
doc.insert("key".to_owned(), Bson::String(src));
26+
27+
let mut buf = Vec::new();
28+
encode_document(&mut buf, &doc).unwrap();
29+
30+
assert_eq!(&buf, &dst);
31+
}
32+
33+
#[test]
34+
fn test_encode_array() {
35+
let src = vec![Bson::FloatingPoint(1.01), Bson::String("xyz".to_owned())];
36+
let dst = [37, 0, 0, 0, 4, 107, 101, 121, 0, 27, 0, 0, 0, 1, 48, 0, 41, 92, 143, 194, 245, 40, 240, 63, 2, 49, 0, 4, 0, 0, 0, 120, 121, 122, 0, 0, 0];
37+
38+
let mut doc = Document::new();
39+
doc.insert("key".to_owned(), Bson::Array(src));
40+
41+
let mut buf = Vec::new();
42+
encode_document(&mut buf, &doc).unwrap();
43+
44+
assert_eq!(&buf[..], &dst[..]);
45+
}

tests/modules/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod encoder;
2+
mod oid;
3+
mod ordered;

tests/oid.rs renamed to tests/modules/oid.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
extern crate bson;
2-
extern crate rustc_serialize;
3-
41
use bson::oid::ObjectId;
52
use rustc_serialize::hex::ToHex;
63

tests/modules/ordered.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use bson::{Bson, Document};
2+
3+
#[test]
4+
fn ordered_insert() {
5+
let mut doc = Document::new();
6+
doc.insert("first".to_owned(), Bson::I32(1));
7+
doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
8+
doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
9+
10+
let expected_keys = vec!(
11+
"first".to_owned(),
12+
"second".to_owned(),
13+
"alphanumeric".to_owned(),
14+
);
15+
16+
let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
17+
assert_eq!(expected_keys, keys);
18+
}
19+
20+
#[test]
21+
fn remove() {
22+
let mut doc = Document::new();
23+
doc.insert("first".to_owned(), Bson::I32(1));
24+
doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
25+
doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
26+
27+
assert!(doc.remove("second").is_some());
28+
assert!(doc.remove("none").is_none());
29+
30+
let expected_keys = vec!(
31+
"first",
32+
"alphanumeric",
33+
);
34+
35+
let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
36+
assert_eq!(expected_keys, keys);
37+
}

0 commit comments

Comments
 (0)