Initial Dever 0.0.1
This commit is contained in:
commit
81233d098c
1479 files changed
+163782
No files matched your search
@@ -0,0 +1,42 @@
|
||||
use super::{ERROR, packages};
|
||||
|
||||
#[test]
|
||||
fn scalar_columns_keep_distinct_precision_and_query_bindings() {
|
||||
let program = packages(&[
|
||||
("dever.database", ERROR),
|
||||
("demo.account.model", "type Account { amount: Decimal(34, 4)\nfee: Decimal(5, 2)?\nuid: Uuid unique\nday: Date\ntime: Time\nelapsed: Duration\ndocument: Json }"),
|
||||
("demo.account.app", "search(amount: Decimal, fee: Decimal?) (page: model.Page) { page = model.list({ where = amount >= amount and fee == fee, order = [amount.asc] }) }"),
|
||||
("demo.account.api", "cmd search = app.search"),
|
||||
]).unwrap();
|
||||
assert_eq!(program.models[0].columns[2].decimal, Some((34, 4)));
|
||||
assert_eq!(program.models[0].columns[3].decimal, Some((5, 2)));
|
||||
assert_eq!(program.models[0].columns[2].limits, None);
|
||||
assert!(program.models[0].columns[4].unique);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_metadata_rejects_lossy_or_ambiguous_decimal_storage() {
|
||||
for kind in [
|
||||
"Decimal",
|
||||
"Decimal(5)",
|
||||
"Decimal(0, 0)",
|
||||
"Decimal(35, 4)",
|
||||
"Decimal(4, 5)",
|
||||
"Decimal(4, 2, 1)",
|
||||
] {
|
||||
let model = format!("type Account {{ amount: {kind} }}");
|
||||
let error = packages(&[("demo.account.model", &model)]).unwrap_err();
|
||||
assert_eq!(error.code, "C014", "{kind}: {error:?}");
|
||||
}
|
||||
for kind in ["Decimal(1, 0)", "Decimal(34, 34)", "Decimal(9, 2)?"] {
|
||||
let model = format!("type Account {{ amount: {kind} }}");
|
||||
packages(&[("demo.account.model", &model)]).unwrap();
|
||||
}
|
||||
for kind in ["List<Int>", "Id", "Secret"] {
|
||||
let model = format!("type Account {{ value: {kind} }}");
|
||||
assert!(
|
||||
packages(&[("demo.account.model", &model)]).is_err(),
|
||||
"{kind}"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user