mod utils;
use crate::utils::ink_version_from_path;
use ink_analyzer::{Analysis, TextRange, TextSize};
use test_utils::{TestCaseParams, TestCaseResults};
#[test]
fn inlay_hints_works() {
for test_group in test_utils::fixtures::inlay_hints_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 range_pats = match test_case.params.unwrap() {
TestCaseParams::InlayHints(Some(it)) => Some((it.start_pat, it.end_pat)),
_ => None,
};
let range = range_pats.map(|(range_start_pat, range_end_pat)| {
TextRange::new(
TextSize::from(
test_utils::parse_offset_at(&test_code, range_start_pat).unwrap() as u32,
),
TextSize::from(
test_utils::parse_offset_at(&test_code, range_end_pat).unwrap() as u32,
),
)
});
let version = ink_version_from_path(test_group.source);
let results = Analysis::new(&test_code, version).inlay_hints(range);
let expected_results = match test_case.results {
TestCaseResults::InlayHints(it) => Some(it),
_ => None,
}
.unwrap();
assert_eq!(
results
.into_iter()
.map(|item| (item.label, item.position, item.range))
.collect::<Vec<(String, TextSize, TextRange)>>(),
expected_results
.iter()
.map(|result| (
result.text.to_owned(),
TextSize::from(
test_utils::parse_offset_at(&test_code, result.pos_pat).unwrap() as u32
),
TextRange::new(
TextSize::from(
test_utils::parse_offset_at(&test_code, result.range_start_pat)
.unwrap() as u32
),
TextSize::from(
test_utils::parse_offset_at(&test_code, result.range_end_pat)
.unwrap() as u32
),
)
))
.collect::<Vec<(String, TextSize, TextRange)>>(),
"source: {}",
test_group.source
);
}
}
}