Skip to content

Commit f60959d

Browse files
committed
cloning cursor instead of special closing logic
1 parent ae27c2e commit f60959d

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
@@ -45,16 +43,15 @@ void getCurrentNode() {
4543

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

6057
@Test

0 commit comments

Comments
 (0)