Skip to content

Commit

Permalink
feat: add tests for tree-sitter backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfaller committed Oct 23, 2024
1 parent b9a42bc commit 0de6d9e
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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 2022 Jean-Rémy Falleri <[email protected]>
* Copyright 2024 Jean-Rémy Falleri <[email protected]>
*/
package com.github.gumtreediff.gen.treesitterng;

Expand All @@ -32,11 +32,11 @@ public class GoTreeSitterNgTreeGeneratorTest {

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("package main\n" +
"import \"fmt\"\n" +
"func main() {\n" +
" fmt.Println(\"hello world\")\n" +
"}");
TreeContext src = generator.generateFrom().string("package main\n"
+ "import \"fmt\"\n"
+ "func main() {\n"
+ " fmt.Println(\"hello world\")\n"
+ "}");
assertEquals(20, src.getRoot().getMetrics().size);
}
}
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 JavaScriptTreeSitterNgTreeGeneratorTest {
private final JavaScriptTreeSitterNgTreeGenerator generator = new JavaScriptTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("alert('Hello World!');");
assertEquals(12, src.getRoot().getMetrics().size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JavaTreeSitterNgTreeGeneratorTest {
private final JavaTreeSitterNgTreeGenerator generator = new JavaTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("class HelloWorld {\n"
+ " public static void main(String[] args) {\n"
+ " System.out.println(\"Hello World!\"); \n"
+ " }\n"
+ "}");
assertEquals(27, src.getRoot().getMetrics().size);
}

@Test
public void testCommentLine() throws IOException {
TreeContext src = generator.generateFrom().file("testData/java/commentLine/src/Test.java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@
import java.io.IOException;

import static com.github.gumtreediff.gen.treesitterng.TreeSitterNgTestUtils.onlyOneUpdate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class KotlinTreeSitterNgTreeGeneratorTest {
private final KotlinTreeSitterNgTreeGenerator generator = new KotlinTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("fun main(args : Array<String>) {\n"
+ " println(\"Hello, World!\")\n"
+ "}");
assertEquals(21, src.getRoot().getMetrics().size);
}

@Test
public void testAffectationOperatorChange() throws IOException {
Tree src = generator.generateFrom().string(
Expand Down
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 OcamlTreeSitterNgTreeGeneratorTest {
private final OcamlTreeSitterNgTreeGenerator generator = new OcamlTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("let () = print_endline \"Hello, World!\"");
assertEquals(12, src.getRoot().getMetrics().size);
}
}
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 PhpTreeSitterNgTreeGeneratorTest {
private final PhpTreeSitterNgTreeGenerator generator = new PhpTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("<?php\n"
+ "echo \"Hello World!\";\n"
+ "?>");
assertEquals(11, src.getRoot().getMetrics().size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
public class PythonTreeSitterNgTreeGeneratorTest {
private final PythonTreeSitterNgTreeGenerator generator = new PythonTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("print(\"Hello World!\")");
assertEquals(6, src.getRoot().getMetrics().size);
}

@Test
public void testString() throws IOException {
TreeContext src = generator.generateFrom().file("testData/python/foo.py");
Expand Down
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 RubyTreeSitterNgTreeGeneratorTest {
private final RubyTreeSitterNgTreeGenerator generator = new RubyTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("puts \"Hello World\"");
assertEquals(8, src.getRoot().getMetrics().size);
}
}
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 RustTreeSitterNgTreeGeneratorTest {
private final RustTreeSitterNgTreeGenerator generator = new RustTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("fn main() {\n"
+ " println!(\"Hello World!\");\n"
+ "}");
assertEquals(11, src.getRoot().getMetrics().size);
}
}
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 TypeScriptTreeSitterNgTreeGeneratorTest {
private final TypeScriptTreeSitterNgTreeGenerator generator = new TypeScriptTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("alert('Hello World!');");
assertEquals(12, src.getRoot().getMetrics().size);
}
}

0 comments on commit 0de6d9e

Please sign in to comment.