Skip to content

Commit 0a6adce

Browse files
committed
cloning cursor instead of special closing logic
1 parent 2c30aa4 commit 0a6adce

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/test/java/io/github/treesitter/jtreesitter/TreeCursorTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ void setUp() {
3131

3232
@AfterEach
3333
void tearDown() {
34-
if(cursor != null){
35-
cursor.close();
36-
}
34+
cursor.close();
3735
}
3836

3937
@Test
@@ -44,16 +42,15 @@ void getCurrentNode() {
4442

4543
@Test
4644
void getCurrentNodeWithCustomAllocator() {
47-
48-
try(var arena = Arena.ofConfined()){
49-
var node = cursor.getCurrentNode(arena);
50-
assertEquals(tree.getRootNode(), node);
51-
cursor.close();
52-
cursor = null; // avoid double close
45+
try (var arena = Arena.ofConfined()) {
46+
Node node;
47+
try (TreeCursor copied = cursor.clone()) {
48+
node = copied.getCurrentNode(arena);
49+
assertEquals(tree.getRootNode(), node);
50+
}
5351
// can still access node after cursor was closed
5452
assertEquals(tree.getRootNode(), node);
5553
}
56-
5754
}
5855

5956
@Test

0 commit comments

Comments
 (0)