Fix Display of Value::LastError with lambda

There was a small typo in the `fn display_last_error`.

Closes #263
This commit is contained in:
Ivan Boldyrev 2022-05-16 20:08:37 +07:00
parent dcfa51c756
commit ec3d3a4e6f
6 changed files with 51 additions and 1 deletions

1
Cargo.lock generated
View File

@ -127,6 +127,7 @@ dependencies = [
"lalrpop",
"lalrpop-util",
"multimap",
"non-empty-vec",
"regex",
"serde",
"serde_json",

View File

@ -33,6 +33,7 @@ thiserror = "1.0.23"
[dev-dependencies]
fstrings = "0.2.3"
criterion = "0.3.3"
non-empty-vec = { version = "0.2.0" }
[[bench]]
name = "parser"

View File

@ -152,7 +152,7 @@ fn display_last_error(
last_error_accessor: &Option<LambdaAST>,
) -> fmt::Result {
match last_error_accessor {
Some(accessor) => write!(f, "%last_error%.$.{}", air_lambda_ast::format_ast(accessor)),
Some(accessor) => write!(f, "%last_error%.${}", air_lambda_ast::format_ast(accessor)),
None => write!(f, "%last_error%"),
}
}

View File

@ -18,6 +18,9 @@ mod instruction_arguments;
mod instructions;
mod values;
#[cfg(test)]
pub mod tests;
pub use instruction_arguments::*;
pub use instructions::*;
pub use values::*;

View File

@ -0,0 +1,28 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::ast::Value;
use air_lambda_ast::ValueAccessor;
use non_empty_vec::NonEmpty;
#[test]
// https://github.com/fluencelabs/aquavm/issues/263
fn issue_263() {
let val = Value::LastError(Some(NonEmpty::new(ValueAccessor::FieldAccessByName {
field_name: "message",
})));
assert_eq!(val.to_string(), "%last_error%.$.message");
}

View File

@ -0,0 +1,17 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub mod instruction_arguments;