Skip to content

Commit 0813d0b

Browse files
authored
test: add tree-sitter snapshot tests for outline, textobjects, and injections (#257)
Improves tree-sitter query test coverage for the Java extension by adding snapshot tests for outline, textobjects, and injections, similar to those in the Ruby extension https://github.com/zed-extensions/ruby/tree/main/tests
1 parent 679544d commit 0813d0b

7 files changed

Lines changed: 752 additions & 0 deletions

File tree

‎tests/java.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,42 @@ fn runnables_nested_test() {
7070
"languages/java/runnables.scm",
7171
);
7272
}
73+
74+
// ============================================================================
75+
// Outline Tests
76+
// ============================================================================
77+
78+
#[test]
79+
fn outline() {
80+
support::assert_query_snapshot(
81+
"outline",
82+
"tests/languages/java/org/example/Outline.java",
83+
"languages/java/outline.scm",
84+
);
85+
}
86+
87+
// ============================================================================
88+
// Textobjects Tests
89+
// ============================================================================
90+
91+
#[test]
92+
fn textobjects() {
93+
support::assert_query_snapshot(
94+
"textobjects",
95+
"tests/languages/java/org/example/TextObjects.java",
96+
"languages/java/textobjects.scm",
97+
);
98+
}
99+
100+
// ============================================================================
101+
// Injections Tests
102+
// ============================================================================
103+
104+
#[test]
105+
fn injections() {
106+
support::assert_query_snapshot(
107+
"injections",
108+
"tests/languages/java/org/example/Injections.java",
109+
"languages/java/injections.scm",
110+
);
111+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.example;
2+
3+
// This is a line comment injection content.
4+
/* This is a block comment injection content. */
5+
/**
6+
* This is a Javadoc comment matching doxygen-like rules.
7+
*/
8+
public class Injections {
9+
public void test() {
10+
System.out.printf("Printf format string: %s %d\n", "hello", 123);
11+
String.format("Format string: %x", 255);
12+
String formatted = "Formatted string literal: %s".formatted("example");
13+
}
14+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.example;
2+
3+
public class Outline {
4+
public static final String CONSTANT_FIELD = "value";
5+
private String instanceField;
6+
7+
static {
8+
// static initializer block
9+
System.out.println("Static Init");
10+
}
11+
12+
public Outline() {
13+
this.instanceField = "default";
14+
}
15+
16+
public Outline(String value) {
17+
this.instanceField = value;
18+
}
19+
20+
public String getInstanceField() {
21+
return instanceField;
22+
}
23+
24+
public static void staticMethod() {
25+
// static method
26+
}
27+
28+
private static class NestedClass {
29+
private int nestedField;
30+
}
31+
}
32+
33+
interface ExampleInterface {
34+
int INTERFACE_CONSTANT = 42;
35+
36+
void abstractMethod();
37+
38+
default void defaultMethod() {
39+
// default method
40+
}
41+
}
42+
43+
record ExampleRecord(String first, int second) {
44+
public ExampleRecord {
45+
// compact constructor
46+
}
47+
}
48+
49+
enum ExampleEnum {
50+
FIRST_CONSTANT,
51+
SECOND_CONSTANT;
52+
}
53+
54+
@interface ExampleAnnotation {
55+
String value() default "default_val";
56+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.example;
2+
3+
// This is a block comment
4+
// with multiple lines for testing
5+
// comment.around
6+
public class TextObjects {
7+
/*
8+
* This is a block comment in the class
9+
*/
10+
private String name;
11+
12+
public TextObjects(String name) {
13+
this.name = name;
14+
}
15+
16+
public String getName() {
17+
return name;
18+
}
19+
20+
public void runLambda() {
21+
Runnable r1 = () -> {
22+
System.out.println("Block lambda body");
23+
};
24+
25+
Runnable r2 = () -> System.out.println("Expression lambda body");
26+
}
27+
}
28+
29+
interface TestInterface {
30+
void process();
31+
32+
default void log() {
33+
System.out.println("Interface log");
34+
}
35+
}
36+
37+
enum TestEnum {
38+
A, B, C;
39+
40+
public void print() {
41+
System.out.println(this.name());
42+
}
43+
}
44+
45+
record TestRecord(int value) {
46+
public TestRecord {
47+
if (value < 0) {
48+
throw new IllegalArgumentException();
49+
}
50+
}
51+
}
52+
53+
@interface TestAnnotation {
54+
String value();
55+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
source: tests/support/mod.rs
3+
expression: captures
4+
---
5+
- name: injection.content
6+
line: 3
7+
column: 1
8+
text: // This is a line comment injection content.
9+
- name: injection.content
10+
line: 4
11+
column: 1
12+
text: /* This is a block comment injection content. */
13+
- name: injection.content
14+
line: 4
15+
column: 1
16+
text: /* This is a block comment injection content. */
17+
- name: injection.content
18+
line: 5
19+
column: 1
20+
text: "/**\n * This is a Javadoc comment matching doxygen-like rules.\n */"
21+
- name: injection.content
22+
line: 5
23+
column: 1
24+
text: "/**\n * This is a Javadoc comment matching doxygen-like rules.\n */"
25+
- name: _method
26+
line: 10
27+
column: 20
28+
text: printf
29+
- name: injection.content
30+
line: 10
31+
column: 28
32+
text: "Printf format string: %s %d"
33+
- name: _method
34+
line: 11
35+
column: 16
36+
text: format
37+
- name: injection.content
38+
line: 11
39+
column: 24
40+
text: "Format string: %x"
41+
- name: injection.content
42+
line: 12
43+
column: 29
44+
text: "Formatted string literal: %s"
45+
- name: _method
46+
line: 12
47+
column: 59
48+
text: formatted

0 commit comments

Comments
 (0)