Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,42 @@ fn runnables_nested_test() {
"languages/java/runnables.scm",
);
}

// ============================================================================
// Outline Tests
// ============================================================================

#[test]
fn outline() {
support::assert_query_snapshot(
"outline",
"tests/languages/java/org/example/Outline.java",
"languages/java/outline.scm",
);
}

// ============================================================================
// Textobjects Tests
// ============================================================================

#[test]
fn textobjects() {
support::assert_query_snapshot(
"textobjects",
"tests/languages/java/org/example/TextObjects.java",
"languages/java/textobjects.scm",
);
}

// ============================================================================
// Injections Tests
// ============================================================================

#[test]
fn injections() {
support::assert_query_snapshot(
"injections",
"tests/languages/java/org/example/Injections.java",
"languages/java/injections.scm",
);
}
14 changes: 14 additions & 0 deletions tests/languages/java/org/example/Injections.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example;

// This is a line comment injection content.
/* This is a block comment injection content. */
/**
* This is a Javadoc comment matching doxygen-like rules.
*/
public class Injections {
public void test() {
System.out.printf("Printf format string: %s %d\n", "hello", 123);
String.format("Format string: %x", 255);
String formatted = "Formatted string literal: %s".formatted("example");
}
}
56 changes: 56 additions & 0 deletions tests/languages/java/org/example/Outline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.example;

public class Outline {
public static final String CONSTANT_FIELD = "value";
private String instanceField;

static {
// static initializer block
System.out.println("Static Init");
}

public Outline() {
this.instanceField = "default";
}

public Outline(String value) {
this.instanceField = value;
}

public String getInstanceField() {
return instanceField;
}

public static void staticMethod() {
// static method
}

private static class NestedClass {
private int nestedField;
}
}

interface ExampleInterface {
int INTERFACE_CONSTANT = 42;

void abstractMethod();

default void defaultMethod() {
// default method
}
}

record ExampleRecord(String first, int second) {
public ExampleRecord {
// compact constructor
}
}

enum ExampleEnum {
FIRST_CONSTANT,
SECOND_CONSTANT;
}

@interface ExampleAnnotation {
String value() default "default_val";
}
55 changes: 55 additions & 0 deletions tests/languages/java/org/example/TextObjects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.example;

// This is a block comment
// with multiple lines for testing
// comment.around
public class TextObjects {
/*
* This is a block comment in the class
*/
private String name;

public TextObjects(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void runLambda() {
Runnable r1 = () -> {
System.out.println("Block lambda body");
};

Runnable r2 = () -> System.out.println("Expression lambda body");
}
}

interface TestInterface {
void process();

default void log() {
System.out.println("Interface log");
}
}

enum TestEnum {
A, B, C;

public void print() {
System.out.println(this.name());
}
}

record TestRecord(int value) {
public TestRecord {
if (value < 0) {
throw new IllegalArgumentException();
}
}
}

@interface TestAnnotation {
String value();
}
48 changes: 48 additions & 0 deletions tests/languages/java/snapshots/injections.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
source: tests/support/mod.rs
expression: captures
---
- name: injection.content
line: 3
column: 1
text: // This is a line comment injection content.
- name: injection.content
line: 4
column: 1
text: /* This is a block comment injection content. */
- name: injection.content
line: 4
column: 1
text: /* This is a block comment injection content. */
- name: injection.content
line: 5
column: 1
text: "/**\n * This is a Javadoc comment matching doxygen-like rules.\n */"
- name: injection.content
line: 5
column: 1
text: "/**\n * This is a Javadoc comment matching doxygen-like rules.\n */"
- name: _method
line: 10
column: 20
text: printf
- name: injection.content
line: 10
column: 28
text: "Printf format string: %s %d"
- name: _method
line: 11
column: 16
text: format
- name: injection.content
line: 11
column: 24
text: "Format string: %x"
- name: injection.content
line: 12
column: 29
text: "Formatted string literal: %s"
- name: _method
line: 12
column: 59
text: formatted
Loading