2024-03-13 12:56:46 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_examples_min {
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
|
|
|
|
async fn serial_test_example_min0() {
|
|
|
|
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
|
|
|
|
let http_client = reqwest::Client::builder()
|
|
|
|
.user_agent(user_agent)
|
|
|
|
.timeout(std::time::Duration::from_secs(600))
|
|
|
|
.connect_timeout(std::time::Duration::from_secs(60));
|
|
|
|
let ws_client = reqwest::Client::builder()
|
|
|
|
.user_agent(user_agent)
|
|
|
|
.timeout(std::time::Duration::from_secs(600))
|
|
|
|
.connect_timeout(std::time::Duration::from_secs(60))
|
|
|
|
.connection_verbose(true)
|
|
|
|
.tcp_keepalive(std::time::Duration::from_secs(600))
|
|
|
|
.http1_only();
|
|
|
|
let token = std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set");
|
2024-03-23 15:45:55 -07:00
|
|
|
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
|
|
|
|
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") {
|
|
|
|
client.set_base_url(addr);
|
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
let ws = client
|
|
|
|
.modeling()
|
|
|
|
.commands_ws(None, None, None, None, None, Some(false))
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let tokens = crate::token::lexer("This is another code block.\nyes sirrr.\nmin");
|
|
|
|
let parser = crate::parser::Parser::new(tokens);
|
|
|
|
let program = parser.ast().unwrap();
|
|
|
|
let mut mem: crate::executor::ProgramMemory = Default::default();
|
2024-03-26 19:32:31 -07:00
|
|
|
let ctx = crate::executor::ExecutorContext::new(ws, kittycad::types::UnitLength::Mm)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-13 12:56:46 -07:00
|
|
|
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
|
|
|
|
async fn serial_test_example_min1() {
|
|
|
|
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
|
|
|
|
let http_client = reqwest::Client::builder()
|
|
|
|
.user_agent(user_agent)
|
|
|
|
.timeout(std::time::Duration::from_secs(600))
|
|
|
|
.connect_timeout(std::time::Duration::from_secs(60));
|
|
|
|
let ws_client = reqwest::Client::builder()
|
|
|
|
.user_agent(user_agent)
|
|
|
|
.timeout(std::time::Duration::from_secs(600))
|
|
|
|
.connect_timeout(std::time::Duration::from_secs(60))
|
|
|
|
.connection_verbose(true)
|
|
|
|
.tcp_keepalive(std::time::Duration::from_secs(600))
|
|
|
|
.http1_only();
|
|
|
|
let token = std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set");
|
2024-03-23 15:45:55 -07:00
|
|
|
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
|
|
|
|
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") {
|
|
|
|
client.set_base_url(addr);
|
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
let ws = client
|
|
|
|
.modeling()
|
|
|
|
.commands_ws(None, None, None, None, None, Some(false))
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let tokens = crate::token::lexer("This is code.\nIt does other shit.\nmin");
|
|
|
|
let parser = crate::parser::Parser::new(tokens);
|
|
|
|
let program = parser.ast().unwrap();
|
|
|
|
let mut mem: crate::executor::ProgramMemory = Default::default();
|
2024-03-26 19:32:31 -07:00
|
|
|
let ctx = crate::executor::ExecutorContext::new(ws, kittycad::types::UnitLength::Mm)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-13 12:56:46 -07:00
|
|
|
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-25 13:41:04 -07:00
|
|
|
#[allow(non_camel_case_types, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: min\nThis is some function.\nIt does shit."]
|
2023-09-05 16:02:27 -07:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, schemars :: JsonSchema, ts_rs :: TS)]
|
|
|
|
#[ts(export)]
|
2023-08-25 13:41:04 -07:00
|
|
|
pub(crate) struct Min {}
|
|
|
|
|
|
|
|
#[allow(non_upper_case_globals, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: min\nThis is some function.\nIt does shit."]
|
2023-08-25 13:41:04 -07:00
|
|
|
pub(crate) const Min: Min = Min {};
|
2023-09-20 18:27:08 -07:00
|
|
|
fn boxed_min(
|
|
|
|
args: crate::std::Args,
|
|
|
|
) -> std::pin::Pin<
|
|
|
|
Box<
|
|
|
|
dyn std::future::Future<
|
|
|
|
Output = anyhow::Result<crate::executor::MemoryItem, crate::errors::KclError>,
|
|
|
|
>,
|
|
|
|
>,
|
|
|
|
> {
|
|
|
|
Box::pin(min(args))
|
|
|
|
}
|
|
|
|
|
2023-08-25 13:41:04 -07:00
|
|
|
impl crate::docs::StdLibFn for Min {
|
|
|
|
fn name(&self) -> String {
|
|
|
|
"min".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn summary(&self) -> String {
|
2024-03-13 12:56:46 -07:00
|
|
|
"This is some function.".to_string()
|
2023-08-25 13:41:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn description(&self) -> String {
|
2024-03-13 12:56:46 -07:00
|
|
|
"It does shit.".to_string()
|
2023-08-25 13:41:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn tags(&self) -> Vec<String> {
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn args(&self) -> Vec<crate::docs::StdLibFnArg> {
|
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
|
|
|
settings.inline_subschemas = true;
|
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
|
|
|
vec![crate::docs::StdLibFnArg {
|
|
|
|
name: "args".to_string(),
|
|
|
|
type_: "[number]".to_string(),
|
|
|
|
schema: <Vec<f64>>::json_schema(&mut generator),
|
|
|
|
required: true,
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
2023-09-05 16:02:27 -07:00
|
|
|
fn return_value(&self) -> Option<crate::docs::StdLibFnArg> {
|
2023-08-25 13:41:04 -07:00
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
|
|
|
settings.inline_subschemas = true;
|
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
2023-09-05 16:02:27 -07:00
|
|
|
Some(crate::docs::StdLibFnArg {
|
2023-08-25 13:41:04 -07:00
|
|
|
name: "".to_string(),
|
|
|
|
type_: "number".to_string(),
|
2024-03-12 12:54:45 -07:00
|
|
|
schema: <f64>::json_schema(&mut generator),
|
2023-08-25 13:41:04 -07:00
|
|
|
required: true,
|
2023-09-05 16:02:27 -07:00
|
|
|
})
|
2023-08-25 13:41:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn unpublished(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deprecated(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
fn examples(&self) -> Vec<String> {
|
|
|
|
let code_blocks = vec![
|
|
|
|
"This is another code block.\nyes sirrr.\nmin",
|
|
|
|
"This is code.\nIt does other shit.\nmin",
|
|
|
|
];
|
|
|
|
code_blocks
|
|
|
|
.iter()
|
|
|
|
.map(|cb| {
|
|
|
|
let tokens = crate::token::lexer(cb);
|
|
|
|
let parser = crate::parser::Parser::new(tokens);
|
|
|
|
let program = parser.ast().unwrap();
|
|
|
|
let mut options: crate::ast::types::FormatOptions = Default::default();
|
|
|
|
options.insert_final_newline = false;
|
|
|
|
program.recast(&options, 0)
|
|
|
|
})
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
}
|
|
|
|
|
2023-08-25 13:41:04 -07:00
|
|
|
fn std_lib_fn(&self) -> crate::std::StdFn {
|
2023-09-20 18:27:08 -07:00
|
|
|
boxed_min
|
2023-08-25 13:41:04 -07:00
|
|
|
}
|
2023-09-05 16:02:27 -07:00
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
|
|
|
Box::new(self.clone())
|
|
|
|
}
|
2023-08-25 13:41:04 -07:00
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = r" This is some function."]
|
|
|
|
#[doc = r" It does shit."]
|
|
|
|
#[doc = r""]
|
|
|
|
#[doc = r" This is code."]
|
|
|
|
#[doc = r" It does other shit."]
|
|
|
|
#[doc = r" min"]
|
|
|
|
#[doc = r""]
|
|
|
|
#[doc = r" ```"]
|
|
|
|
#[doc = r" This is another code block."]
|
|
|
|
#[doc = r" yes sirrr."]
|
|
|
|
#[doc = r" min"]
|
|
|
|
#[doc = r" ```"]
|
2023-08-25 13:41:04 -07:00
|
|
|
fn inner_min(#[doc = r" The args to do shit to."] args: Vec<f64>) -> f64 {
|
|
|
|
let mut min = std::f64::MAX;
|
|
|
|
for arg in args.iter() {
|
|
|
|
if *arg < min {
|
|
|
|
min = *arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
min
|
|
|
|
}
|