Implement to-upper-case() and to-lower-case()

This commit is contained in:
ConnorSkees 2020-02-08 20:32:10 -05:00
parent 6c8dd6de93
commit 07845beee9
3 changed files with 46 additions and 0 deletions

View File

@ -23,6 +23,7 @@ lazy_static! {
let mut m = BTreeMap::new();
color::register(&mut m);
meta::register(&mut m);
string::register(&mut m);
m
};
}

View File

@ -1 +1,21 @@
use std::collections::BTreeMap;
use super::Builtin;
use crate::value::Value;
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
decl!(f "to-upper-case", |args, _| {
let s: &Value = arg!(args, 0, "string");
match s.eval() {
Value::Ident(i, q) => Some(Value::Ident(i.to_ascii_uppercase(), q)),
_ => todo!("")
}
});
decl!(f "to-lower-case", |args, _| {
let s: &Value = arg!(args, 0, "string");
match s.eval() {
Value::Ident(i, q) => Some(Value::Ident(i.to_ascii_lowercase(), q)),
_ => todo!("")
}
});
}

25
tests/strings.rs Normal file
View File

@ -0,0 +1,25 @@
#![cfg(test)]
#[macro_use]
mod macros;
test!(
uppercase_ident,
"a {\n color: to-upper-case(aBc123);\n}\n",
"a {\n color: ABC123;\n}\n"
);
test!(
lowercase_ident,
"a {\n color: to-lower-case(AbC123);\n}\n",
"a {\n color: abc123;\n}\n"
);
test!(
uppercase_named_arg,
"a {\n color: to-upper-case($string: aBc123);\n}\n",
"a {\n color: ABC123;\n}\n"
);
test!(
lowercase_named_arg,
"a {\n color: to-lower-case($string: AbC123);\n}\n",
"a {\n color: abc123;\n}\n"
);