mod utils;
use crate::utils::ink_version_from_path;
use ink_analyzer::{Analysis, TextRange, TextSize};
use test_utils::{PartialMatchStr, TestCaseParams, TestCaseResults};
#[test]
fn actions_works() {
for test_group in test_utils::fixtures::actions_fixtures() {
let original_code = test_utils::read_source_code(test_group.source);
for test_case in test_group.test_cases {
let mut test_code = original_code.clone();
if let Some(modifications) = test_case.modifications {
test_utils::apply_test_modifications(&mut test_code, &modifications);
}
let offset_pat = match test_case.params.unwrap() {
TestCaseParams::Action(it) => Some(it),
_ => None,
}
.unwrap()
.pat;
let offset =
TextSize::from(test_utils::parse_offset_at(&test_code, offset_pat).unwrap() as u32);
let range = TextRange::new(offset, offset);
let version = ink_version_from_path(test_group.source);
let results = Analysis::new(&test_code, version).actions(range);
let expected_results = match test_case.results {
TestCaseResults::Action(it) => Some(it),
_ => None,
}
.unwrap();
assert_eq!(
results
.iter()
.map(|action| (
PartialMatchStr::from(action.label.as_str()),
action
.edits
.iter()
.map(|edit| (PartialMatchStr::from(edit.text.as_str()), edit.range))
.collect::<Vec<(PartialMatchStr, TextRange)>>()
))
.collect::<Vec<(PartialMatchStr, Vec<(PartialMatchStr, TextRange)>)>>(),
expected_results
.iter()
.map(|expected_action| (
PartialMatchStr::from(expected_action.label),
expected_action
.edits
.iter()
.map(|result| {
(
PartialMatchStr::from(result.text),
TextRange::new(
TextSize::from(
test_utils::parse_offset_at(
&test_code,
result.start_pat,
)
.unwrap()
as u32,
),
TextSize::from(
test_utils::parse_offset_at(&test_code, result.end_pat)
.unwrap()
as u32,
),
),
)
})
.collect::<Vec<(PartialMatchStr, TextRange)>>(),
))
.collect::<Vec<(PartialMatchStr, Vec<(PartialMatchStr, TextRange)>)>>(),
"source: {}",
test_group.source
);
}
}
}