Implement to-upper-case()
and to-lower-case()
This commit is contained in:
parent
6c8dd6de93
commit
07845beee9
@ -23,6 +23,7 @@ lazy_static! {
|
||||
let mut m = BTreeMap::new();
|
||||
color::register(&mut m);
|
||||
meta::register(&mut m);
|
||||
string::register(&mut m);
|
||||
m
|
||||
};
|
||||
}
|
||||
|
@ -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
25
tests/strings.rs
Normal 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"
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user