2024-03-13 12:56:46 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_examples_import {
|
2024-05-15 10:17:29 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_mock_example_import0() {
|
|
|
|
let tokens = crate::token::lexer("This is code.\nIt does other shit.\nimport").unwrap();
|
|
|
|
let parser = crate::parser::Parser::new(tokens);
|
|
|
|
let program = parser.ast().unwrap();
|
|
|
|
let ctx = crate::executor::ExecutorContext {
|
|
|
|
engine: std::sync::Arc::new(Box::new(
|
|
|
|
crate::engine::conn_mock::EngineConnection::new()
|
|
|
|
.await
|
|
|
|
.unwrap(),
|
|
|
|
)),
|
|
|
|
fs: std::sync::Arc::new(crate::fs::FileManager::new()),
|
|
|
|
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
|
|
|
|
settings: Default::default(),
|
|
|
|
is_mock: true,
|
|
|
|
};
|
2024-06-26 14:51:47 -07:00
|
|
|
ctx.run(&program, None).await.unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
|
2024-08-12 13:06:30 -07:00
|
|
|
async fn kcl_test_example_import0() {
|
2024-07-31 09:54:46 -05:00
|
|
|
let code = "This is code.\nIt does other shit.\nimport";
|
|
|
|
let result =
|
|
|
|
crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-26 21:28:50 -07:00
|
|
|
twenty_twenty::assert_image(
|
|
|
|
&format!("tests/outputs/{}.png", "serial_test_example_import0"),
|
2024-07-31 09:54:46 -05:00
|
|
|
&result,
|
2024-07-15 17:41:41 -05:00
|
|
|
0.99,
|
2024-03-26 21:28:50 -07:00
|
|
|
);
|
2024-03-13 12:56:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-12 12:18:37 -08:00
|
|
|
#[allow(non_camel_case_types, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: import\nThis is some function.\nIt does shit."]
|
2024-02-12 12:18:37 -08:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, schemars :: JsonSchema, ts_rs :: TS)]
|
|
|
|
#[ts(export)]
|
|
|
|
pub(crate) struct Import {}
|
|
|
|
|
|
|
|
#[allow(non_upper_case_globals, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: import\nThis is some function.\nIt does shit."]
|
2024-02-12 12:18:37 -08:00
|
|
|
pub(crate) const Import: Import = Import {};
|
|
|
|
fn boxed_import(
|
|
|
|
args: crate::std::Args,
|
|
|
|
) -> std::pin::Pin<
|
|
|
|
Box<
|
|
|
|
dyn std::future::Future<
|
2024-08-12 16:53:24 -05:00
|
|
|
Output = anyhow::Result<crate::executor::KclValue, crate::errors::KclError>,
|
2024-04-12 21:32:57 -07:00
|
|
|
> + Send,
|
2024-02-12 12:18:37 -08:00
|
|
|
>,
|
|
|
|
> {
|
|
|
|
Box::pin(import(args))
|
|
|
|
}
|
|
|
|
|
|
|
|
impl crate::docs::StdLibFn for Import {
|
|
|
|
fn name(&self) -> String {
|
|
|
|
"import".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn summary(&self) -> String {
|
2024-03-13 12:56:46 -07:00
|
|
|
"This is some function.".to_string()
|
2024-02-12 12:18:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn description(&self) -> String {
|
2024-03-13 12:56:46 -07:00
|
|
|
"It does shit.".to_string()
|
2024-02-12 12:18:37 -08: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_: "kittycad::types::InputFormat".to_string(),
|
|
|
|
schema: <Option<kittycad::types::InputFormat>>::json_schema(&mut generator),
|
2024-03-07 12:35:56 -08:00
|
|
|
required: false,
|
2024-02-12 12:18:37 -08:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn return_value(&self) -> Option<crate::docs::StdLibFnArg> {
|
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
|
|
|
settings.inline_subschemas = true;
|
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
|
|
|
Some(crate::docs::StdLibFnArg {
|
|
|
|
name: "".to_string(),
|
|
|
|
type_: "number".to_string(),
|
2024-03-12 12:54:45 -07:00
|
|
|
schema: <f64>::json_schema(&mut generator),
|
2024-02-12 12:18:37 -08:00
|
|
|
required: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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 code.\nIt does other shit.\nimport"];
|
|
|
|
code_blocks
|
|
|
|
.iter()
|
|
|
|
.map(|cb| {
|
2024-04-15 17:18:32 -07:00
|
|
|
let tokens = crate::token::lexer(cb).unwrap();
|
2024-03-13 12:56:46 -07:00
|
|
|
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>>()
|
|
|
|
}
|
|
|
|
|
2024-02-12 12:18:37 -08:00
|
|
|
fn std_lib_fn(&self) -> crate::std::StdFn {
|
|
|
|
boxed_import
|
|
|
|
}
|
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
|
|
|
Box::new(self.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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" import"]
|
2024-02-12 12:18:37 -08:00
|
|
|
fn inner_import(
|
|
|
|
#[doc = r" The args to do shit to."] args: Option<kittycad::types::InputFormat>,
|
2024-03-12 12:54:45 -07:00
|
|
|
) -> Result<Box<f64>> {
|
2024-02-12 12:18:37 -08:00
|
|
|
args
|
|
|
|
}
|