mentat/tests/external_test.rs

59 lines
1.8 KiB
Rust
Raw Permalink Normal View History

// Copyright 2016 Mozilla
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
2017-01-07 01:19:36 +00:00
extern crate mentat;
#[test]
fn can_import_sqlite() {
// From https://github.com/jgallagher/rusqlite#rusqlite.
#[derive(Debug)]
struct Person {
id: i32,
name: String,
2017-01-10 18:54:37 +00:00
data: Option<Vec<u8>>,
}
2017-01-07 01:19:36 +00:00
let conn = mentat::get_connection();
conn.execute("CREATE TABLE person (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
data BLOB
2017-01-10 18:54:37 +00:00
)",
&[])
.unwrap();
let me = Person {
id: 1,
name: "Steven".to_string(),
2017-01-10 18:54:37 +00:00
data: None,
};
conn.execute("INSERT INTO person (name, data)
VALUES (?1, ?2)",
2017-01-10 18:54:37 +00:00
&[&me.name, &me.data])
.unwrap();
let mut stmt = conn.prepare("SELECT id, name, data FROM person").unwrap();
let person_iter = stmt.query_map(&[], |row| {
2017-01-10 18:54:37 +00:00
Person {
id: row.get(0),
name: row.get(1),
data: row.get(2),
}
})
.unwrap();
for person in person_iter {
let p = person.unwrap();
assert_eq!(me.id, p.id);
assert_eq!(me.data, p.data);
assert_eq!(me.data, p.data);
}
}