#[derive(Debug, Clone)]
pub struct LanguageTerminology {
pub element_type_singular: String,
pub element_type_plural: String,
pub function_label: String,
pub function_label_plural: String,
pub return_type_default: String,
pub property_label: String,
pub property_label_plural: String,
}
impl LanguageTerminology {
pub fn generic() -> Self {
LanguageTerminology {
element_type_singular: "type".to_string(),
element_type_plural: "types".to_string(),
function_label: "item".to_string(),
function_label_plural: "items".to_string(),
return_type_default: "—".to_string(),
property_label: "field".to_string(),
property_label_plural: "fields".to_string(),
}
}
pub fn rust() -> Self {
LanguageTerminology {
element_type_singular: "struct".to_string(),
element_type_plural: "structs".to_string(),
function_label: "fn".to_string(),
function_label_plural: "fns".to_string(),
return_type_default: "()".to_string(),
property_label: "field".to_string(),
property_label_plural: "fields".to_string(),
}
}
#[allow(dead_code)]
pub fn python() -> Self {
LanguageTerminology {
element_type_singular: "class".to_string(),
element_type_plural: "classes".to_string(),
function_label: "def".to_string(),
function_label_plural: "defs".to_string(),
return_type_default: "None".to_string(),
property_label: "attribute".to_string(),
property_label_plural: "attributes".to_string(),
}
}
#[allow(dead_code)]
pub fn go() -> Self {
LanguageTerminology {
element_type_singular: "type".to_string(),
element_type_plural: "types".to_string(),
function_label: "func".to_string(),
function_label_plural: "funcs".to_string(),
return_type_default: "error".to_string(),
property_label: "field".to_string(),
property_label_plural: "fields".to_string(),
}
}
#[allow(dead_code)]
pub fn haskell() -> Self {
LanguageTerminology {
element_type_singular: "data type".to_string(),
element_type_plural: "data types".to_string(),
function_label: "function".to_string(),
function_label_plural: "functions".to_string(),
return_type_default: "IO ()".to_string(),
property_label: "constructor".to_string(),
property_label_plural: "constructors".to_string(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generic_terminology() {
let generic = LanguageTerminology::generic();
assert_eq!(generic.element_type_singular, "type");
assert_eq!(generic.function_label, "item");
}
#[test]
fn test_rust_terminology_override() {
let rust = LanguageTerminology::rust();
assert_eq!(rust.element_type_singular, "struct");
assert_eq!(rust.function_label, "fn");
assert_eq!(rust.return_type_default, "()");
}
#[test]
fn test_python_terminology() {
let python = LanguageTerminology::python();
assert_eq!(python.element_type_singular, "class");
assert_eq!(python.function_label, "def");
assert_eq!(python.return_type_default, "None");
}
}