-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add swift support. add tests for each tree-sitter-ng project.
- Loading branch information
Showing
7 changed files
with
208 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...src/main/java/com/github/gumtreediff/gen/treesitterng/SwiftTreeSitterNgTreeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* This file is part of GumTree. | ||
* | ||
* GumTree is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* GumTree is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright 2021 Jean-Rémy Falleri <[email protected]> | ||
*/ | ||
|
||
package com.github.gumtreediff.gen.treesitterng; | ||
|
||
import com.github.gumtreediff.gen.Register; | ||
import com.github.gumtreediff.utils.Registry; | ||
import org.treesitter.TSLanguage; | ||
import org.treesitter.TreeSitterSwift; | ||
|
||
@Register(id = "swift-treesitter-ng", accept = "\\.swift$", priority = Registry.Priority.HIGH) | ||
public final class SwiftTreeSitterNgTreeGenerator extends AbstractTreeSitterNgGenerator { | ||
public static final TSLanguage SWIFT_TREE_SITTER_LANGUAGE = new TreeSitterSwift(); | ||
private static final String SWIFT_LANGUAGE_NAME = "swift"; | ||
|
||
@Override | ||
protected TSLanguage getTreeSitterLanguage() { | ||
return SWIFT_TREE_SITTER_LANGUAGE; | ||
} | ||
|
||
@Override | ||
protected String getLanguageName() { | ||
return SWIFT_LANGUAGE_NAME; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...test/java/com/github/gumtreediff/gen/treesitterng/CMakeTreeSitterNgTreeGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of GumTree. | ||
* | ||
* GumTree is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* GumTree is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright 2024 Jean-Rémy Falleri <[email protected]> | ||
*/ | ||
package com.github.gumtreediff.gen.treesitterng; | ||
|
||
import com.github.gumtreediff.tree.TreeContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CMakeTreeSitterNgTreeGeneratorTest { | ||
private final CMakeTreeSitterNgTreeGenerator generator = new CMakeTreeSitterNgTreeGenerator(); | ||
|
||
@Test | ||
public void testHelloWorld() throws IOException { | ||
TreeContext src = generator.generateFrom().string("project(HelloWorld)\n" | ||
+ "cmake_minimum_required(VERSION 3.0)\n" | ||
+ "add_executable(hello_world main.cpp)"); | ||
assertEquals(26, src.getRoot().getMetrics().size); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...src/test/java/com/github/gumtreediff/gen/treesitterng/CTreeSitterNgTreeGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of GumTree. | ||
* | ||
* GumTree is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* GumTree is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright 2024 Jean-Rémy Falleri <[email protected]> | ||
*/ | ||
package com.github.gumtreediff.gen.treesitterng; | ||
|
||
import com.github.gumtreediff.tree.TreeContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CTreeSitterNgTreeGeneratorTest { | ||
private final CTreeSitterNgTreeGenerator generator = new CTreeSitterNgTreeGenerator(); | ||
|
||
@Test | ||
public void testHelloWorld() throws IOException { | ||
TreeContext src = generator.generateFrom().string("#include <stdio.h>\n" | ||
+ "int main() {\n" | ||
+ " printf(\"Hello, World!\");\n" | ||
+ " return 0;\n" | ||
+ "}"); | ||
assertEquals(29, src.getRoot().getMetrics().size); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...src/test/java/com/github/gumtreediff/gen/treesitterng/RTreeSitterNgTreeGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This file is part of GumTree. | ||
* | ||
* GumTree is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* GumTree is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright 2024 Jean-Rémy Falleri <[email protected]> | ||
*/ | ||
package com.github.gumtreediff.gen.treesitterng; | ||
|
||
import com.github.gumtreediff.tree.TreeContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class RTreeSitterNgTreeGeneratorTest { | ||
private final RTreeSitterNgTreeGenerator generator = new RTreeSitterNgTreeGenerator(); | ||
|
||
@Test | ||
public void testHelloWorld() throws IOException { | ||
TreeContext src = generator.generateFrom().string("print(\"Hello World!\")"); | ||
assertEquals(9, src.getRoot().getMetrics().size); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...test/java/com/github/gumtreediff/gen/treesitterng/SwiftTreeSitterNgTreeGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This file is part of GumTree. | ||
* | ||
* GumTree is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* GumTree is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright 2024 Jean-Rémy Falleri <[email protected]> | ||
*/ | ||
package com.github.gumtreediff.gen.treesitterng; | ||
|
||
import com.github.gumtreediff.tree.TreeContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class SwiftTreeSitterNgTreeGeneratorTest { | ||
private final SwiftTreeSitterNgTreeGenerator generator = new SwiftTreeSitterNgTreeGenerator(); | ||
|
||
@Test | ||
public void testHelloWorld() throws IOException { | ||
TreeContext src = generator.generateFrom().string("print(\"Hello, World!\")"); | ||
assertEquals(12, src.getRoot().getMetrics().size); | ||
} | ||
} |