Skip to content

Commit

Permalink
Added QualifiedIdentifier kinds(#1078)
Browse files Browse the repository at this point in the history
Fixes #1055
  • Loading branch information
michaelvanstraten authored Jan 7, 2024
1 parent 33f6f26 commit 56f182a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ impl Getter for CppCode {
| Cpp::FieldIdentifier
| Cpp::DestructorName
| Cpp::OperatorName
| Cpp::QualifiedIdentifier
| Cpp::QualifiedIdentifier2
| Cpp::QualifiedIdentifier3
| Cpp::QualifiedIdentifier4
| Cpp::TemplateFunction
| Cpp::TemplateMethod => {
let code = &code[first.start_byte()..first.end_byte()];
Expand Down
21 changes: 21 additions & 0 deletions src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,24 @@ impl Callback for Metrics {
}
}
}

#[cfg(test)]
mod tests {
use crate::{check_func_space, CppParser};

#[test]
fn c_scope_resolution_operator() {
check_func_space::<CppParser, _>(
"void Foo::bar(){
return;
}",
"foo.c",
|func_space| {
insta::assert_json_snapshot!(
func_space.spaces[0].name,
@r###""Foo::bar""###
);
},
);
}
}
15 changes: 12 additions & 3 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,27 @@ pub(crate) fn intense_color(stdout: &mut StandardStreamLock, color: Color) -> st
}

#[cfg(test)]
pub(crate) fn check_metrics<T: crate::ParserTrait>(
pub(crate) fn check_func_space<T: crate::ParserTrait, F: Fn(crate::FuncSpace)>(
source: &str,
filename: &str,
check: fn(crate::CodeMetrics) -> (),
check: F,
) {
let path = std::path::PathBuf::from(filename);
let mut trimmed_bytes = source.trim_end().trim_matches('\n').as_bytes().to_vec();
trimmed_bytes.push(b'\n');
let parser = T::new(trimmed_bytes, &path, None);
let func_space = crate::metrics(&parser, &path).unwrap();

check(func_space.metrics)
check(func_space)
}

#[cfg(test)]
pub(crate) fn check_metrics<T: crate::ParserTrait>(
source: &str,
filename: &str,
check: fn(crate::CodeMetrics) -> (),
) {
check_func_space::<T, _>(source, filename, |func_space| check(func_space.metrics))
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion tests/repositories/rca-output
Submodule rca-output updated 1603 files

0 comments on commit 56f182a

Please sign in to comment.