Compare commits
6 Commits
foreigntho
...
foreigntho
| Author | SHA1 | Date | |
|---|---|---|---|
| 2041c167cb | |||
| 6dc44dc5bc | |||
| 1bb09774d9 | |||
| 862aeaebbc | |||
| 084f05a2c1 | |||
| ef87091391 |
@@ -5,12 +5,13 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from foreignthon.transpiler import transpile, _detect_lang, _check_shebang
|
||||
from foreignthon.transpiler import _check_shebang, _detect_lang, transpile
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# All tests use the real foreignthon-es pack — no mocks
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def es(source: str) -> str:
|
||||
return transpile(source, "es")
|
||||
|
||||
@@ -19,27 +20,33 @@ def es(source: str) -> str:
|
||||
# Keywords
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_if_else():
|
||||
out = es("si x > 0:\n imprimir(x)\nsino:\n pasar")
|
||||
assert "if" in out and "else" in out and "pass" in out
|
||||
assert "si" not in out and "sino" not in out
|
||||
|
||||
|
||||
def test_for_loop():
|
||||
out = es("para i en rango(10):\n imprimir(i)")
|
||||
out = es("para i en dist(10):\n imprimir(i)")
|
||||
assert "for" in out and "in" in out and "range" in out
|
||||
|
||||
|
||||
def test_function_def():
|
||||
out = es("definir saludar(nombre):\n retornar nombre")
|
||||
out = es("def saludar(nombre):\n retornar nombre")
|
||||
assert "def" in out and "return" in out
|
||||
|
||||
|
||||
def test_class_def():
|
||||
out = es("clase Animal:\n pasar")
|
||||
assert "class" in out and "pass" in out
|
||||
|
||||
|
||||
def test_booleans_and_none():
|
||||
out = es("x = Verdadero\ny = Falso\nz = Nada")
|
||||
out = es("x = Verda\ny = Falso\nz = Nada")
|
||||
assert "True" in out and "False" in out and "None" in out
|
||||
|
||||
|
||||
def test_try_except():
|
||||
out = es(
|
||||
"intentar:\n"
|
||||
@@ -52,54 +59,66 @@ def test_try_except():
|
||||
assert "try" in out and "except" in out and "finally" in out
|
||||
assert "ValueError" in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Safety — strings and comments must never be touched
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_strings_not_transpiled():
|
||||
out = es('x = "si esto es para mientras definir"')
|
||||
assert '"si esto es para mientras definir"' in out
|
||||
out = es('x = "si esto es para mientras def"')
|
||||
assert '"si esto es para mientras def"' in out
|
||||
|
||||
|
||||
def test_comments_not_transpiled():
|
||||
out = es("# si para mientras\nx = 1")
|
||||
assert "# si para mientras" in out
|
||||
|
||||
|
||||
def test_fstring_not_touched():
|
||||
out = es('imprimir(f"si {x} para")')
|
||||
assert "si" in out # inside the string, untouched
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Output is always valid Python
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_output_is_valid_python():
|
||||
out = es(
|
||||
"definir sumar(a, b):\n"
|
||||
"def sumar(a, b):\n"
|
||||
" retornar a + b\n\n"
|
||||
"para i en rango(5):\n"
|
||||
"para i en dist(5):\n"
|
||||
" imprimir(sumar(i, 1))\n"
|
||||
)
|
||||
ast.parse(out) # raises if invalid
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Language detection
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_detect_lang_from_extension():
|
||||
assert _detect_lang(Path("script.es.py")) == "es"
|
||||
assert _detect_lang(Path("script.ta.py")) == "ta"
|
||||
|
||||
|
||||
def test_detect_lang_bad_extension():
|
||||
with pytest.raises(ValueError):
|
||||
_detect_lang(Path("script.py"))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Shebang override
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_shebang_override():
|
||||
assert _check_shebang("# foreignthon: fr\nsi x:\n pasar", "es") == "fr"
|
||||
|
||||
|
||||
def test_shebang_default_when_absent():
|
||||
assert _check_shebang("si x:\n pasar", "es") == "es"
|
||||
|
||||
@@ -108,14 +127,16 @@ def test_shebang_default_when_absent():
|
||||
# Postfix @@ syntax
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_postfix_if():
|
||||
out = es("x = 5\nx > 0 @@si:\n imprimir(x)")
|
||||
assert "if" in out
|
||||
assert "@@" not in out
|
||||
|
||||
|
||||
def test_postfix_preserves_indentation():
|
||||
src = (
|
||||
"definir comprobar(x):\n"
|
||||
"def comprobar(x):\n"
|
||||
" x > 0 @@si:\n"
|
||||
" imprimir(x)\n"
|
||||
" sino:\n"
|
||||
@@ -124,13 +145,9 @@ def test_postfix_preserves_indentation():
|
||||
out = es(src)
|
||||
ast.parse(out) # fails if indentation is broken
|
||||
|
||||
|
||||
def test_prefix_still_works_alongside_postfix():
|
||||
src = (
|
||||
"si x > 0:\n"
|
||||
" imprimir(x)\n"
|
||||
"y < 0 @@si:\n"
|
||||
" imprimir(y)\n"
|
||||
)
|
||||
src = "si x > 0:\n" " imprimir(x)\n" "y < 0 @@si:\n" " imprimir(y)\n"
|
||||
out = es(src)
|
||||
assert out.count("if") == 2
|
||||
assert "@@" not in out
|
||||
|
||||
@@ -4,18 +4,17 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-es"
|
||||
version = "0.2.10"
|
||||
version = "0.3.0"
|
||||
description = "Spanish language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
authors = [
|
||||
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" }
|
||||
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" },
|
||||
{ name = "Cody Trainer" },
|
||||
]
|
||||
keywords = ["foreignthon", "spanish", "español"]
|
||||
|
||||
dependencies = [
|
||||
"foreignthon>=0.4.0",
|
||||
]
|
||||
dependencies = ["foreignthon>=0.4.0"]
|
||||
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
es = "foreignthon_es"
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
"keywords": {
|
||||
"si": "if",
|
||||
"sino": "else",
|
||||
"sino_si": "elif",
|
||||
"osi": "elif",
|
||||
"para": "for",
|
||||
"mientras": "while",
|
||||
"definir": "def",
|
||||
"def": "def",
|
||||
"clase": "class",
|
||||
"importar": "import",
|
||||
"desde": "from",
|
||||
"de": "from",
|
||||
"como": "as",
|
||||
"retornar": "return",
|
||||
"romper": "break",
|
||||
"parar": "break",
|
||||
"continuar": "continue",
|
||||
"pasar": "pass",
|
||||
"intentar": "try",
|
||||
@@ -31,58 +31,60 @@
|
||||
"y": "and",
|
||||
"o": "or",
|
||||
"no": "not",
|
||||
"eliminar": "del",
|
||||
"elim": "del",
|
||||
"global": "global",
|
||||
"nolocal": "nonlocal",
|
||||
"afirmar": "assert",
|
||||
"generar": "yield",
|
||||
"esperar": "await",
|
||||
"asincrono": "async",
|
||||
"asinc": "async",
|
||||
"lambda": "lambda",
|
||||
"Verdadero": "True",
|
||||
"Verda": "True",
|
||||
"Falso": "False",
|
||||
"Nada": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"escribir": "print",
|
||||
"imprimir": "print",
|
||||
"entrada": "input",
|
||||
"longitud": "len",
|
||||
"rango": "range",
|
||||
"lon": "len",
|
||||
"dist": "range",
|
||||
"tipo": "type",
|
||||
"entero": "int",
|
||||
"decimal": "float",
|
||||
"cadena": "str",
|
||||
"ent": "int",
|
||||
"dec": "float",
|
||||
"texto": "str",
|
||||
"lista": "list",
|
||||
"diccionario": "dict",
|
||||
"conjunto": "set",
|
||||
"dicc": "dict",
|
||||
"conj": "set",
|
||||
"tupla": "tuple",
|
||||
"booleano": "bool",
|
||||
"bool": "bool",
|
||||
"abrir": "open",
|
||||
"enumerar": "enumerate",
|
||||
"mapear": "map",
|
||||
"map": "map",
|
||||
"filtrar": "filter",
|
||||
"ordenado": "sorted",
|
||||
"invertido": "reversed",
|
||||
"suma": "sum",
|
||||
"minimo": "min",
|
||||
"maximo": "max",
|
||||
"absoluto": "abs",
|
||||
"sum": "sum",
|
||||
"min": "min",
|
||||
"max": "max",
|
||||
"abs": "abs",
|
||||
"redondear": "round",
|
||||
"rnd": "round",
|
||||
"todos": "all",
|
||||
"alguno": "any",
|
||||
"es_instancia": "isinstance",
|
||||
"tiene_atributo": "hasattr",
|
||||
"obtener_atributo": "getattr",
|
||||
"establecer_atributo": "setattr",
|
||||
"representar": "repr",
|
||||
"esinstancia": "isinstance",
|
||||
"teneatri": "hasattr",
|
||||
"obtatri": "getattr",
|
||||
"estabatri": "setattr",
|
||||
"repr": "repr",
|
||||
"formatear": "format",
|
||||
"variables": "vars",
|
||||
"siguiente": "next",
|
||||
"identificador": "id",
|
||||
"caracter": "chr",
|
||||
"hexadecimal": "hex",
|
||||
"binario": "bin",
|
||||
"octal": "oct"
|
||||
"vars": "vars",
|
||||
"sigue": "next",
|
||||
"id": "id",
|
||||
"car": "chr",
|
||||
"hex": "hex",
|
||||
"bin": "bin",
|
||||
"oct": "oct"
|
||||
},
|
||||
"exceptions": {
|
||||
"Excepcion": "Exception",
|
||||
@@ -120,27 +122,28 @@
|
||||
"NameError": "Error de nombre",
|
||||
"ImportError": "Error de importación",
|
||||
"FileNotFoundError": "Archivo no encontrado",
|
||||
"ZeroDivisionError": "Error: división por cero",
|
||||
"ZeroDivisionError": "Error división por cero",
|
||||
"RecursionError": "Error de recursión",
|
||||
"RuntimeError": "Error de ejecución",
|
||||
"MemoryError": "Error de memoria",
|
||||
"OverflowError": "Error de desbordamiento",
|
||||
"AssertionError": "Error de afirmación",
|
||||
"NotImplementedError": "Error: no implementado",
|
||||
"NotImplementedError": "Error no implementado",
|
||||
"StopIteration": "Detener iteración",
|
||||
"KeyboardInterrupt": "Interrupción de teclado",
|
||||
"PermissionError": "Error de permiso",
|
||||
"TimeoutError": "Error de tiempo agotado"
|
||||
},
|
||||
"stdlib": {
|
||||
"matematicas": "math",
|
||||
"sistema": "sys",
|
||||
"fecha_hora": "datetime",
|
||||
"mate": "math",
|
||||
"sis": "sys",
|
||||
"fechahora": "datetime",
|
||||
"tiempo": "time",
|
||||
"aleatorio": "random",
|
||||
"aleatoria": "random",
|
||||
"colecciones": "collections",
|
||||
"ruta": "pathlib",
|
||||
"expresion_regular": "re"
|
||||
"er": "re"
|
||||
},
|
||||
"postfix_keywords": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-ta"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
description = "Tamil language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
},
|
||||
"keywords": {
|
||||
"ஆனால்": "if",
|
||||
"இல்லையெனில்": "else",
|
||||
"இல்லெனில்": "elif",
|
||||
"ஒவ்வொன்றும்": "for",
|
||||
"தொடர்": "while",
|
||||
"வரையறு": "def",
|
||||
"வகுப்பு": "class",
|
||||
"திரும்ப": "return",
|
||||
"மற்றபடி": "else",
|
||||
"இல்லைஆனால்": "elif",
|
||||
"ஆக": "for",
|
||||
"வரை": "while",
|
||||
"நிரல்பாகம்": "def",
|
||||
"கோப்பு": "class",
|
||||
"பின்கோடு": "return",
|
||||
"நிறுத்து": "break",
|
||||
"தொடரவும்": "continue",
|
||||
"தொடர்": "continue",
|
||||
"கடந்துசெல்": "pass",
|
||||
"முயற்சி": "try",
|
||||
"தவிர": "except",
|
||||
"இறுதியில்": "finally",
|
||||
"கடைசியில்": "finally",
|
||||
"எழுப்பு": "raise",
|
||||
"உடன்": "with",
|
||||
"இறக்கு": "import",
|
||||
@@ -44,13 +44,13 @@
|
||||
"ஒன்றுமில்லை": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"அச்சிடு": "print",
|
||||
"பதிப்பி": "print",
|
||||
"உள்ளீடு": "input",
|
||||
"நீளம்": "len",
|
||||
"வரம்பு": "range",
|
||||
"வகை": "type",
|
||||
"முழுஎண்": "int",
|
||||
"மிதவை": "float",
|
||||
"தசமஎண்": "float",
|
||||
"சரம்": "str",
|
||||
"பட்டியல்": "list",
|
||||
"அகராதி": "dict",
|
||||
@@ -131,12 +131,11 @@
|
||||
"if",
|
||||
"elif",
|
||||
"while",
|
||||
"def",
|
||||
"class",
|
||||
"for",
|
||||
"with",
|
||||
"try",
|
||||
"except",
|
||||
"finally"
|
||||
"finally",
|
||||
"from"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user