Skip to content

Commit ca39493

Browse files
unhappychoiceclaude
andcommitted
test: add Zig language integration tests
- Add test cases for function, struct, and mixed code extraction - Add snapshot tests for validation - Register Zig in test helper functions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2898a9a commit ca39493

7 files changed

+221
-0
lines changed

tests/integration/languages/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod rust;
1515
pub mod scala;
1616
pub mod swift;
1717
pub mod typescript;
18+
pub mod zig;
1819

1920
// Common typing core utilities
2021
pub mod typing_core_common;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
source: tests/integration/languages/extractor.rs
3+
expression: "serde_json::to_string_pretty(&snapshot_data).unwrap()"
4+
---
5+
{
6+
"chunks": [
7+
{
8+
"chunk_type": "File",
9+
"comment_ranges": [],
10+
"content": "\npub fn add(a: i32, b: i32) i32 {\n return a + b;\n}\n\nfn subtract(a: i32, b: i32) i32 {\n return a - b;\n}\n",
11+
"end_line": 8,
12+
"language": "zig",
13+
"name": "entire_file",
14+
"original_indentation": 0,
15+
"start_line": 1
16+
},
17+
{
18+
"chunk_type": "Function",
19+
"comment_ranges": [],
20+
"content": "pub fn add(a: i32, b: i32) i32 {\n return a + b;\n}",
21+
"end_line": 4,
22+
"language": "zig",
23+
"name": "function",
24+
"original_indentation": 0,
25+
"start_line": 2
26+
},
27+
{
28+
"chunk_type": "Function",
29+
"comment_ranges": [],
30+
"content": "fn subtract(a: i32, b: i32) i32 {\n return a - b;\n}",
31+
"end_line": 8,
32+
"language": "zig",
33+
"name": "function",
34+
"original_indentation": 0,
35+
"start_line": 6
36+
}
37+
],
38+
"source_code": "\npub fn add(a: i32, b: i32) i32 {\n return a + b;\n}\n\nfn subtract(a: i32, b: i32) i32 {\n return a - b;\n}\n",
39+
"test_name": "test_zig_function_extraction",
40+
"total_chunks": 3
41+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
source: tests/integration/languages/extractor.rs
3+
expression: "serde_json::to_string_pretty(&snapshot_data).unwrap()"
4+
---
5+
{
6+
"chunks": [
7+
{
8+
"chunk_type": "File",
9+
"comment_ranges": [],
10+
"content": "\nconst std = @import(\"std\");\n\npub const Vector = struct {\n x: f32,\n y: f32,\n\n pub fn init(x: f32, y: f32) Vector {\n return Vector{ .x = x, .y = y };\n }\n\n pub fn length(self: Vector) f32 {\n return @sqrt(self.x * self.x + self.y * self.y);\n }\n};\n\npub fn main() !void {\n const stdout = std.io.getStdOut().writer();\n try stdout.print(\"Hello, Zig!\\n\", .{});\n}\n",
11+
"end_line": 20,
12+
"language": "zig",
13+
"name": "entire_file",
14+
"original_indentation": 0,
15+
"start_line": 1
16+
},
17+
{
18+
"chunk_type": "CodeBlock",
19+
"comment_ranges": [],
20+
"content": "pub const Vector = struct {\n x: f32,\n y: f32,\n\n pub fn init(x: f32, y: f32) Vector {\n return Vector{ .x = x, .y = y };\n }\n\n pub fn length(self: Vector) f32 {\n return @sqrt(self.x * self.x + self.y * self.y);\n }\n};",
21+
"end_line": 15,
22+
"language": "zig",
23+
"name": "struct",
24+
"original_indentation": 0,
25+
"start_line": 4
26+
},
27+
{
28+
"chunk_type": "Function",
29+
"comment_ranges": [],
30+
"content": " pub fn init(x: f32, y: f32) Vector {\n return Vector{ .x = x, .y = y };\n }",
31+
"end_line": 10,
32+
"language": "zig",
33+
"name": "function",
34+
"original_indentation": 4,
35+
"start_line": 8
36+
},
37+
{
38+
"chunk_type": "Function",
39+
"comment_ranges": [],
40+
"content": " pub fn length(self: Vector) f32 {\n return @sqrt(self.x * self.x + self.y * self.y);\n }",
41+
"end_line": 14,
42+
"language": "zig",
43+
"name": "function",
44+
"original_indentation": 4,
45+
"start_line": 12
46+
},
47+
{
48+
"chunk_type": "Function",
49+
"comment_ranges": [],
50+
"content": "pub fn main() !void {\n const stdout = std.io.getStdOut().writer();\n try stdout.print(\"Hello, Zig!\\n\", .{});\n}",
51+
"end_line": 20,
52+
"language": "zig",
53+
"name": "function",
54+
"original_indentation": 0,
55+
"start_line": 17
56+
}
57+
],
58+
"source_code": "\nconst std = @import(\"std\");\n\npub const Vector = struct {\n x: f32,\n y: f32,\n\n pub fn init(x: f32, y: f32) Vector {\n return Vector{ .x = x, .y = y };\n }\n\n pub fn length(self: Vector) f32 {\n return @sqrt(self.x * self.x + self.y * self.y);\n }\n};\n\npub fn main() !void {\n const stdout = std.io.getStdOut().writer();\n try stdout.print(\"Hello, Zig!\\n\", .{});\n}\n",
59+
"test_name": "test_zig_mixed_extraction",
60+
"total_chunks": 5
61+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
source: tests/integration/languages/extractor.rs
3+
expression: "serde_json::to_string_pretty(&snapshot_data).unwrap()"
4+
---
5+
{
6+
"chunks": [
7+
{
8+
"chunk_type": "File",
9+
"comment_ranges": [],
10+
"content": "\nconst Point = struct {\n x: f32,\n y: f32,\n};\n\npub const Config = struct {\n debug: bool,\n verbose: bool,\n};\n",
11+
"end_line": 10,
12+
"language": "zig",
13+
"name": "entire_file",
14+
"original_indentation": 0,
15+
"start_line": 1
16+
},
17+
{
18+
"chunk_type": "CodeBlock",
19+
"comment_ranges": [],
20+
"content": "const Point = struct {\n x: f32,\n y: f32,\n};",
21+
"end_line": 5,
22+
"language": "zig",
23+
"name": "struct",
24+
"original_indentation": 0,
25+
"start_line": 2
26+
},
27+
{
28+
"chunk_type": "CodeBlock",
29+
"comment_ranges": [],
30+
"content": "pub const Config = struct {\n debug: bool,\n verbose: bool,\n};",
31+
"end_line": 10,
32+
"language": "zig",
33+
"name": "struct",
34+
"original_indentation": 0,
35+
"start_line": 7
36+
}
37+
],
38+
"source_code": "\nconst Point = struct {\n x: f32,\n y: f32,\n};\n\npub const Config = struct {\n debug: bool,\n verbose: bool,\n};\n",
39+
"test_name": "test_zig_struct_extraction",
40+
"total_chunks": 3
41+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use crate::integration::languages::extractor::test_language_extractor;
2+
3+
test_language_extractor! {
4+
name: test_zig_function_extraction,
5+
language: "zig",
6+
extension: "zig",
7+
source: r#"
8+
pub fn add(a: i32, b: i32) i32 {
9+
return a + b;
10+
}
11+
12+
fn subtract(a: i32, b: i32) i32 {
13+
return a - b;
14+
}
15+
"#,
16+
total_chunks: 3,
17+
chunk_counts: {
18+
File: 1,
19+
Function: 2,
20+
}
21+
}
22+
23+
test_language_extractor! {
24+
name: test_zig_struct_extraction,
25+
language: "zig",
26+
extension: "zig",
27+
source: r#"
28+
const Point = struct {
29+
x: f32,
30+
y: f32,
31+
};
32+
33+
pub const Config = struct {
34+
debug: bool,
35+
verbose: bool,
36+
};
37+
"#,
38+
total_chunks: 3,
39+
chunk_counts: {
40+
File: 1,
41+
Function: 0,
42+
}
43+
}
44+
45+
test_language_extractor! {
46+
name: test_zig_mixed_extraction,
47+
language: "zig",
48+
extension: "zig",
49+
source: r#"
50+
const std = @import("std");
51+
52+
pub const Vector = struct {
53+
x: f32,
54+
y: f32,
55+
56+
pub fn init(x: f32, y: f32) Vector {
57+
return Vector{ .x = x, .y = y };
58+
}
59+
60+
pub fn length(self: Vector) f32 {
61+
return @sqrt(self.x * self.x + self.y * self.y);
62+
}
63+
};
64+
65+
pub fn main() !void {
66+
const stdout = std.io.getStdOut().writer();
67+
try stdout.print("Hello, Zig!\n", .{});
68+
}
69+
"#,
70+
total_chunks: 5,
71+
chunk_counts: {
72+
File: 1,
73+
Function: 3,
74+
}
75+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod extractor;

tests/integration/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ fn string_to_language_obj(language: &str) -> &'static dyn Language {
6666
"scala" => &Scala,
6767
"swift" => &Swift,
6868
"typescript" => &TypeScript,
69+
"zig" => &Zig,
6970
_ => panic!("Unsupported language: {}", language),
7071
}
7172
}

0 commit comments

Comments
 (0)