Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements #3

Merged
merged 6 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions albero/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"comment": "Comment",
"_": "Keyword",
"as": "Keyword",
"assert": "Keyword",
"break": "Keyword",
"case": "Keyword",
"class": "Keyword",
"continue": "Keyword",
"def": "Keyword",
"elif": "Keyword",
"else": "Keyword",
"except": "Keyword",
"false": "Keyword",
"for": "Keyword",
"from": "Keyword",
Expand All @@ -27,16 +29,20 @@
"pass": "Keyword",
"raise": "Keyword",
"return": "Keyword",
"try": "Keyword",
"true": "Keyword",
"while": "Keyword",
"with": "Keyword",
"@": "Name",
"identifier": "Name",
"float": "Number",
"finally": "Number",
"integer": "Number",
"!=": "Operator",
"*": "Operator",
"**": "Operator",
"*=": "Operator",
"**=": "Operator",
"+": "Operator",
"+=": "Operator",
"-": "Operator",
Expand Down
3 changes: 3 additions & 0 deletions tests/test-languages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# tests/test-langauges

This folder aims to test that the mappings work the for the languages that have mappings
107 changes: 107 additions & 0 deletions tests/test-languages/java_test_file.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.example;

import java.util.*; // Import statement

/**
* This is a block comment
*/

public class Test {

public static void main(String[] args) {
// Line comment
int a = 5; // decimal_integer_literal
double b = 5.5; // decimal_floating_point_literal
boolean isTrue = true; // boolean and true keyword
boolean isFalse = false; // boolean and false keyword
String str = "Hello, World!"; // String
char c = 'A'; // character_literal
char esc = '\n'; // escape_sequence

a += 1; // += operator
a -= 1; // -= operator
a *= 2; // *= operator
a /= 2; // /= operator
a %= 2; // % operator
a++; // ++ operator
a--; // -- operator

if (a == 5) { // if and == operator
System.out.println("Equal to 5"); // Method call
} else if (a != 5) { // else if and != operator
System.out.println("Not equal to 5");
} else { // else keyword
System.out.println("Something else");
}

while (a < 10) { // while and < operator
a++; // Increment
}

for (int i = 0; i < 10; i++) { // for loop and < operator
System.out.println(i); // Method call
}

try { // try keyword
throw new Exception("Error!"); // throw and new keyword
} catch (Exception e) { // catch keyword
e.printStackTrace(); // Method call
} finally { // finally keyword
System.out.println("Finally block");
}

assert a == 10; // assert keyword and == operator

switch (a) {
case 10: // case keyword
System.out.println("Case 10");
break; // break keyword
default:
System.out.println("Default case");
break;
}

boolean condition = a > 5 && a < 15; // && and <, > operators
boolean orCondition = a > 5 || a < 15; // || operator

Test test = new Test();
test.exampleMethod();
}

public void exampleMethod() {
super.toString(); // super keyword
this.toString(); // this keyword
}

public interface ExampleInterface { // interface keyword
void example(); // Method in interface
}

public abstract class ExampleAbstractClass { // abstract class
public abstract void example(); // abstract method
}

public class ExampleClass extends ExampleAbstractClass implements ExampleInterface { // class, extends, implements keywords
@Override
public void example() { // @Override annotation
// Method implementation
}
}

private final int privateFinalVar = 1; // private, final keywords
protected static int protectedStaticVar = 2; // protected, static keywords
public int publicVar = 3; // public keyword

public void returnVoid() {
return; // return keyword
}

public int returnInt() {
return 1; // return keyword with value
}

boolean notCondition = !isTrue; // ! operator
boolean ternaryCondition = (a == 10) ? true : false; // ternary operator ? :

int[] array = new int[]{1, 2, 3}; // array and new keyword
}
89 changes: 89 additions & 0 deletions tests/test-languages/python_test_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from typing import Any

from xyz import abc as efg # noqa: F401

# Example comment

# Variables and literals
u = {"x": "y\f"} # String with escape sequence
v = 5.5 # float
w = [] # list
x = 5 # integer
y = int("5") # integer from string
z = lambda: print # lambda function # noqa: E731

# Control structures
if x == 5: # if statement
x += 5 + x # Addition and compound assignment
x -= 5 - x # Subtraction and compound assignment
x *= 2 * x # Multiplication and compound assignment
x /= 2 / x # Division and compound assignment
x **= 2**x # Exponentiation and compound assignment
if x is not None: # is not
pass # pass statement
elif x is None: # elif and is
pass
else: # else
pass

# match-case statement
match x:
case 5: # case
print("Nice")
case _: # case _
print("Woah")

# while loop and break statement
while 2 in w: # in operator
break
if 2 not in w: # not in operator
pass


# Function with decorator
def decorator(arg) -> Any: # Function definition and type hint
def wrapper(): # Nested function
return arg() # return statement

return wrapper


@decorator
def example():
if x > y: # Greater than
pass
if x >= y: # Greater than or equal
pass
if x < y: # Less than
pass
if x <= y: # Less than or equal
pass
...
if x or y: # Logical OR
pass
with open("xyz.foo") as l: # with statement and as # noqa: F841, E741
assert False == False # assert statement and equality # noqa: E712
assert True == True # noqa: E712
pass


# Class with method
class Foo:
def break_func(self):
raise Exception("NO") # raise statement


# for loop and continue statement
for i in range(x):
continue

# Dictionary merging (Python 3.9+)
q = {} | {} # Dictionary merge operator

# try-except-finally block
try:
pass
except: # bare except # noqa: E722
pass
finally: # finally
pass
Loading
Loading