chore(code-graph): reorganize fixtures, add TS/JS/Rust foundation tests · gitlabhq/orbit-knowledge-graph@2b6d65a · GitHub
Skip to content

Commit 2b6d65a

Browse files
Michael UsachenkoGitLab
authored andcommitted
chore(code-graph): reorganize fixtures, add TS/JS/Rust foundation tests
1 parent 50a9561 commit 2b6d65a

34 files changed

Lines changed: 1517 additions & 495 deletions

‎crates/integration-tests-codegraph/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
fn main() {
2+
let root = format!("{}/fixtures", std::env::var("CARGO_MANIFEST_DIR").unwrap());
3+
let mut tests = Vec::new();
4+
find_yaml(&root, &root, &mut tests);
5+
tests.sort();
6+
7+
// Detect duplicate test names (e.g. foo/bar-baz.yaml and foo/bar_baz.yaml)
8+
for pair in tests.windows(2) {
9+
if pair[0].0 == pair[1].0 {
10+
panic!(
11+
"duplicate test name '{}' from:\n {}\n {}",
12+
pair[0].0, pair[0].1, pair[1].1
13+
);
14+
}
15+
}
16+
17+
let code: String = tests
18+
.iter()
19+
.map(|(name, path)| {
20+
format!("#[tokio::test]\nasync fn {name}() {{ run_yaml_suite(include_str!(\"{path}\")).await; }}\n")
21+
})
22+
.collect();
23+
24+
std::fs::write(
25+
format!("{}/generated_suites.rs", std::env::var("OUT_DIR").unwrap()),
26+
code,
27+
)
28+
.unwrap();
29+
println!("cargo::rerun-if-changed=fixtures");
30+
}
31+
32+
fn find_yaml(root: &str, dir: &str, out: &mut Vec<(String, String)>) {
33+
for entry in std::fs::read_dir(dir).unwrap().flatten() {
34+
let path = entry.path();
35+
if path.is_dir() {
36+
find_yaml(root, path.to_str().unwrap(), out);
37+
} else if path.extension().is_some_and(|e| e == "yaml") {
38+
let abs = path.to_str().unwrap().replace('\\', "/");
39+
let name = abs[root.len() + 1..]
40+
.replace(['/', '.', '-'], "_")
41+
.trim_end_matches("_yaml")
42+
.to_string();
43+
out.push((name, abs));
44+
}
45+
}
46+
}

crates/integration-tests-codegraph/fixtures/containment.yaml renamed to crates/integration-tests-codegraph/fixtures/cross_language/containment.yaml

File renamed without changes.

crates/integration-tests-codegraph/fixtures/range_contract.yaml renamed to crates/integration-tests-codegraph/fixtures/cross_language/range_contract.yaml

File renamed without changes.

crates/integration-tests-codegraph/fixtures/structural.yaml renamed to crates/integration-tests-codegraph/fixtures/cross_language/structural.yaml

File renamed without changes.

crates/integration-tests-codegraph/fixtures/java_resolution.yaml renamed to crates/integration-tests-codegraph/fixtures/java/java_resolution.yaml

File renamed without changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "JavaScript: simple function call"
2+
pipeline: js
3+
fixtures:
4+
- path: main.js
5+
content: |
6+
function helper() {
7+
return "help";
8+
}
9+
10+
function unused() {}
11+
12+
function run() {
13+
helper();
14+
}
15+
16+
tests:
17+
- name: Exactly 3 definitions
18+
query: |
19+
MATCH (d:Definition)
20+
WHERE d.file_path = 'main.js' AND d.definition_type = 'Function'
21+
RETURN d.name AS name, d.fqn AS fqn
22+
ORDER BY name
23+
assert:
24+
- { row_count: 3 }
25+
- { unique: fqn }
26+
- { no_nulls: fqn }
27+
- { column_values: { field: name, values: ["helper", "run", "unused"] } }
28+
29+
- name: run calls helper (exactly 1 call edge)
30+
query: |
31+
MATCH (caller:Definition)-[e:DefinitionToDefinition]->(callee:Definition)
32+
WHERE e.edge_kind = 'Calls'
33+
RETURN caller.fqn AS caller, callee.fqn AS callee
34+
assert:
35+
- { row_count: 1 }
36+
- { row: { caller: "run", callee: "helper" } }
37+
38+
- name: unused has no incoming calls
39+
query: |
40+
MATCH (caller:Definition)-[e:DefinitionToDefinition]->(callee:Definition)
41+
WHERE callee.name = 'unused' AND e.edge_kind = 'Calls'
42+
RETURN caller.fqn AS caller
43+
assert:
44+
- { empty: true }
45+
46+
- name: Exactly 1 JavaScript file
47+
query: |
48+
MATCH (f:File)
49+
RETURN f.path AS path, f.language AS lang
50+
assert:
51+
- { row_count: 1 }
52+
- { row: { path: "main.js", lang: "javascript" } }
Lines changed: 80 additions & 0 deletions

crates/integration-tests-codegraph/fixtures/kotlin_resolution.yaml renamed to crates/integration-tests-codegraph/fixtures/kotlin/kotlin_resolution.yaml

File renamed without changes.

crates/integration-tests-codegraph/fixtures/python_resolution.yaml renamed to crates/integration-tests-codegraph/fixtures/python/python_resolution.yaml

File renamed without changes.

0 commit comments

Comments
 (0)