From 1cb460932f5d418e7e43545c4aa8e14a1ea65093 Mon Sep 17 00:00:00 2001 From: dabico Date: Tue, 31 Oct 2023 11:00:57 +0100 Subject: [PATCH] Added a completely new test case specifically for `toBuilder` --- .../ch/usi/si/seart/treesitter/QueryTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/ch/usi/si/seart/treesitter/QueryTest.java b/src/test/java/ch/usi/si/seart/treesitter/QueryTest.java index 3daac7ba..87f0b471 100644 --- a/src/test/java/ch/usi/si/seart/treesitter/QueryTest.java +++ b/src/test/java/ch/usi/si/seart/treesitter/QueryTest.java @@ -102,4 +102,32 @@ public Stream provideArguments(ExtensionContext extensionCo void testQueryException(String ignored, Supplier 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()); + } }