#[cfg(test)]
mod tests {
use crate::DepylerPipeline;
fn transpile(code: &str) -> String {
let pipeline = DepylerPipeline::new();
pipeline.transpile(code).expect("transpile")
}
fn transpile_ok(code: &str) -> bool {
let pipeline = DepylerPipeline::new();
pipeline.transpile(code).is_ok()
}
#[test]
fn test_sys_exit_with_code() {
let result = transpile("import sys\ndef quit_app(code: int) -> None:\n sys.exit(code)\n");
assert!(!result.is_empty());
assert!(result.contains("exit"));
}
#[test]
fn test_sys_exit_no_args() {
let result = transpile("import sys\ndef quit_app() -> None:\n sys.exit()\n");
assert!(!result.is_empty());
assert!(result.contains("exit"));
}
#[test]
fn test_sys_platform() {
let result = transpile("import sys\ndef get_platform() -> str:\n return sys.platform\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_version() {
let _ok = transpile_ok("import sys\ndef get_version() -> str:\n v = sys.version()\n return v\n");
}
#[test]
fn test_sys_argv() {
let result = transpile("import sys\ndef get_args() -> list:\n return sys.argv\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_path() {
let _ok = transpile_ok("import sys\ndef get_path() -> list:\n p = sys.path()\n return p\n");
}
#[test]
fn test_sys_stdin() {
let result = transpile("import sys\ndef get_stdin():\n return sys.stdin\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_stdout() {
let result = transpile("import sys\ndef get_stdout():\n return sys.stdout\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_stderr() {
let result = transpile("import sys\ndef get_stderr():\n return sys.stderr\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_maxsize() {
let _ok = transpile_ok("import sys\ndef get_maxsize() -> int:\n return sys.maxsize\n");
}
#[test]
fn test_re_search_string_literals() {
let result = transpile("import re\ndef search_pattern() -> bool:\n m = re.search(\"abc\", \"xabcy\")\n return m is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_search_variable_args() {
let result = transpile("import re\ndef search_pattern(pattern: str, text: str) -> bool:\n m = re.search(pattern, text)\n return m is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_match_string_literals() {
let result = transpile("import re\ndef match_pattern() -> bool:\n m = re.match(\"abc\", \"abcdef\")\n return m is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_match_variable_args() {
let result = transpile("import re\ndef match_pattern(pattern: str, text: str) -> bool:\n m = re.match(pattern, text)\n return m is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_fullmatch_string_literals() {
let result = transpile("import re\ndef fullmatch_pattern() -> bool:\n m = re.fullmatch(\"abc\", \"abc\")\n return m is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_fullmatch_variable_args() {
let result = transpile("import re\ndef fullmatch_pattern(pattern: str, text: str) -> bool:\n m = re.fullmatch(pattern, text)\n return m is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_findall_string_literals() {
let result = transpile("import re\ndef find_all() -> list:\n return re.findall(\"a\", \"banana\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_findall_variable_args() {
let result = transpile("import re\ndef find_all(pattern: str, text: str) -> list:\n return re.findall(pattern, text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_finditer_string_literals() {
let result = transpile("import re\ndef find_iter():\n return re.finditer(\"a\", \"banana\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_finditer_variable_args() {
let result = transpile("import re\ndef find_iter(pattern: str, text: str):\n return re.finditer(pattern, text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_sub_string_literals() {
let result = transpile("import re\ndef substitute() -> str:\n return re.sub(\"a\", \"b\", \"banana\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_sub_variable_args() {
let result = transpile("import re\ndef substitute(pattern: str, repl: str, text: str) -> str:\n return re.sub(pattern, repl, text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_subn_string_literals() {
let result = transpile("import re\ndef substitute_n():\n return re.subn(\"a\", \"b\", \"banana\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_subn_variable_args() {
let result = transpile("import re\ndef substitute_n(pattern: str, repl: str, text: str):\n return re.subn(pattern, repl, text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_split_string_literals() {
let result = transpile("import re\ndef split_text() -> list:\n return re.split(\",\", \"a,b,c\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_split_variable_args() {
let result = transpile("import re\ndef split_text(pattern: str, text: str) -> list:\n return re.split(pattern, text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_compile_string_literal() {
let result = transpile("import re\ndef compile_pattern():\n return re.compile(\"abc\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_compile_variable() {
let result = transpile("import re\ndef compile_pattern(pattern: str):\n return re.compile(pattern)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_escape_string_literal() {
let result = transpile("import re\ndef escape_text() -> str:\n return re.escape(\"hello.world\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_escape_variable() {
let result = transpile("import re\ndef escape_text(text: str) -> str:\n return re.escape(text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_colorsys_rgb_to_hsv() {
let result = transpile("import colorsys\ndef convert_color(r: float, g: float, b: float):\n return colorsys.rgb_to_hsv(r, g, b)\n");
assert!(!result.is_empty());
}
#[test]
fn test_colorsys_hsv_to_rgb() {
let result = transpile("import colorsys\ndef convert_color(h: float, s: float, v: float):\n return colorsys.hsv_to_rgb(h, s, v)\n");
assert!(!result.is_empty());
}
#[test]
fn test_colorsys_rgb_to_hls() {
let result = transpile("import colorsys\ndef convert_color(r: float, g: float, b: float):\n return colorsys.rgb_to_hls(r, g, b)\n");
assert!(!result.is_empty());
}
#[test]
fn test_colorsys_hls_to_rgb() {
let result = transpile("import colorsys\ndef convert_color(h: float, l: float, s: float):\n return colorsys.hls_to_rgb(h, l, s)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_b64encode() {
let result = transpile("import base64\ndef encode_data(data: bytes) -> str:\n return base64.b64encode(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_b64decode() {
let result = transpile("import base64\ndef decode_data(data: str) -> bytes:\n return base64.b64decode(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_urlsafe_b64encode() {
let result = transpile("import base64\ndef encode_url(data: bytes) -> str:\n return base64.urlsafe_b64encode(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_urlsafe_b64decode() {
let result = transpile("import base64\ndef decode_url(data: str) -> bytes:\n return base64.urlsafe_b64decode(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_b32encode() {
let _ok = transpile_ok("import base64\ndef encode_b32(data: bytes) -> bytes:\n return base64.b32encode(data)\n");
}
#[test]
fn test_base64_b32decode() {
let _ok = transpile_ok("import base64\ndef decode_b32(data: bytes) -> bytes:\n return base64.b32decode(data)\n");
}
#[test]
fn test_base64_b16encode() {
let result = transpile("import base64\ndef encode_hex(data: bytes) -> bytes:\n return base64.b16encode(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_b16decode() {
let result = transpile("import base64\ndef decode_hex(data: bytes) -> bytes:\n return base64.b16decode(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_md5_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.md5()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_md5_with_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.md5(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha1_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.sha1()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha1_with_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.sha1(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha256_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.sha256()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha256_with_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.sha256(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha512_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.sha512()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha512_with_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.sha512(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha384_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.sha384()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha384_with_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.sha384(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_blake2b_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.blake2b()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_blake2b_with_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.blake2b(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_blake2s_no_data() {
let result = transpile("import hashlib\ndef make_hash():\n return hashlib.blake2s()\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_new_no_args() {
let _ok = transpile_ok("import hashlib\ndef make_hash():\n return hashlib.new()\n");
}
#[test]
fn test_hashlib_new_with_algo() {
let result = transpile("import hashlib\ndef make_hash() -> None:\n h = hashlib.new(\"sha256\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_new_with_algo_and_data() {
let result = transpile("import hashlib\ndef make_hash(data: bytes):\n return hashlib.new(\"sha256\", data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_json_dumps() {
let result = transpile("import json\ndef to_json(data: dict) -> str:\n return json.dumps(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_json_loads() {
let result = transpile("import json\ndef from_json(text: str) -> dict:\n return json.loads(text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_math_sqrt() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.sqrt(x)\n");
assert!(!result.is_empty());
assert!(result.contains("sqrt"));
}
#[test]
fn test_math_sin() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.sin(x)\n");
assert!(!result.is_empty());
assert!(result.contains("sin"));
}
#[test]
fn test_math_cos() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.cos(x)\n");
assert!(!result.is_empty());
assert!(result.contains("cos"));
}
#[test]
fn test_math_tan() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.tan(x)\n");
assert!(!result.is_empty());
assert!(result.contains("tan"));
}
#[test]
fn test_math_floor() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.floor(x)\n");
assert!(!result.is_empty());
assert!(result.contains("floor"));
}
#[test]
fn test_math_ceil() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.ceil(x)\n");
assert!(!result.is_empty());
assert!(result.contains("ceil"));
}
#[test]
fn test_math_abs() {
let result = transpile("def calc(x: float) -> float:\n return abs(x)\n");
assert!(!result.is_empty());
assert!(result.contains("abs"));
}
#[test]
fn test_math_pow() {
let result = transpile("import math\ndef calc(x: float, y: float) -> float:\n return math.pow(x, y)\n");
assert!(!result.is_empty());
assert!(result.contains("powf"));
}
#[test]
fn test_math_log_natural() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.log(x)\n");
assert!(!result.is_empty());
assert!(result.contains("ln"));
}
#[test]
fn test_math_log_with_base() {
let result = transpile("import math\ndef calc(x: float, base: float) -> float:\n return math.log(x, base)\n");
assert!(!result.is_empty());
}
#[test]
fn test_math_exp() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.exp(x)\n");
assert!(!result.is_empty());
assert!(result.contains("exp"));
}
#[test]
fn test_random_randint() {
let result = transpile("import random\ndef roll(a: int, b: int) -> int:\n return random.randint(a, b)\n");
assert!(!result.is_empty());
}
#[test]
fn test_random_random() {
let result = transpile("import random\ndef get_rand() -> float:\n return random.random()\n");
assert!(!result.is_empty());
}
#[test]
fn test_random_choice() {
let result = transpile("import random\ndef pick(items: list):\n return random.choice(items)\n");
assert!(!result.is_empty());
}
#[test]
fn test_random_shuffle() {
let result = transpile("import random\ndef mix(items: list) -> None:\n random.shuffle(items)\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_time() {
let result = transpile("import time\ndef now() -> float:\n return time.time()\n");
assert!(!result.is_empty());
assert!(result.contains("SystemTime"));
}
#[test]
fn test_time_sleep() {
let result = transpile("import time\ndef wait(secs: float) -> None:\n time.sleep(secs)\n");
assert!(!result.is_empty());
assert!(result.contains("sleep"));
}
#[test]
fn test_time_monotonic() {
let result = transpile("import time\ndef tick():\n return time.monotonic()\n");
assert!(!result.is_empty());
assert!(result.contains("Instant"));
}
#[test]
fn test_time_perf_counter() {
let result = transpile("import time\ndef perf():\n return time.perf_counter()\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_process_time() {
let result = transpile("import time\ndef proc_time():\n return time.process_time()\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_ctime_no_args() {
let _ok = transpile_ok("import time\ndef get_ctime() -> str:\n return time.ctime()\n");
}
#[test]
fn test_time_ctime_with_timestamp() {
let result = transpile("import time\ndef get_ctime(ts: float) -> str:\n return time.ctime(ts)\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_gmtime_no_args() {
let result = transpile("import time\ndef get_gmtime():\n return time.gmtime()\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_gmtime_with_timestamp() {
let result = transpile("import time\ndef get_gmtime(ts: float):\n return time.gmtime(ts)\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_localtime_no_args() {
let result = transpile("import time\ndef get_localtime():\n return time.localtime()\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_localtime_with_timestamp() {
let result = transpile("import time\ndef get_localtime(ts: float):\n return time.localtime(ts)\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_mktime() {
let result = transpile("import time\ndef to_timestamp(t: tuple) -> float:\n return time.mktime(t)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_unlink() {
let result = transpile("import os\ndef remove_file(path: str) -> None:\n os.unlink(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_remove() {
let result = transpile("import os\ndef remove_file(path: str) -> None:\n os.remove(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_mkdir() {
let result = transpile("import os\ndef make_dir(path: str) -> None:\n os.mkdir(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_makedirs() {
let result = transpile("import os\ndef make_dirs(path: str) -> None:\n os.makedirs(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_rmdir() {
let result = transpile("import os\ndef remove_dir(path: str) -> None:\n os.rmdir(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_rename() {
let result = transpile("import os\ndef rename_file(src: str, dst: str) -> None:\n os.rename(src, dst)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_getcwd() {
let result = transpile("import os\ndef get_cwd() -> str:\n return os.getcwd()\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_chdir() {
let result = transpile("import os\ndef change_dir(path: str) -> None:\n os.chdir(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_listdir_no_args() {
let result = transpile("import os\ndef list_dir() -> list:\n return os.listdir()\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_listdir_with_path() {
let result = transpile("import os\ndef list_dir(path: str) -> list:\n return os.listdir(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_getenv_one_arg() {
let result = transpile("import os\ndef get_env(key: str) -> str:\n return os.getenv(key)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_getenv_two_args() {
let result = transpile("import os\ndef get_env(key: str, default: str) -> str:\n return os.getenv(key, default)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_join() {
let result = transpile("import os\ndef join_paths(a: str, b: str) -> str:\n return os.path.join(a, b)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_basename() {
let result = transpile("import os\ndef get_basename(path: str) -> str:\n return os.path.basename(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_dirname() {
let result = transpile("import os\ndef get_dirname(path: str) -> str:\n return os.path.dirname(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_exists() {
let result = transpile("import os\ndef file_exists(path: str) -> bool:\n return os.path.exists(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_isfile() {
let result = transpile("import os\ndef is_file(path: str) -> bool:\n return os.path.isfile(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_isdir() {
let result = transpile("import os\ndef is_dir(path: str) -> bool:\n return os.path.isdir(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_expanduser() {
let result = transpile("import os\ndef expand_home(path: str) -> str:\n return os.path.expanduser(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_environ_get() {
let result = transpile("import os\ndef get_env(key: str) -> str:\n return os.environ.get(key)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_environ_get_with_default() {
let result = transpile("import os\ndef get_env(key: str, default: str) -> str:\n return os.environ.get(key, default)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_environ_keys() {
let result = transpile("import os\ndef get_keys() -> list:\n return os.environ.keys()\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_environ_values() {
let result = transpile("import os\ndef get_values() -> list:\n return os.environ.values()\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_environ_items() {
let result = transpile("import os\ndef get_items() -> list:\n return os.environ.items()\n");
assert!(!result.is_empty());
}
#[test]
fn test_string_upper() {
let result = transpile("def up(s: str) -> str:\n return s.upper()\n");
assert!(!result.is_empty());
assert!(result.contains("to_uppercase"));
}
#[test]
fn test_string_lower() {
let result = transpile("def low(s: str) -> str:\n return s.lower()\n");
assert!(!result.is_empty());
assert!(result.contains("to_lowercase"));
}
#[test]
fn test_string_strip() {
let result = transpile("def strip_ws(s: str) -> str:\n return s.strip()\n");
assert!(!result.is_empty());
assert!(result.contains("trim"));
}
#[test]
fn test_string_lstrip() {
let result = transpile("def lstrip_ws(s: str) -> str:\n return s.lstrip()\n");
assert!(!result.is_empty());
assert!(result.contains("trim_start"));
}
#[test]
fn test_string_rstrip() {
let result = transpile("def rstrip_ws(s: str) -> str:\n return s.rstrip()\n");
assert!(!result.is_empty());
assert!(result.contains("trim_end"));
}
#[test]
fn test_string_startswith() {
let result = transpile("def check(s: str) -> bool:\n return s.startswith(\"hello\")\n");
assert!(!result.is_empty());
assert!(result.contains("starts_with"));
}
#[test]
fn test_string_endswith() {
let result = transpile("def check(s: str) -> bool:\n return s.endswith(\"world\")\n");
assert!(!result.is_empty());
assert!(result.contains("ends_with"));
}
#[test]
fn test_string_split_no_args() {
let result = transpile("def split_text(s: str) -> list:\n return s.split()\n");
assert!(!result.is_empty());
assert!(result.contains("split_whitespace"));
}
#[test]
fn test_string_split_with_sep() {
let result = transpile("def split_text(s: str) -> list:\n return s.split(\",\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_string_split_with_maxsplit() {
let result = transpile("def split_text(s: str) -> list:\n return s.split(\",\", 2)\n");
assert!(!result.is_empty());
assert!(result.contains("splitn"));
}
#[test]
fn test_string_join() {
let result = transpile("def join_parts(sep: str, parts: list) -> str:\n return sep.join(parts)\n");
assert!(!result.is_empty());
assert!(result.contains("join"));
}
#[test]
fn test_string_replace() {
let result = transpile("def replace_text(s: str) -> str:\n return s.replace(\"old\", \"new\")\n");
assert!(!result.is_empty());
assert!(result.contains("replace"));
}
#[test]
fn test_string_find() {
let result = transpile("def find_text(s: str) -> int:\n return s.find(\"needle\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_string_rfind() {
let result = transpile("def rfind_text(s: str) -> int:\n return s.rfind(\"needle\")\n");
assert!(!result.is_empty());
assert!(result.contains("rfind"));
}
#[test]
fn test_string_isdigit() {
let result = transpile("def is_digit(s: str) -> bool:\n return s.isdigit()\n");
assert!(!result.is_empty());
assert!(result.contains("is_ascii_digit"));
}
#[test]
fn test_string_isalpha() {
let result = transpile("def is_alpha(s: str) -> bool:\n return s.isalpha()\n");
assert!(!result.is_empty());
assert!(result.contains("is_alphabetic"));
}
#[test]
fn test_string_isalnum() {
let result = transpile("def is_alnum(s: str) -> bool:\n return s.isalnum()\n");
assert!(!result.is_empty());
assert!(result.contains("is_alphanumeric"));
}
#[test]
fn test_string_contains() {
let result = transpile("def has_text(s: str) -> bool:\n return s.contains(\"abc\")\n");
assert!(!result.is_empty());
assert!(result.contains("contains"));
}
#[test]
fn test_list_append() {
let result = transpile("def add_item(items: list, x: int) -> None:\n items.append(x)\n");
assert!(!result.is_empty());
assert!(result.contains("push"));
}
#[test]
fn test_list_pop_no_args() {
let result = transpile("def pop_item(items: list) -> int:\n return items.pop()\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_pop_with_index() {
let result = transpile("def pop_item(items: list, idx: int) -> int:\n return items.pop(idx)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_remove() {
let result = transpile("def remove_item(items: list, x: int) -> None:\n items.remove(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_clear() {
let result = transpile("def clear_list(items: list) -> None:\n items.clear()\n");
assert!(!result.is_empty());
assert!(result.contains("clear"));
}
#[test]
fn test_set_add() {
let result = transpile("def add_to_set(s: set, x: int) -> None:\n s.add(x)\n");
assert!(!result.is_empty());
assert!(result.contains("insert"));
}
#[test]
fn test_set_discard() {
let result = transpile("def discard_from_set(s: set, x: int) -> None:\n s.discard(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_copy() {
let result = transpile("def copy_list(items: list) -> list:\n return items.copy()\n");
assert!(!result.is_empty());
assert!(result.contains("clone"));
}
#[test]
fn test_dict_get_single_arg() {
let result = transpile("def get_val(d: dict, key: str):\n return d.get(key)\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_get_with_default() {
let result = transpile("def get_val(d: dict, key: str, default: int) -> int:\n return d.get(key, default)\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_get_with_string_default() {
let result = transpile("def get_val(d: dict, key: str) -> str:\n return d.get(key, \"fallback\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_acquire_method() {
let result = transpile("def lock_it(mutex) -> bool:\n return mutex.acquire()\n");
assert!(!result.is_empty());
}
#[test]
fn test_release_method() {
let result = transpile("def unlock_it(mutex) -> None:\n mutex.release()\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_fromkeys_with_default() {
let result = transpile("def make_dict(keys: list) -> dict:\n return dict.fromkeys(keys, 0)\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_fromkeys_no_default() {
let result = transpile("def make_dict(keys: list) -> dict:\n return dict.fromkeys(keys)\n");
assert!(!result.is_empty());
}
#[test]
fn test_int_from_bytes_big() {
let result = transpile("def to_int(data: bytes) -> int:\n return int.from_bytes(data, \"big\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_int_from_bytes_little() {
let result = transpile("def to_int(data: bytes) -> int:\n return int.from_bytes(data, \"little\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_threading_semaphore() {
let result = transpile("import threading\ndef make_sem() -> None:\n s = threading.Semaphore(5)\n");
assert!(!result.is_empty());
}
#[test]
fn test_threading_semaphore_no_args() {
let result = transpile("import threading\ndef make_sem() -> None:\n s = threading.Semaphore()\n");
assert!(!result.is_empty());
}
#[test]
fn test_threading_lock() {
let result = transpile("import threading\ndef make_lock() -> None:\n lk = threading.Lock()\n");
assert!(!result.is_empty());
}
#[test]
fn test_threading_rlock() {
let result = transpile("import threading\ndef make_lock() -> None:\n lk = threading.RLock()\n");
assert!(!result.is_empty());
}
#[test]
fn test_threading_event() {
let result = transpile("import threading\ndef make_event() -> None:\n ev = threading.Event()\n");
assert!(!result.is_empty());
}
#[test]
fn test_threading_thread() {
let result = transpile("import threading\ndef spawn_thread() -> None:\n t = threading.Thread()\n");
assert!(!result.is_empty());
}
#[test]
fn test_queue_queue() {
let result = transpile("import queue\ndef make_queue() -> None:\n q = queue.Queue()\n");
assert!(!result.is_empty());
}
#[test]
fn test_queue_lifo_queue() {
let result = transpile("import queue\ndef make_queue() -> None:\n q = queue.LifoQueue()\n");
assert!(!result.is_empty());
}
#[test]
fn test_queue_priority_queue() {
let result = transpile("import queue\ndef make_queue() -> None:\n q = queue.PriorityQueue()\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_datetime() {
let result = transpile("import datetime\ndef get_now() -> None:\n dt = datetime.datetime()\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_date() {
let result = transpile("import datetime\ndef get_date() -> None:\n d = datetime.date()\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_time() {
let result = transpile("import datetime\ndef get_time() -> None:\n t = datetime.time()\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_timedelta_with_arg() {
let result = transpile("import datetime\ndef delta(days: int) -> None:\n d = datetime.timedelta(days)\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_timedelta_no_args() {
let result = transpile("import datetime\ndef delta() -> None:\n d = datetime.timedelta()\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_now() {
let result = transpile("import datetime\ndef get_now() -> None:\n n = datetime.now()\n");
assert!(!result.is_empty());
}
#[test]
fn test_collections_deque_no_args() {
let result = transpile("import collections\ndef make_deque() -> None:\n d = collections.deque()\n");
assert!(!result.is_empty());
assert!(result.contains("VecDeque"));
}
#[test]
fn test_collections_deque_with_arg() {
let result = transpile("import collections\ndef make_deque(items: list) -> None:\n d = collections.deque(items)\n");
assert!(!result.is_empty());
}
#[test]
fn test_collections_counter_no_args() {
let result = transpile("import collections\ndef make_counter() -> None:\n c = collections.Counter()\n");
assert!(!result.is_empty());
}
#[test]
fn test_collections_counter_with_arg() {
let result = transpile("import collections\ndef make_counter(items: list) -> None:\n c = collections.Counter(items)\n");
assert!(!result.is_empty());
}
#[test]
fn test_collections_ordered_dict_no_args() {
let result = transpile("import collections\ndef make_od() -> None:\n od = collections.OrderedDict()\n");
assert!(!result.is_empty());
}
#[test]
fn test_collections_defaultdict() {
let result = transpile("import collections\ndef make_dd() -> None:\n dd = collections.defaultdict()\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_event() {
let result = transpile("import asyncio\ndef make_event() -> None:\n ev = asyncio.Event()\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_lock() {
let result = transpile("import asyncio\ndef make_lock() -> None:\n lk = asyncio.Lock()\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_semaphore_with_arg() {
let result = transpile("import asyncio\ndef make_sem(n: int) -> None:\n s = asyncio.Semaphore(n)\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_semaphore_no_arg() {
let result = transpile("import asyncio\ndef make_sem() -> None:\n s = asyncio.Semaphore()\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_queue() {
let result = transpile("import asyncio\ndef make_queue() -> None:\n q = asyncio.Queue()\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_sleep_with_arg() {
let result = transpile("import asyncio\ndef wait(s: float) -> None:\n asyncio.sleep(s)\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_sleep_no_arg() {
let result = transpile("import asyncio\ndef wait() -> None:\n asyncio.sleep()\n");
assert!(!result.is_empty());
}
#[test]
fn test_asyncio_run() {
let result = transpile("import asyncio\ndef run_async(coro) -> None:\n asyncio.run(coro)\n");
assert!(!result.is_empty());
}
#[test]
fn test_json_loads_constructor() {
let result = transpile("import json\ndef parse_json(s: str) -> dict:\n return json.loads(s)\n");
assert!(!result.is_empty());
}
#[test]
fn test_json_dumps_constructor() {
let result = transpile("import json\ndef to_json_str(data: dict) -> str:\n return json.dumps(data)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_comprehension_simple() {
let result = transpile("def squares(n: int) -> list:\n return [x * x for x in range(n)]\n");
assert!(!result.is_empty());
assert!(result.contains("into_iter"));
}
#[test]
fn test_list_comprehension_with_condition() {
let result = transpile("def evens(n: int) -> list:\n return [x for x in range(n) if x % 2 == 0]\n");
assert!(!result.is_empty());
assert!(result.contains("filter"));
}
#[test]
fn test_set_comprehension_simple() {
let result = transpile("def unique_squares(items: list) -> set:\n return {x * x for x in items}\n");
assert!(!result.is_empty());
assert!(result.contains("HashSet"));
}
#[test]
fn test_set_comprehension_with_condition() {
let result = transpile("def filtered_set(items: list) -> set:\n return {x for x in items if x > 0}\n");
assert!(!result.is_empty());
assert!(result.contains("filter"));
}
#[test]
fn test_dict_comprehension_simple() {
let result = transpile("def make_dict(keys: list) -> dict:\n return {k: k * 2 for k in keys}\n");
assert!(!result.is_empty());
assert!(result.contains("HashMap"));
}
#[test]
fn test_dict_comprehension_with_condition() {
let result = transpile("def filtered_dict(keys: list) -> dict:\n return {k: k * 2 for k in keys if k > 0}\n");
assert!(!result.is_empty());
assert!(result.contains("filter"));
}
#[test]
fn test_lambda_no_params() {
let result = transpile("def make_fn():\n f = lambda: 42\n return f\n");
assert!(!result.is_empty());
}
#[test]
fn test_lambda_one_param() {
let result = transpile("def make_fn():\n f = lambda x: x * 2\n return f\n");
assert!(!result.is_empty());
}
#[test]
fn test_lambda_two_params() {
let result = transpile("def make_fn():\n f = lambda x, y: x + y\n return f\n");
assert!(!result.is_empty());
}
#[test]
fn test_fstring_simple() {
let result = transpile("def greet(name: str) -> str:\n return f\"Hello {name}\"\n");
assert!(!result.is_empty());
assert!(result.contains("format!"));
}
#[test]
fn test_fstring_multiple_exprs() {
let result = transpile("def fmt(a: int, b: int) -> str:\n return f\"{a} + {b} = {a + b}\"\n");
assert!(!result.is_empty());
assert!(result.contains("format!"));
}
#[test]
fn test_fstring_no_expressions() {
let result = transpile("def constant() -> str:\n return f\"literal text only\"\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_argv_attribute() {
let result = transpile("import sys\ndef get_args() -> list:\n return sys.argv\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_version_attribute() {
let _ok = transpile_ok("import sys\ndef ver() -> str:\n return sys.version\n");
}
#[test]
fn test_sys_platform_attribute() {
let result = transpile("import sys\ndef plat() -> str:\n return sys.platform\n");
assert!(!result.is_empty());
}
#[test]
fn test_sys_maxsize_attribute() {
let _ok = transpile_ok("import sys\ndef max_int() -> int:\n return sys.maxsize\n");
}
#[test]
fn test_await_expression() {
let result = transpile("async def fetch(url: str) -> str:\n result = await get_data(url)\n return result\n");
assert!(!result.is_empty());
}
#[test]
fn test_dynamic_call_no_args() {
let result = transpile("def call_fn(handlers: dict, name: str):\n return handlers[name]()\n");
assert!(!result.is_empty());
}
#[test]
fn test_dynamic_call_with_args() {
let result = transpile("def call_fn(handlers: dict, name: str, x: int):\n return handlers[name](x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_deque_appendleft() {
let result = transpile("from collections import deque\ndef prepend(d: deque, x: int) -> None:\n d.appendleft(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_deque_popleft() {
let result = transpile("from collections import deque\ndef pop_front(d: deque):\n return d.popleft()\n");
assert!(!result.is_empty());
}
#[test]
fn test_fnmatch_fnmatch() {
let result = transpile("import fnmatch\ndef match_pattern(name: str, pattern: str) -> bool:\n return fnmatch.fnmatch(name, pattern)\n");
assert!(!result.is_empty());
}
#[test]
fn test_static_method_call() {
let result = transpile("def call_static() -> int:\n return Counter.create_with_value(5)\n");
assert!(!result.is_empty());
}
#[test]
fn test_classmethod_cls() {
let result = transpile("class MyClass:\n @classmethod\n def create(cls, x: int):\n return cls.new_instance(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_array() {
let result = transpile("import numpy as np\ndef make_arr():\n return np.array([1.0, 2.0, 3.0])\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_dot() {
let result = transpile("import numpy as np\ndef dot_product(a, b):\n return np.dot(a, b)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_sum() {
let result = transpile("import numpy as np\ndef total(a):\n return np.sum(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_mean() {
let result = transpile("import numpy as np\ndef average(a):\n return np.mean(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_sqrt_scalar() {
let result = transpile("import numpy as np\ndef root(x: float) -> float:\n return np.sqrt(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_abs_scalar() {
let result = transpile("import numpy as np\ndef absolute(x: float) -> float:\n return np.abs(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_min() {
let result = transpile("import numpy as np\ndef minimum(a):\n return np.min(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_max() {
let result = transpile("import numpy as np\ndef maximum(a):\n return np.max(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_exp_scalar() {
let result = transpile("import numpy as np\ndef exponent(x: float) -> float:\n return np.exp(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_log_scalar() {
let result = transpile("import numpy as np\ndef logarithm(x: float) -> float:\n return np.log(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_sin_scalar() {
let result = transpile("import numpy as np\ndef sine(x: float) -> float:\n return np.sin(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_cos_scalar() {
let result = transpile("import numpy as np\ndef cosine(x: float) -> float:\n return np.cos(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_clip() {
let result = transpile("import numpy as np\ndef clip_vals(a, lo: float, hi: float):\n return np.clip(a, lo, hi)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_argmax() {
let result = transpile("import numpy as np\ndef arg_max(a):\n return np.argmax(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_argmin() {
let result = transpile("import numpy as np\ndef arg_min(a):\n return np.argmin(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_std() {
let result = transpile("import numpy as np\ndef std_dev(a):\n return np.std(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_var() {
let result = transpile("import numpy as np\ndef variance(a):\n return np.var(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_zeros() {
let result = transpile("import numpy as np\ndef make_zeros(n: int):\n return np.zeros(n)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_ones() {
let result = transpile("import numpy as np\ndef make_ones(n: int):\n return np.ones(n)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_norm() {
let result = transpile("import numpy as np\ndef l2_norm(a):\n return np.norm(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_startswith_variable_arg() {
let result = transpile("def check(s: str, prefix: str) -> bool:\n return s.startswith(prefix)\n");
assert!(!result.is_empty());
}
#[test]
fn test_endswith_variable_arg() {
let result = transpile("def check(s: str, suffix: str) -> bool:\n return s.endswith(suffix)\n");
assert!(!result.is_empty());
}
#[test]
fn test_split_variable_sep() {
let result = transpile("def split_it(s: str, sep: str) -> list:\n return s.split(sep)\n");
assert!(!result.is_empty());
}
#[test]
fn test_find_variable_arg() {
let result = transpile("def find_it(s: str, sub: str) -> int:\n return s.find(sub)\n");
assert!(!result.is_empty());
}
#[test]
fn test_rfind_variable_arg() {
let result = transpile("def rfind_it(s: str, sub: str) -> int:\n return s.rfind(sub)\n");
assert!(!result.is_empty());
}
#[test]
fn test_replace_variable_args() {
let result = transpile("def replace_it(s: str, old: str, new: str) -> str:\n return s.replace(old, new)\n");
assert!(!result.is_empty());
}
#[test]
fn test_contains_variable_arg() {
let result = transpile("def has_it(s: str, sub: str) -> bool:\n return s.contains(sub)\n");
assert!(!result.is_empty());
}
#[test]
fn test_math_in_function_body() {
let result = transpile("import math\ndef distance(x1: float, y1: float, x2: float, y2: float) -> float:\n dx = x2 - x1\n dy = y2 - y1\n return math.sqrt(dx * dx + dy * dy)\n");
assert!(!result.is_empty());
assert!(result.contains("sqrt"));
}
#[test]
fn test_json_round_trip() {
let result = transpile("import json\ndef round_trip(data: dict) -> dict:\n text = json.dumps(data)\n return json.loads(text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_combined() {
let result = transpile("import os\ndef check_path(base: str, name: str) -> bool:\n path = os.path.join(base, name)\n return os.path.exists(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_measure() {
let result = transpile("import time\ndef measure() -> float:\n start = time.time()\n time.sleep(1.0)\n end = time.time()\n return end - start\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_combined() {
let result = transpile("import re\ndef process(text: str) -> str:\n cleaned = re.sub(\"\\\\s+\", \" \", text)\n return cleaned\n");
assert!(!result.is_empty());
}
#[test]
fn test_date_min() {
let result = transpile("import datetime\ndef get_min_date():\n return date.min\n");
assert!(!result.is_empty());
}
#[test]
fn test_date_max() {
let result = transpile("import datetime\ndef get_max_date():\n return date.max\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_min() {
let result = transpile("import datetime\ndef get_min_dt():\n return datetime.min\n");
assert!(!result.is_empty());
}
#[test]
fn test_datetime_max() {
let result = transpile("import datetime\ndef get_max_dt():\n return datetime.max\n");
assert!(!result.is_empty());
}
#[test]
fn test_enum_constant_access() {
let result = transpile("def get_color() -> int:\n return Color.RED\n");
assert!(!result.is_empty());
assert!(result.contains("Color"));
}
#[test]
fn test_type_constant_access() {
let result = transpile("def get_mode():\n return FileMode.READ_ONLY\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_contains_key_by_name() {
let result = transpile("def has_key(d: dict, k: str) -> bool:\n return d.contains_key(k)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_extend() {
let result = transpile("def extend_list(items: list, more: list) -> None:\n items.extend(more)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_insert() {
let result = transpile("def insert_item(items: list, idx: int, val: int) -> None:\n items.insert(idx, val)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_getcwd_constructor() {
let result = transpile("import os\ndef cwd() -> str:\n return os.getcwd()\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_getenv_constructor() {
let result = transpile("import os\ndef env(key: str) -> str:\n return os.getenv(key)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_listdir_constructor() {
let result = transpile("import os\ndef ls(path: str) -> list:\n return os.listdir(path)\n");
assert!(!result.is_empty());
}
#[test]
fn test_property_method_access() {
let result = transpile("class MyClass:\n def get_name(self) -> str:\n return self.name\n");
assert!(!result.is_empty());
}
#[test]
fn test_self_field_clone() {
let result = transpile("class MyClass:\n def get_items(self) -> list:\n return self.items\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_search_in_function() {
let result = transpile("import re\ndef validate_email(email: str) -> bool:\n pattern = \"^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$\"\n result = re.search(pattern, email)\n return result is not None\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_findall_in_function() {
let result = transpile("import re\ndef extract_numbers(text: str) -> list:\n return re.findall(\"[0-9]+\", text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_re_sub_in_function() {
let result = transpile("import re\ndef clean_whitespace(text: str) -> str:\n return re.sub(\"\\\\s+\", \" \", text)\n");
assert!(!result.is_empty());
}
#[test]
fn test_math_combined_trig() {
let result = transpile("import math\ndef trig_identity(x: float) -> float:\n return math.sin(x) * math.sin(x) + math.cos(x) * math.cos(x)\n");
assert!(!result.is_empty());
}
#[test]
fn test_math_combined_arithmetic() {
let result = transpile("import math\ndef calc(x: float) -> float:\n return math.floor(math.sqrt(x))\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_encode_decode_round_trip() {
let result = transpile("import base64\ndef round_trip(data: bytes) -> bytes:\n encoded = base64.b64encode(data)\n return base64.b64decode(encoded)\n");
assert!(!result.is_empty());
}
#[test]
fn test_base64_urlsafe_round_trip() {
let result = transpile("import base64\ndef round_trip(data: bytes) -> bytes:\n encoded = base64.urlsafe_b64encode(data)\n return base64.urlsafe_b64decode(encoded)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_array_empty() {
let result = transpile("import numpy as np\ndef empty_arr():\n return np.array([])\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_amin() {
let result = transpile("import numpy as np\ndef arr_min(a):\n return np.amin(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_numpy_amax() {
let result = transpile("import numpy as np\ndef arr_max(a):\n return np.amax(a)\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_comp_with_method_call() {
let result = transpile("def upper_all(words: list) -> list:\n return [w.upper() for w in words]\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_comp_with_arithmetic() {
let result = transpile("def doubles(n: int) -> list:\n return [x * 2 for x in range(n)]\n");
assert!(!result.is_empty());
}
#[test]
fn test_set_comp_with_arithmetic() {
let result = transpile("def unique_mods(items: list) -> set:\n return {x % 10 for x in items}\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_comp_with_enumerate() {
let result = transpile("def index_map(items: list) -> dict:\n return {i: v for i, v in enumerate(items)}\n");
assert!(transpile_ok("def index_map(items: list) -> dict:\n return {i: v for i, v in enumerate(items)}\n"));
}
#[test]
fn test_lambda_with_condition() {
let result = transpile("def make_filter():\n f = lambda x: x > 0\n return f\n");
assert!(!result.is_empty());
}
#[test]
fn test_fstring_with_method_call() {
let result = transpile("def fmt(name: str) -> str:\n return f\"Hello {name.upper()}\"\n");
assert!(!result.is_empty());
}
#[test]
fn test_fstring_with_arithmetic() {
let result = transpile("def fmt(x: int, y: int) -> str:\n return f\"Sum is {x + y}\"\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_sha256_round_trip() {
let result = transpile("import hashlib\ndef hash_data(data: bytes):\n h = hashlib.sha256()\n return h\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_md5_data_flow() {
let result = transpile("import hashlib\ndef hash_data(data: bytes):\n h = hashlib.md5(data)\n return h\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_thread_time() {
let result = transpile("import time\ndef thread_timer():\n return time.thread_time()\n");
assert!(!result.is_empty());
}
#[test]
fn test_time_perf_counter_usage() {
let result = transpile("import time\ndef benchmark() -> float:\n start = time.perf_counter()\n end = time.perf_counter()\n return end - start\n");
assert!(!result.is_empty());
}
#[test]
fn test_dict_update() {
let result = transpile("def merge(d: dict, other: dict) -> None:\n d.update(other)\n");
assert!(!result.is_empty());
}
#[test]
fn test_set_update() {
let result = transpile("def merge_sets(s: set, other: set) -> None:\n s.update(other)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_join_three_parts() {
let result = transpile("import os\ndef join_three(a: str, b: str, c: str) -> str:\n return os.path.join(a, b, c)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_path_join_single() {
let result = transpile("import os\ndef to_path(s: str) -> str:\n return os.path.join(s)\n");
assert!(!result.is_empty());
}
#[test]
fn test_random_and_math() {
let result = transpile("import random\nimport math\ndef random_angle() -> float:\n angle = random.random()\n return math.sin(angle)\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_and_json() {
let result = transpile("import os\nimport json\ndef read_config(path: str) -> dict:\n exists = os.path.exists(path)\n return json.loads(\"{}\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_hashlib_and_base64() {
let result = transpile("import hashlib\nimport base64\ndef hash_encode(data: bytes):\n h = hashlib.sha256(data)\n return h\n");
assert!(!result.is_empty());
}
#[test]
fn test_ok_math_all_funcs() {
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.sqrt(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.sin(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.cos(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.tan(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.floor(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.ceil(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float) -> float:\n return math.exp(x)\n"));
assert!(transpile_ok("import math\ndef f(x: float, y: float) -> float:\n return math.pow(x, y)\n"));
}
#[test]
fn test_ok_re_all_funcs() {
assert!(transpile_ok("import re\ndef f(p: str, t: str):\n return re.search(p, t)\n"));
assert!(transpile_ok("import re\ndef f(p: str, t: str):\n return re.match(p, t)\n"));
assert!(transpile_ok("import re\ndef f(p: str, t: str):\n return re.fullmatch(p, t)\n"));
assert!(transpile_ok("import re\ndef f(p: str, t: str):\n return re.findall(p, t)\n"));
assert!(transpile_ok("import re\ndef f(p: str, r: str, t: str):\n return re.sub(p, r, t)\n"));
}
#[test]
fn test_ok_time_all_funcs() {
assert!(transpile_ok("import time\ndef f() -> float:\n return time.time()\n"));
assert!(transpile_ok("import time\ndef f(s: float) -> None:\n time.sleep(s)\n"));
assert!(transpile_ok("import time\ndef f():\n return time.monotonic()\n"));
}
#[test]
fn test_ok_numpy_all_funcs() {
assert!(transpile_ok("import numpy as np\ndef f(a):\n return np.sum(a)\n"));
assert!(transpile_ok("import numpy as np\ndef f(a):\n return np.mean(a)\n"));
assert!(transpile_ok("import numpy as np\ndef f(a):\n return np.min(a)\n"));
assert!(transpile_ok("import numpy as np\ndef f(a):\n return np.max(a)\n"));
assert!(transpile_ok("import numpy as np\ndef f(a):\n return np.std(a)\n"));
assert!(transpile_ok("import numpy as np\ndef f(a):\n return np.var(a)\n"));
}
#[test]
fn test_ok_base64_all_funcs() {
assert!(transpile_ok("import base64\ndef f(d: bytes):\n return base64.b64encode(d)\n"));
assert!(transpile_ok("import base64\ndef f(d: str):\n return base64.b64decode(d)\n"));
assert!(transpile_ok("import base64\ndef f(d: bytes):\n return base64.urlsafe_b64encode(d)\n"));
assert!(transpile_ok("import base64\ndef f(d: str):\n return base64.urlsafe_b64decode(d)\n"));
let _ = transpile_ok("import base64\ndef f(d: bytes):\n return base64.b32encode(d)\n");
let _ = transpile_ok("import base64\ndef f(d: bytes):\n return base64.b32decode(d)\n");
assert!(transpile_ok("import base64\ndef f(d: bytes):\n return base64.b16encode(d)\n"));
assert!(transpile_ok("import base64\ndef f(d: bytes):\n return base64.b16decode(d)\n"));
}
#[test]
fn test_ok_hashlib_all_funcs() {
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.md5()\n"));
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.sha1()\n"));
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.sha256()\n"));
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.sha512()\n"));
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.sha384()\n"));
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.blake2b()\n"));
assert!(transpile_ok("import hashlib\ndef f():\n return hashlib.blake2s()\n"));
}
#[test]
fn test_ok_os_all_funcs() {
assert!(transpile_ok("import os\ndef f(p: str) -> None:\n os.mkdir(p)\n"));
assert!(transpile_ok("import os\ndef f(p: str) -> None:\n os.makedirs(p)\n"));
assert!(transpile_ok("import os\ndef f(p: str) -> None:\n os.rmdir(p)\n"));
assert!(transpile_ok("import os\ndef f(p: str) -> None:\n os.unlink(p)\n"));
assert!(transpile_ok("import os\ndef f(a: str, b: str) -> None:\n os.rename(a, b)\n"));
}
#[test]
fn test_ok_string_all_methods() {
assert!(transpile_ok("def f(s: str) -> str:\n return s.upper()\n"));
assert!(transpile_ok("def f(s: str) -> str:\n return s.lower()\n"));
assert!(transpile_ok("def f(s: str) -> str:\n return s.strip()\n"));
assert!(transpile_ok("def f(s: str) -> str:\n return s.lstrip()\n"));
assert!(transpile_ok("def f(s: str) -> str:\n return s.rstrip()\n"));
assert!(transpile_ok("def f(s: str) -> bool:\n return s.isdigit()\n"));
assert!(transpile_ok("def f(s: str) -> bool:\n return s.isalpha()\n"));
assert!(transpile_ok("def f(s: str) -> bool:\n return s.isalnum()\n"));
}
#[test]
fn test_ok_collection_methods() {
assert!(transpile_ok("def f(items: list, x: int) -> None:\n items.append(x)\n"));
assert!(transpile_ok("def f(items: list) -> int:\n return items.pop()\n"));
assert!(transpile_ok("def f(items: list) -> None:\n items.clear()\n"));
assert!(transpile_ok("def f(items: list) -> list:\n return items.copy()\n"));
}
#[test]
fn test_sys_getsizeof() {
let _ok = transpile_ok("import sys\ndef get_size(obj) -> int:\n return sys.getsizeof(obj)\n");
}
#[test]
fn test_collections_ordered_dict_with_arg() {
let result = transpile("import collections\ndef make_od(items: list) -> dict:\n return collections.OrderedDict(items)\n");
assert!(!result.is_empty());
}
#[test]
fn test_lambda_with_string_operation() {
let result = transpile("def make_upper():\n f = lambda s: s.upper()\n return f\n");
assert!(!result.is_empty());
}
#[test]
fn test_lambda_with_math() {
let result = transpile("def make_squarer():\n f = lambda x: x * x\n return f\n");
assert!(!result.is_empty());
}
#[test]
fn test_list_comp_filter_transform() {
let result = transpile("def process(items: list) -> list:\n return [x * 2 for x in items if x > 0]\n");
assert!(!result.is_empty());
assert!(result.contains("filter"));
assert!(result.contains("map"));
}
#[test]
fn test_nested_method_calls() {
let result = transpile("def process(s: str) -> str:\n return s.strip().lower()\n");
assert!(!result.is_empty());
}
#[test]
fn test_method_call_chain() {
let result = transpile("def process(s: str) -> list:\n return s.strip().split(\",\")\n");
assert!(!result.is_empty());
}
#[test]
fn test_os_environ_insert() {
let result = transpile("import os\ndef set_env(key: str, val: str) -> None:\n os.environ.insert(key, val)\n");
assert!(transpile_ok("import os\ndef set_env(key: str, val: str) -> None:\n os.environ.insert(key, val)\n"));
}
#[test]
fn test_os_environ_contains_key() {
let result = transpile("import os\ndef has_env(key: str) -> bool:\n return os.environ.contains_key(key)\n");
assert!(transpile_ok("import os\ndef has_env(key: str) -> bool:\n return os.environ.contains_key(key)\n"));
}
}