mod canonical {
nichlink_run_method::__nichlink_object! {
kind: Ordered,
name: { zh: "有序", en: "Ordered" },
needs_registry: true,
parent: nichlink_run_method::registry_core::root_node_id("face-fields-test"),
registry_rule: nichlink_run_method::registry_core::RegistrationRule::ANY,
}
}
mod shuffled {
nichlink_run_method::__nichlink_object! {
registry_rule: nichlink_run_method::registry_core::RegistrationRule::ANY;
kind: Ordered;
parent: nichlink_run_method::registry_core::root_node_id("face-fields-test");
needs_registry: true;
name: { zh: "有序", en: "Ordered" };
}
}
#[test]
fn any_order_and_separator_declares_the_same_face() {
assert_eq!(canonical::NODE_ID, shuffled::NODE_ID);
assert_eq!(
canonical::REGISTRATION.needs_registry,
shuffled::REGISTRATION.needs_registry
);
assert_eq!(
canonical::REGISTRATION.parent,
shuffled::REGISTRATION.parent
);
assert_eq!(canonical::REGISTRATION.registry_name, "canonical");
assert_eq!(shuffled::REGISTRATION.registry_name, "shuffled");
assert_eq!(
canonical::REGISTRATION.name.zh,
shuffled::REGISTRATION.name.zh
);
assert_eq!(
canonical::REGISTRATION.registry_rule_path,
shuffled::REGISTRATION.registry_rule_path
);
}
#[test]
fn a_reordered_face_reports_the_authors_lines() {
assert_eq!(
canonical::REGISTRATION.source.file,
shuffled::REGISTRATION.source.file
);
let lines = [
canonical::REGISTRATION.source.line,
shuffled::REGISTRATION.source.line,
];
assert_ne!(
lines[0], lines[1],
"each declaration reports its own line: {lines:?}"
);
assert!(lines.iter().all(|line| *line > 0), "lines: {lines:?}");
assert_eq!(canonical::REGISTRATION.source.column, 5);
assert_eq!(shuffled::REGISTRATION.source.column, 5);
}
mod parens {
nichlink_run_method::__nichlink_object!(
kind: Ordered;
registry_rule: nichlink_run_method::registry_core::RegistrationRule::ANY;
needs_registry: true;
name: { zh: "有序", en: "Ordered" };
parent: nichlink_run_method::registry_core::root_node_id("face-fields-test")
);
}
#[test]
fn the_parenthesised_form_declares_the_same_face() {
assert_eq!(canonical::NODE_ID, parens::NODE_ID);
assert_eq!(canonical::REGISTRATION.kind, parens::REGISTRATION.kind);
assert_eq!(
canonical::REGISTRATION.needs_registry,
parens::REGISTRATION.needs_registry
);
assert_eq!(canonical::REGISTRATION.registry_name, "canonical");
assert_eq!(parens::REGISTRATION.registry_name, "parens");
assert_eq!(
canonical::REGISTRATION.name.en,
parens::REGISTRATION.name.en
);
assert_eq!(canonical::REGISTRATION.parent, parens::REGISTRATION.parent);
let columns = [
canonical::REGISTRATION.source.column,
parens::REGISTRATION.source.column,
];
assert_eq!(columns, [5, 5]);
let lines = [
canonical::REGISTRATION.source.line,
parens::REGISTRATION.source.line,
];
assert!(lines.iter().all(|line| *line > 0), "lines: {lines:?}");
}
mod registry_rule {
use nichlink_run_method::registry_core::RegistrationRule;
pub const REGISTRATION_RULE: RegistrationRule = RegistrationRule::new()
.require_exports(&["control.render"])
.require_handle_traits(&["ControlHandle"]);
}
mod omitted_rule {
nichlink_run_method::__nichlink_object! {
kind: RuleOmitted,
name: { zh: "省略规则", en: "Rule omitted" },
needs_registry: true,
parent: nichlink_run_method::registry_core::root_node_id("face-fields-test"),
}
}
mod leaf_no_rule {
nichlink_run_method::__nichlink_object! {
kind: LeafNoRule,
}
}
#[test]
fn an_omitted_rule_resolves_to_the_canonical_sibling() {
let derived = omitted_rule::REGISTRATION.registry_rule;
let canonical = registry_rule::REGISTRATION_RULE;
assert_eq!(derived.required_exports, canonical.required_exports);
assert_eq!(
derived.required_handle_traits,
canonical.required_handle_traits
);
assert_eq!(derived.required_exports, ["control.render"]);
}
#[test]
fn a_face_without_a_registry_keeps_the_permissive_default() {
let rule = leaf_no_rule::REGISTRATION.registry_rule;
assert!(rule.required_exports.is_empty());
assert!(rule.required_handle_traits.is_empty());
assert_eq!(rule.required_preset, None);
}
mod external_shuffled {
use nichlink_run_method::registry_core::{
ContractId, FlowContract, NoParts, NoPreset, RegistrationRule, root_node_id,
};
#[allow(dead_code)]
pub struct ExternalFast;
nichlink_run_method::external_object! {
kind: ExternalFast;
flow: FlowContract::new(ContractId::new("t.v1"), 1, "In", "Out");
source: "face_fields/external_fast.rs";
parts: NoParts;
preset: NoPreset;
name: { zh: "外部", en: "External" };
summary: { zh: "外部实现", en: "External implementation" };
exports: ["t.out"];
needs_registry: false;
parent: root_node_id(env!("CARGO_PKG_NAME"));
getting_from_other_registry: None;
registry_rule_path: "face_fields/external_fast.rs";
registry_rule: RegistrationRule::ANY;
requires: [];
provides: [];
runtime_checks: [];
}
}
#[test]
fn an_external_face_accepts_semicolons_and_any_order() {
assert_eq!(external_shuffled::REGISTRATION.kind, "ExternalFast");
assert_eq!(external_shuffled::REGISTRATION.name.en, "External");
let registered = [external_shuffled::REGISTRATION.needs_registry];
assert_eq!(registered, [false]);
assert_eq!(
external_shuffled::REGISTRATION.source.file,
"face_fields/external_fast.rs"
);
}