2024-03-13 12:56:46 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_examples_line_to {
|
2024-05-15 10:17:29 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_mock_example_line_to0() {
|
2024-11-07 11:23:41 -05:00
|
|
|
let program =
|
2024-11-20 15:19:25 +13:00
|
|
|
crate::Program::parse("This is another code block.\nyes sirrr.\nlineTo").unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
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(),
|
2024-10-01 12:45:01 -07:00
|
|
|
context_type: crate::executor::ContextType::Mock,
|
2024-05-15 10:17:29 -07:00
|
|
|
};
|
2024-11-20 15:19:25 +13:00
|
|
|
ctx.run(&program, &mut crate::ExecState::default())
|
|
|
|
.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_line_to0() {
|
2024-07-31 09:54:46 -05:00
|
|
|
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();
|
2024-03-26 21:28:50 -07:00
|
|
|
twenty_twenty::assert_image(
|
|
|
|
&format!("tests/outputs/{}.png", "serial_test_example_line_to0"),
|
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-05-15 10:17:29 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_mock_example_line_to1() {
|
2024-11-20 15:19:25 +13:00
|
|
|
let program = crate::Program::parse("This is code.\nIt does other shit.\nlineTo").unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
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(),
|
2024-10-01 12:45:01 -07:00
|
|
|
context_type: crate::executor::ContextType::Mock,
|
2024-05-15 10:17:29 -07:00
|
|
|
};
|
2024-11-20 15:19:25 +13:00
|
|
|
ctx.run(&program, &mut crate::ExecState::default())
|
|
|
|
.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_line_to1() {
|
2024-07-31 09:54:46 -05:00
|
|
|
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();
|
2024-03-26 21:28:50 -07:00
|
|
|
twenty_twenty::assert_image(
|
|
|
|
&format!("tests/outputs/{}.png", "serial_test_example_line_to1"),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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: lineTo\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 LineTo {}
|
|
|
|
|
|
|
|
#[allow(non_upper_case_globals, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: lineTo\nThis is some function.\nIt does shit."]
|
2023-08-25 13:41:04 -07:00
|
|
|
pub(crate) const LineTo: LineTo = LineTo {};
|
2023-09-20 18:27:08 -07:00
|
|
|
fn boxed_line_to(
|
2024-09-16 15:10:33 -04:00
|
|
|
exec_state: &mut crate::executor::ExecState,
|
2023-09-20 18:27:08 -07:00
|
|
|
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-09-16 15:10:33 -04:00
|
|
|
> + Send
|
|
|
|
+ '_,
|
2023-09-20 18:27:08 -07:00
|
|
|
>,
|
|
|
|
> {
|
2024-09-16 15:10:33 -04:00
|
|
|
Box::pin(line_to(exec_state, args))
|
2023-09-20 18:27:08 -07:00
|
|
|
}
|
|
|
|
|
2023-08-25 13:41:04 -07:00
|
|
|
impl crate::docs::StdLibFn for LineTo {
|
|
|
|
fn name(&self) -> String {
|
|
|
|
"lineTo".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![]
|
|
|
|
}
|
|
|
|
|
2024-12-05 14:27:51 -06:00
|
|
|
fn keyword_arguments(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2024-09-28 11:51:08 -07:00
|
|
|
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
|
2023-08-25 13:41:04 -07:00
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
2024-09-28 11:51:08 -07:00
|
|
|
settings.inline_subschemas = inline_subschemas;
|
2023-08-25 13:41:04 -07:00
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
|
|
|
vec![
|
|
|
|
crate::docs::StdLibFnArg {
|
|
|
|
name: "data".to_string(),
|
|
|
|
type_: "LineToData".to_string(),
|
2024-09-30 12:30:22 -07:00
|
|
|
schema: generator.root_schema_for::<LineToData>(),
|
2023-08-25 13:41:04 -07:00
|
|
|
required: true,
|
2024-12-05 14:27:51 -06:00
|
|
|
label_required: true,
|
2023-08-25 13:41:04 -07:00
|
|
|
},
|
|
|
|
crate::docs::StdLibFnArg {
|
2024-09-27 15:44:44 -07:00
|
|
|
name: "sketch".to_string(),
|
|
|
|
type_: "Sketch".to_string(),
|
2024-09-30 12:30:22 -07:00
|
|
|
schema: generator.root_schema_for::<Sketch>(),
|
2023-08-25 13:41:04 -07:00
|
|
|
required: true,
|
2024-12-05 14:27:51 -06:00
|
|
|
label_required: true,
|
2023-08-25 13:41:04 -07:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2024-09-28 11:51:08 -07:00
|
|
|
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
|
2023-08-25 13:41:04 -07:00
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
2024-09-28 11:51:08 -07:00
|
|
|
settings.inline_subschemas = inline_subschemas;
|
2023-08-25 13:41:04 -07:00
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
2024-09-30 12:30:22 -07:00
|
|
|
let schema = generator.root_schema_for::<Sketch>();
|
2023-09-05 16:02:27 -07:00
|
|
|
Some(crate::docs::StdLibFnArg {
|
2023-08-25 13:41:04 -07:00
|
|
|
name: "".to_string(),
|
2024-09-27 15:44:44 -07:00
|
|
|
type_: "Sketch".to_string(),
|
2024-09-28 11:51:08 -07:00
|
|
|
schema,
|
2023-08-25 13:41:04 -07:00
|
|
|
required: true,
|
2024-12-05 14:27:51 -06:00
|
|
|
label_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.\nlineTo",
|
|
|
|
"This is code.\nIt does other shit.\nlineTo",
|
|
|
|
];
|
|
|
|
code_blocks
|
|
|
|
.iter()
|
|
|
|
.map(|cb| {
|
2024-11-20 15:19:25 +13:00
|
|
|
let program = crate::Program::parse(cb).unwrap();
|
2024-12-05 17:56:49 +13:00
|
|
|
let mut options: crate::parsing::ast::types::FormatOptions = Default::default();
|
2024-03-13 12:56:46 -07:00
|
|
|
options.insert_final_newline = false;
|
2024-11-20 15:19:25 +13:00
|
|
|
program.ast.recast(&options, 0)
|
2024-03-13 12:56:46 -07:00
|
|
|
})
|
|
|
|
.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_line_to
|
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" lineTo"]
|
|
|
|
#[doc = r""]
|
|
|
|
#[doc = r" ```"]
|
|
|
|
#[doc = r" This is another code block."]
|
|
|
|
#[doc = r" yes sirrr."]
|
|
|
|
#[doc = r" lineTo"]
|
|
|
|
#[doc = r" ```"]
|
2024-09-27 15:44:44 -07:00
|
|
|
fn inner_line_to(data: LineToData, sketch: Sketch, args: &Args) -> Result<Sketch, KclError> {
|
2023-08-25 13:41:04 -07:00
|
|
|
Ok(())
|
|
|
|
}
|