use super::DpTran;
use super::DeeplAPIError;
use super::connection;
use super::ApiKeyType;
pub mod api;
pub fn get_language_codes(api: &DpTran, type_name: String) -> Result<Vec<api::LangCodeName>, DeeplAPIError> {
api::get_language_codes(api, type_name)
}
#[cfg(test)]
pub mod tests {
use super::*;
fn do_api_get_language_codes_test(times: u8) {
let (api_key, api_key_type) = super::super::tests::get_api_key();
let api = DpTran::with_endpoint(&api_key, &api_key_type, super::super::tests::get_endpoint());
let res = get_language_codes(&api, "source".to_string());
match res {
Ok(res) => {
if res.len() == 0 {
panic!("Error: language codes is empty");
}
let mut found = false;
for i in 0..api::EXTENDED_LANG_CODES.len() {
if res.iter().any(|x| x.0 == api::EXTENDED_LANG_CODES[i].0 && x.1 == api::EXTENDED_LANG_CODES[i].1) {
found = true;
break;
}
}
if !found {
panic!("Error: extended language codes not found");
}
},
Err(e) => {
if super::super::tests::retry_or_panic_for_api_tests(&e, times) {
do_api_get_language_codes_test(times + 1);
return;
}
}
}
}
#[test]
fn api_get_language_codes_test() {
do_api_get_language_codes_test(0);
}
}