forked from mirrors/jj
templater: update test templater to be compatible with "self" methods
Prepares for the removal of build_keyword().
This commit is contained in:
parent
e9b420f592
commit
6e5eff5423
1 changed files with 52 additions and 4 deletions
|
@ -956,9 +956,9 @@ mod tests {
|
||||||
|
|
||||||
impl TemplateLanguage<'static> for TestTemplateLanguage {
|
impl TemplateLanguage<'static> for TestTemplateLanguage {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
type Property = CoreTemplatePropertyKind<'static, ()>;
|
type Property = TestTemplatePropertyKind;
|
||||||
|
|
||||||
impl_core_wrap_property_fns!('static);
|
impl_core_wrap_property_fns!('static, TestTemplatePropertyKind::Core);
|
||||||
|
|
||||||
fn build_keyword(
|
fn build_keyword(
|
||||||
&self,
|
&self,
|
||||||
|
@ -977,11 +977,59 @@ mod tests {
|
||||||
property: Self::Property,
|
property: Self::Property,
|
||||||
function: &FunctionCallNode,
|
function: &FunctionCallNode,
|
||||||
) -> TemplateParseResult<Self::Property> {
|
) -> TemplateParseResult<Self::Property> {
|
||||||
build_core_method(self, build_ctx, property, function)
|
match property {
|
||||||
|
TestTemplatePropertyKind::Core(property) => {
|
||||||
|
build_core_method(self, build_ctx, property, function)
|
||||||
|
}
|
||||||
|
TestTemplatePropertyKind::Unit => {
|
||||||
|
let build = self
|
||||||
|
.keywords
|
||||||
|
.get(function.name)
|
||||||
|
.ok_or_else(|| TemplateParseError::no_such_method("()", function))?;
|
||||||
|
template_parser::expect_no_arguments(function)?;
|
||||||
|
Ok(build(self))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestTemplateKeywordFn = fn(&TestTemplateLanguage) -> CoreTemplatePropertyKind<'static, ()>;
|
enum TestTemplatePropertyKind {
|
||||||
|
Core(CoreTemplatePropertyKind<'static, ()>),
|
||||||
|
#[allow(unused)] // TODO
|
||||||
|
Unit,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoTemplateProperty<'static, ()> for TestTemplatePropertyKind {
|
||||||
|
fn try_into_boolean(self) -> Option<Box<dyn TemplateProperty<(), Output = bool>>> {
|
||||||
|
match self {
|
||||||
|
TestTemplatePropertyKind::Core(property) => property.try_into_boolean(),
|
||||||
|
TestTemplatePropertyKind::Unit => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_integer(self) -> Option<Box<dyn TemplateProperty<(), Output = i64>>> {
|
||||||
|
match self {
|
||||||
|
TestTemplatePropertyKind::Core(property) => property.try_into_integer(),
|
||||||
|
TestTemplatePropertyKind::Unit => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_plain_text(self) -> Option<Box<dyn TemplateProperty<(), Output = String>>> {
|
||||||
|
match self {
|
||||||
|
TestTemplatePropertyKind::Core(property) => property.try_into_plain_text(),
|
||||||
|
TestTemplatePropertyKind::Unit => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_template(self) -> Option<Box<dyn Template<()>>> {
|
||||||
|
match self {
|
||||||
|
TestTemplatePropertyKind::Core(property) => property.try_into_template(),
|
||||||
|
TestTemplatePropertyKind::Unit => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestTemplateKeywordFn = fn(&TestTemplateLanguage) -> TestTemplatePropertyKind;
|
||||||
|
|
||||||
/// Helper to set up template evaluation environment.
|
/// Helper to set up template evaluation environment.
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
|
Loading…
Reference in a new issue