55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use crate::database::{Binding, Kind, Sql, context::initialization_order};
|
|
|
|
fn binding(references: &'static [usize]) -> Binding {
|
|
Binding {
|
|
storage: crate::database::Storage::Global,
|
|
component: "demo",
|
|
database: None,
|
|
table: "unused",
|
|
schema: Sql::same(""),
|
|
plan: None,
|
|
references,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn postgres_dependencies_precede_children_without_changing_binding_indices() {
|
|
let bindings = [
|
|
binding(&[0, 1, 2, 2]),
|
|
binding(&[2]),
|
|
binding(&[]),
|
|
binding(&[]),
|
|
];
|
|
assert_eq!(
|
|
initialization_order(&bindings, &[true; 4]).unwrap(),
|
|
[2, 1, 0, 3]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn postgres_cycles_fail_before_initialization_but_self_references_are_valid() {
|
|
assert_eq!(
|
|
initialization_order(&[binding(&[1]), binding(&[0])], &[true, true])
|
|
.unwrap_err()
|
|
.kind,
|
|
Kind::Migration
|
|
);
|
|
assert_eq!(
|
|
initialization_order(&[binding(&[0])], &[true]).unwrap(),
|
|
[0]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn sqlite_keeps_source_order_and_accepts_forward_and_cyclic_references() {
|
|
assert_eq!(
|
|
initialization_order(&[binding(&[1]), binding(&[0])], &[false, false]).unwrap(),
|
|
[0, 1]
|
|
);
|
|
let bindings = [binding(&[2]), binding(&[3]), binding(&[]), binding(&[1])];
|
|
assert_eq!(
|
|
initialization_order(&bindings, &[true, false, true, false]).unwrap(),
|
|
[1, 2, 0, 3]
|
|
);
|
|
}
|