Skip to content

Commit c84529d

Browse files
committed
Redo tests
1 parent 54aa3a3 commit c84529d

File tree

121 files changed

+2798
-2344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2798
-2344
lines changed

Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,35 @@
7676
[dev-dependencies]
7777
tokio = { version = "0.3.3", features = ["macros", "rt"] }
7878
criterion = {version = "0.3.5", features = ["html_reports"] }
79+
# Testing
80+
inventory = "0.2.3"
81+
indicatif = "0.16.2"
7982

8083
[[bench]]
8184
name = "bench"
8285
harness = false
86+
87+
[[test]]
88+
name = "query"
89+
path = "tests/query_main.rs"
90+
harness = false
91+
92+
[[test]]
93+
name = "misc"
94+
path = "tests/misc_main.rs"
95+
harness = false
96+
97+
[[test]]
98+
name = "api"
99+
path = "tests/api_main.rs"
100+
harness = false
101+
102+
[[test]]
103+
name = "functionality"
104+
path = "tests/functionality_main.rs"
105+
harness = false
106+
107+
[[test]]
108+
name = "databases"
109+
path = "tests/databases_main.rs"
110+
harness = false

src/databases/sheet/mutable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl DBMut for SheetDatabase {
109109
let sheet = self.get_sheet_mut(sheet_name)?;
110110
rows.into_iter().try_for_each::<_, Result<()>>(|key| {
111111
let row_num: u64 = key.cast()?;
112-
sheet.remove_row(&(row_num as u32), &1);
112+
sheet.remove_row(&((row_num as u32) + 1), &1);
113113
Ok(())
114114
})?;
115115
self.save()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use crate::util::*;
2+
testcase!(test);
3+
fn test(mut glue: multisql::Glue) {
4+
assert_success!(
5+
glue,
6+
"
7+
CREATE TABLE main.simple (
8+
id INTEGER,
9+
val FLOAT
10+
)
11+
"
12+
);
13+
14+
assert_error!(
15+
glue,
16+
"
17+
CREATE TABLE other.simple (
18+
id INTEGER,
19+
val FLOAT
20+
)
21+
"
22+
);
23+
24+
#[allow(unused_must_use)]
25+
{
26+
// Delete file if still exists from previous test
27+
std::fs::remove_dir_all("data/create_test_other_database/");
28+
}
29+
30+
assert_success!(
31+
glue,
32+
"
33+
CREATE DATABASE other LOCATION 'data/create_test_other_database/'
34+
"
35+
);
36+
assert_error!(
37+
glue,
38+
"
39+
CREATE DATABASE other LOCATION 'data/create_test_other_database/'
40+
"
41+
);
42+
assert_success!(
43+
glue,
44+
"
45+
CREATE DATABASE IF NOT EXISTS other LOCATION 'data/create_test_other_database/'
46+
"
47+
);
48+
49+
assert_success!(
50+
glue,
51+
"
52+
CREATE TABLE other.simple (
53+
id INTEGER,
54+
val FLOAT
55+
)
56+
"
57+
);
58+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod create_database;

tests/ability/alter/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod database;
2+
mod table;
3+
mod view;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use crate::util::*;
2+
testcase!(test);
3+
fn test(mut glue: multisql::Glue) {
4+
assert_success!(
5+
glue,
6+
"CREATE TABLE Foo (id INTEGER);",
7+
multisql::Payload::Create
8+
);
9+
assert_success!(
10+
glue,
11+
"INSERT INTO Foo VALUES (1), (2), (3);",
12+
multisql::Payload::Insert(3)
13+
);
14+
assert_select!(glue, "SELECT id FROM Foo" => id = I64: (1),(2),(3));
15+
16+
assert_error!(glue, "ALTER TABLE Foo2 RENAME TO Bar;"); //, multisql::AlterTableError::TableNotFound("Foo2".to_owned()));
17+
assert_success!(
18+
glue,
19+
"ALTER TABLE Foo RENAME TO Bar;",
20+
multisql::Payload::AlterTable
21+
);
22+
assert_select!(glue, "SELECT id FROM Bar" => id = I64: (1),(2),(3));
23+
24+
assert_success!(
25+
glue,
26+
"ALTER TABLE Bar RENAME COLUMN id TO new_id",
27+
multisql::Payload::AlterTable
28+
);
29+
assert_select!(glue, "SELECT new_id FROM Bar" => new_id = I64: (1),(2),(3));
30+
31+
assert_error!(glue, "ALTER TABLE Bar RENAME COLUMN hello TO idid"); //, multisql::AlterTableError::RenamingColumnNotFound);
32+
assert_success!(
33+
glue,
34+
"CREATE TABLE Foo (id INTEGER);",
35+
multisql::Payload::Create
36+
);
37+
assert_success!(
38+
glue,
39+
"INSERT INTO Foo VALUES (1), (2);",
40+
multisql::Payload::Insert(2)
41+
);
42+
assert_select!(glue, "SELECT * FROM Foo" => id = I64: (1),(2));
43+
44+
assert_error!(glue, "ALTER TABLE Foo ADD COLUMN amount INTEGER"); //, multisql::AlterTableError::DefaultValueRequired("amount INT".to_owned()));
45+
assert_error!(glue, "ALTER TABLE Foo ADD COLUMN id INTEGER"); //, multisql::AlterTableError::AddingColumnAlreadyExists("id".to_owned()));
46+
47+
/* TODO: #72
48+
assert_success!(glue, "ALTER TABLE Foo ADD COLUMN amount INTEGER DEFAULT 10", multisql::Payload::AlterTable);
49+
assert_select!(glue, "SELECT * FROM Foo" => id = I64, amount = I64: (1, 10),(2, 10));
50+
assert_success!(glue, "ALTER TABLE Foo ADD COLUMN opt BOOLEAN NULL", multisql::Payload::AlterTable);
51+
// TODO: Null test assert_success!(glue, "SELECT * FROM Foo;", select_with_null! pt; I64(1) I64(10) Null I64(2) I64(10) Nu;
52+
assert_success!(glue, "ALTER TABLE Foo ADD COLUMN opt2 BOOLEAN NULL DEFAULT true", multisql::Payload::AlterTable);
53+
// TODO: Null test assert_success!(glue, "SELECT * FROM Foo;", select_with_null! pt | opt2; I64(1) I64(10) Null Bool(true) I64(2) I64(10) Null Bool(tru;
54+
assert_error!(glue, "ALTER TABLE Foo ADD COLUMN something INTEGER DEFAULT (SELECT id FROM Bar LIMIT 1)", multisql::WIPError::TODO);
55+
*/
56+
57+
assert_error!(glue, "ALTER TABLE Foo ADD COLUMN something SOMEWHAT"); //, multisql::AlterError::UnsupportedDataType("SOMEWHAT".to_owned()));
58+
assert_error!(
59+
glue,
60+
"ALTER TABLE Foo ADD COLUMN something INTEGER CHECK (true)"
61+
); //, multisql::AlterError::UnsupportedColumnOption("CHECK (true)".to_owned()));
62+
63+
assert_success!(
64+
glue,
65+
"ALTER TABLE Foo ADD COLUMN something FLOAT UNIQUE",
66+
multisql::Payload::AlterTable
67+
);
68+
assert_success!(
69+
glue,
70+
"ALTER TABLE Foo DROP COLUMN IF EXISTS something;",
71+
multisql::Payload::AlterTable
72+
);
73+
assert_error!(glue, "ALTER TABLE Foo DROP COLUMN something;"); //, multisql::AlterTableError::DroppingColumnNotFound("something".to_owned()));
74+
assert_success!(
75+
glue,
76+
"ALTER TABLE Foo DROP COLUMN amount;",
77+
multisql::Payload::AlterTable
78+
);
79+
// TODO: Null test assert_success!(glue, "SELECT * FROM Foo;", select_with_null! ; I64(1) Null Bool(true) I64(2) Null Bool(tru;
80+
assert_success!(
81+
glue,
82+
"ALTER TABLE Foo DROP COLUMN IF EXISTS opt2;",
83+
multisql::Payload::AlterTable
84+
);
85+
// TODO: Null test assert_success!(glue, "SELECT * FROM Foo;", select_with_null! id | opt;I64(1) Null; I64(2) Nu;
86+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use crate::util::*;
2+
testcase!(test);
3+
fn test(mut glue: multisql::Glue) {
4+
glue.execute(
5+
r#"
6+
CREATE TABLE basic (
7+
a INTEGER
8+
)
9+
"#,
10+
)
11+
.expect("CREATE TABLE basic");
12+
13+
assert_success!(
14+
glue,
15+
"
16+
CREATE TABLE CreateTable1 (
17+
id INTEGER NULL,
18+
num INTEGER,
19+
name TEXT
20+
)"
21+
);
22+
assert_error!(
23+
glue,
24+
"
25+
CREATE TABLE CreateTable1 (
26+
id INTEGER NULL,
27+
num INTEGER,
28+
name TEXT
29+
)",
30+
multisql::AlterError::TableAlreadyExists("CreateTable1".to_owned())
31+
);
32+
assert_success!(
33+
glue,
34+
"
35+
CREATE TABLE IF NOT EXISTS CreateTable2 (
36+
id INTEGER NULL,
37+
num INTEGER,
38+
name TEXT
39+
)"
40+
);
41+
assert_success!(
42+
glue,
43+
"CREATE TABLE IF NOT EXISTS CreateTable2 (
44+
id2 INTEGER NULL,
45+
)"
46+
);
47+
assert_success!(glue, "INSERT INTO CreateTable2 VALUES (NULL, 1, '1');");
48+
assert_error!(
49+
glue,
50+
"CREATE TABLE Gluery (id SOMEWHAT);",
51+
multisql::AlterError::UnsupportedDataType("SOMEWHAT".to_owned())
52+
);
53+
assert_error!(
54+
glue,
55+
"CREATE TABLE Gluery (id INTEGER CHECK (true));",
56+
multisql::AlterError::UnsupportedColumnOption("CHECK (true)".to_owned())
57+
);
58+
assert_error!(
59+
glue,
60+
"
61+
CREATE TABLE CreateTable3 (
62+
id INTEGER,
63+
ratio FLOAT UNIQUE
64+
)",
65+
multisql::AlterError::UnsupportedDataTypeForUniqueColumn(
66+
"ratio".to_owned(),
67+
"FLOAT".to_owned(),
68+
)
69+
);
70+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use crate::util::*;
2+
testcase!(test);
3+
fn test(mut glue: multisql::Glue) {
4+
assert_success!(
5+
glue,
6+
"
7+
CREATE TABLE DropTable (
8+
id INT,
9+
num INT,
10+
name TEXT
11+
)
12+
"
13+
);
14+
15+
assert_success!(
16+
glue,
17+
"INSERT INTO DropTable (id, num, name) VALUES (1, 2, 'Hello')"
18+
);
19+
20+
assert_select_count!(glue, "SELECT id, num, name FROM DropTable;", 1);
21+
assert_success!(glue, "DROP TABLE DropTable;");
22+
assert_error!(
23+
glue,
24+
"DROP TABLE DropTable;",
25+
multisql::AlterError::TableNotFound("DropTable".to_owned())
26+
);
27+
assert_success!(
28+
glue,
29+
"
30+
CREATE TABLE DropTable (
31+
id INT,
32+
num INT,
33+
name TEXT
34+
)
35+
"
36+
);
37+
assert_success!(glue, "DROP TABLE IF EXISTS DropTable;");
38+
assert_success!(glue, "DROP TABLE IF EXISTS DropTable;");
39+
assert_error!(
40+
glue,
41+
"SELECT id, num, name FROM DropTable;",
42+
multisql::FetchError::TableNotFound("DropTable".to_owned())
43+
);
44+
assert_success!(
45+
glue,
46+
"
47+
CREATE TABLE DropTable (
48+
id INT,
49+
num INT,
50+
name TEXT
51+
)
52+
"
53+
);
54+
assert_select_count!(glue, "SELECT id, num, name FROM DropTable;", 0);
55+
assert_error!(
56+
glue,
57+
"DROP VIEW DropTable;",
58+
multisql::AlterError::DropTypeNotSupported("VIEW".to_owned())
59+
);
60+
}

tests/ability/alter/table/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod alter_table;
2+
mod create_table;
3+
mod drop_table;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::util::*;
2+
testcase!(test);
3+
fn test(mut glue: multisql::Glue) {
4+
make_basic_table!(glue);
5+
assert_success!(
6+
glue,
7+
r#"
8+
CREATE VIEW basic_view AS (
9+
SELECT a
10+
FROM basic
11+
)
12+
"#
13+
);
14+
15+
assert_select!(glue,
16+
"SELECT a FROM basic_view"
17+
=> a = I64: (1)
18+
);
19+
}

0 commit comments

Comments
 (0)