Skip to content

Commit

Permalink
Added a completely new test case specifically for toBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico committed Oct 31, 2023
1 parent b26f102 commit 1cb4609
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/java/ch/usi/si/seart/treesitter/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,32 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext extensionCo
void testQueryException(String ignored, Supplier<Query> supplier) {
Assertions.assertThrows(NullPointerException.class, supplier::get);
}

@Test
void testQueryToBuilder() {
@Cleanup Query original = Query.builder()
.language(language)
.pattern("(line_comment)")
.build();
Query.Builder builder = original.toBuilder();
@Cleanup Query modified = builder
.pattern("(block_comment)")
.build();
Assertions.assertNotEquals(original, modified);
Assertions.assertEquals(1, original.getPatterns().size());
Assertions.assertEquals(2, modified.getPatterns().size());
Assertions.assertEquals(original.getLanguage(), modified.getLanguage());
@Cleanup Query overwrite = builder
.patterns(List.of("(_)"))
.build();
Assertions.assertNotEquals(original, overwrite);
Assertions.assertEquals(original.getPatterns().size(), overwrite.getPatterns().size());
Assertions.assertNotEquals(original.getPattern(), overwrite.getPattern());
Assertions.assertEquals(original.getLanguage(), modified.getLanguage());
@Cleanup Query empty = builder.pattern().build();
Assertions.assertNotEquals(original, empty);
Assertions.assertEquals(1, original.getPatterns().size());
Assertions.assertEquals(0, empty.getPatterns().size());
Assertions.assertEquals(original.getLanguage(), empty.getLanguage());
}
}

0 comments on commit 1cb4609

Please sign in to comment.