<commit_before>use bson::Bson;
use json::arguments::Arguments;
use json::reader::SuiteContainer;
use json::eq;
use mongodb::client:: MongoClient;
use rustc_serialize::json::Json;

macro_rules! run_find_test {
    ( $c:expr, $f:expr, $o:expr, $t:expr ) => {
        {
            let mut cursor = $c.find($f, $o).unwrap();

            let array = match $t.result {
                Bson::Array(ref arr) => arr.clone(),
                _ => panic!("Invalid `result` of find test")
            };

            for bson in array {
                assert!(eq::bson_eq(&bson, &Bson::Document(cursor.next().unwrap())));
            }
        }
    };
}

macro_rules! run_suite {
    ( $f:expr, $c:expr ) => {
        {
            let json = Json::from_file($f).unwrap();
            let suite = json.get_suite().unwrap();
            let client =  MongoClient::new("localhost", 27017).unwrap();
            let db = client.db("test");
            let coll = db.collection($c);
            coll.drop().unwrap();
            coll.insert_many(suite.data, true, None).unwrap();

            for test in suite.tests {
                match test.operation {
                    Arguments::Find { filter, options } =>
                        run_find_test!(coll, filter, Some(options), test.outcome)
                };
            }
        }
    };
}

#[test]
fn find() {
    run_suite!("tests/json/data/find.json", "find");
}<commit_msg>added collection parsing for find tests<commit_after>use bson::Bson;
use json::arguments::Arguments;
use json::reader::SuiteContainer;
use json::eq;
use mongodb::client:: MongoClient;
use rustc_serialize::json::Json;

macro_rules! run_find_test {
    ( $db:expr, $c:expr, $f:expr, $o:expr, $t:expr ) => {
        {
            let mut cursor = $c.find($f, $o).unwrap();

            let array = match $t.result {
                Bson::Array(ref arr) => arr.clone(),
                _ => panic!("Invalid `result` of find test")
            };

            for bson in array {
                assert!(eq::bson_eq(&bson, &Bson::Document(cursor.next().unwrap())));
            }

            assert!(!cursor.has_next());

            let outcome_coll = match $t.collection {
                Some(ref coll) => coll.clone(),
                None => return
            };

            let coll = match outcome_coll.name {
                Some(ref str) => $db.collection(&str),
                None => $db.collection(&$c.name())
            };

            let mut cursor = coll.find(None, None).unwrap();

            for doc in outcome_coll.data.iter() {
                assert!(eq::bson_eq(&Bson::Document(doc.clone()),
                                    &Bson::Document(cursor.next().unwrap())));
            }

            assert!(!cursor.has_next());
         }
    };
}

macro_rules! run_suite {
    ( $f:expr, $c:expr ) => {
        {
            let json = Json::from_file($f).unwrap();
            let suite = json.get_suite().unwrap();
            let client =  MongoClient::new("localhost", 27017).unwrap();
            let db = client.db("test");
            let coll = db.collection($c);
            coll.drop().unwrap();
            coll.insert_many(suite.data, true, None).unwrap();

            for test in suite.tests {
                match test.operation {
                    Arguments::Find { filter, options } =>
                        run_find_test!(db, coll, filter, Some(options),
                                       test.outcome)
                };
            }
        }
    };
}

#[test]
fn find() {
    run_suite!("tests/json/data/find.json", "find");
}
{'fraction_non_alphanumeric': 0.15774882173551427, 'fraction_numerical': 0.0027723870252287217, 'mean_word_length': 1.702621722846442, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '101002', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1048, 'n_words': 206}