make kcl std lib first class (#1603)

* make kcl std lib first class

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* u[dates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-03-01 14:23:30 -08:00
committed by GitHub
parent 9d8a7064da
commit b81c9d04cc
10 changed files with 1864 additions and 194 deletions

View File

@ -133,6 +133,15 @@ impl StdLib {
Self { fns, kcl_fns }
}
// Get the combined hashmaps.
pub fn combined(&self) -> HashMap<String, Box<dyn StdLibFn>> {
let mut combined = self.fns.clone();
for (k, v) in self.kcl_fns.clone() {
combined.insert(k, v.std_lib());
}
combined
}
pub fn get(&self, name: &str) -> Option<Box<dyn StdLibFn>> {
self.fns.get(name).cloned()
}
@ -789,6 +798,7 @@ mod tests {
#[test]
fn test_generate_stdlib_markdown_docs() {
let stdlib = StdLib::new();
let combined = stdlib.combined();
let mut buf = String::new();
buf.push_str("<!--- DO NOT EDIT THIS FILE. IT IS AUTOMATICALLY GENERATED. -->\n\n");
@ -800,8 +810,8 @@ mod tests {
buf.push_str("* [Functions](#functions)\n");
for key in stdlib.fns.keys().sorted() {
let internal_fn = stdlib.fns.get(key).unwrap();
for key in combined.keys().sorted() {
let internal_fn = combined.get(key).unwrap();
if internal_fn.unpublished() || internal_fn.deprecated() {
continue;
}
@ -813,8 +823,8 @@ mod tests {
buf.push_str("## Functions\n\n");
for key in stdlib.fns.keys().sorted() {
let internal_fn = stdlib.fns.get(key).unwrap();
for key in combined.keys().sorted() {
let internal_fn = combined.get(key).unwrap();
if internal_fn.unpublished() {
continue;
}
@ -874,11 +884,12 @@ mod tests {
#[test]
fn test_generate_stdlib_json_schema() {
let stdlib = StdLib::new();
let combined = stdlib.combined();
let mut json_data = vec![];
for key in stdlib.fns.keys().sorted() {
let internal_fn = stdlib.fns.get(key).unwrap();
for key in combined.keys().sorted() {
let internal_fn = combined.get(key).unwrap();
json_data.push(internal_fn.to_json().unwrap());
}
expectorate::assert_contents(