#[cfg(test)] mod test_examples_line_to { #[tokio::test(flavor = "multi_thread")] async fn test_mock_example_line_to0() { let tokens = crate::token::lexer("This is another code block.\nyes sirrr.\nlineTo").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, }; ctx.run(&program, None).await.unwrap(); } #[tokio::test(flavor = "multi_thread", worker_threads = 5)] async fn kcl_test_example_line_to0() { let code = "This is another code block.\nyes sirrr.\nlineTo"; let result = crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm) .await .unwrap(); twenty_twenty::assert_image( &format!("tests/outputs/{}.png", "serial_test_example_line_to0"), &result, 0.99, ); } #[tokio::test(flavor = "multi_thread")] async fn test_mock_example_line_to1() { let tokens = crate::token::lexer("This is code.\nIt does other shit.\nlineTo").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, }; ctx.run(&program, None).await.unwrap(); } #[tokio::test(flavor = "multi_thread", worker_threads = 5)] async fn kcl_test_example_line_to1() { let code = "This is code.\nIt does other shit.\nlineTo"; let result = crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm) .await .unwrap(); twenty_twenty::assert_image( &format!("tests/outputs/{}.png", "serial_test_example_line_to1"), &result, 0.99, ); } } #[allow(non_camel_case_types, missing_docs)] #[doc = "Std lib function: lineTo\nThis is some function.\nIt does shit."] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, schemars :: JsonSchema, ts_rs :: TS)] #[ts(export)] pub(crate) struct LineTo {} #[allow(non_upper_case_globals, missing_docs)] #[doc = "Std lib function: lineTo\nThis is some function.\nIt does shit."] pub(crate) const LineTo: LineTo = LineTo {}; fn boxed_line_to( exec_state: &mut crate::executor::ExecState, args: crate::std::Args, ) -> std::pin::Pin< Box< dyn std::future::Future< Output = anyhow::Result, > + Send + '_, >, > { Box::pin(line_to(exec_state, args)) } impl crate::docs::StdLibFn for LineTo { fn name(&self) -> String { "lineTo".to_string() } fn summary(&self) -> String { "This is some function.".to_string() } fn description(&self) -> String { "It does shit.".to_string() } fn tags(&self) -> Vec { vec![] } fn args(&self, inline_subschemas: bool) -> Vec { let mut settings = schemars::gen::SchemaSettings::openapi3(); settings.inline_subschemas = inline_subschemas; let mut generator = schemars::gen::SchemaGenerator::new(settings); vec![ crate::docs::StdLibFnArg { name: "data".to_string(), type_: "LineToData".to_string(), schema: LineToData::json_schema(&mut generator), schema_definitions: generator.definitions().clone(), required: true, }, crate::docs::StdLibFnArg { name: "sketch".to_string(), type_: "Sketch".to_string(), schema: Sketch::json_schema(&mut generator), schema_definitions: generator.definitions().clone(), required: true, }, ] } fn return_value(&self, inline_subschemas: bool) -> Option { let mut settings = schemars::gen::SchemaSettings::openapi3(); settings.inline_subschemas = inline_subschemas; let mut generator = schemars::gen::SchemaGenerator::new(settings); let schema = ::json_schema(&mut generator); Some(crate::docs::StdLibFnArg { name: "".to_string(), type_: "Sketch".to_string(), schema, schema_definitions: generator.definitions().clone(), required: true, }) } fn unpublished(&self) -> bool { false } fn deprecated(&self) -> bool { false } fn examples(&self) -> Vec { let code_blocks = vec![ "This is another code block.\nyes sirrr.\nlineTo", "This is code.\nIt does other shit.\nlineTo", ]; code_blocks .iter() .map(|cb| { let tokens = crate::token::lexer(cb).unwrap(); 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::>() } fn std_lib_fn(&self) -> crate::std::StdFn { boxed_line_to } fn clone_box(&self) -> Box { Box::new(self.clone()) } } #[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" lineTo"] #[doc = r""] #[doc = r" ```"] #[doc = r" This is another code block."] #[doc = r" yes sirrr."] #[doc = r" lineTo"] #[doc = r" ```"] fn inner_line_to(data: LineToData, sketch: Sketch, args: &Args) -> Result { Ok(()) }