2024-07-31 09:54:46 -05:00
use kcl_lib ::{ settings ::types ::UnitLength , test_server ::execute_and_snapshot } ;
2023-09-12 14:59:40 -07:00
2024-07-15 17:41:41 -05:00
/// The minimum permissible difference between asserted twenty-twenty images.
/// i.e. how different the current model snapshot can be from the previous saved one.
const MIN_DIFF : f64 = 0.99 ;
2024-08-05 21:44:49 -05:00
mod no_visuals ;
2024-08-12 18:18:44 -05:00
mod visuals ;
2024-06-06 16:01:41 -05:00
2024-07-30 11:14:37 -05:00
macro_rules ! kcl_input {
( $file :literal ) = > {
include_str! ( concat! ( " inputs/ " , $file , " .kcl " ) )
} ;
}
fn assert_out ( test_name : & str , result : & image ::DynamicImage ) {
twenty_twenty ::assert_image ( format! ( " tests/executor/outputs/ {test_name} .png " ) , result , MIN_DIFF ) ;
}
2024-03-05 11:52:45 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_fillet_duplicate_tags ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " fillet_duplicate_tags " ) ;
2024-03-05 11:52:45 -08:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-03-05 11:52:45 -08:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-07-27 17:59:41 -07:00
r # "type: KclErrorDetails { source_ranges: [SourceRange([203, 249])], message: "Duplicate tags are not allowed." }"# ,
2024-03-05 11:52:45 -08:00
) ;
}
2023-09-12 14:59:40 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_with_function_sketch ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " function_sketch " ) ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " function_sketch " , & result ) ;
2023-09-12 14:59:40 -07:00
}
2023-09-19 14:20:14 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_with_function_sketch_with_position ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " function_sketch_with_position " ) ;
2023-09-19 14:20:14 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " function_sketch_with_position " , & result ) ;
2023-09-19 14:20:14 -07:00
}
2023-09-12 14:59:40 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_with_angled_line ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " angled_line " ) ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " angled_line " , & result ) ;
2023-09-12 14:59:40 -07:00
}
2023-09-15 20:45:28 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_parametric_example ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " parametric " ) ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " parametric " , & result ) ;
2023-09-15 20:45:28 -07:00
}
2023-09-18 17:31:11 -07:00
2023-10-02 16:14:09 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_parametric_with_tan_arc_example ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " parametric_with_tan_arc " ) ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " parametric_with_tan_arc " , & result ) ;
2023-10-02 16:14:09 -07:00
}
2023-09-18 17:31:11 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_engine_error_return ( ) {
2023-10-05 14:27:48 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 5.5229 , 5.25217 ] , % )
2023-09-18 17:31:11 -07:00
| > line ( [ 10.50433 , - 1.19122 ] , % )
| > line ( [ 8.01362 , - 5.48731 ] , % )
| > line ( [ - 1.02877 , - 6.76825 ] , % )
| > line ( [ - 11.53311 , 2.81559 ] , % )
| > extrude ( 4 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2023-09-18 17:31:11 -07:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-06-19 13:57:50 -07:00
r # "engine: KclErrorDetails { source_ranges: [SourceRange([222, 235])], message: "Modeling command failed: [ApiError { error_code: BadRequest, message: \"The path is not closed. Solid2D construction requires a closed path!\" }]" }"# ,
2023-09-18 17:31:11 -07:00
) ;
}
2023-09-19 14:20:14 -07:00
2024-03-27 09:46:13 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_i_shape ( ) {
2024-03-27 09:46:13 -07:00
// This is some code from lee that starts a pipe expression with a variable.
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " i_shape " ) ;
2024-03-27 09:46:13 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " i_shape " , & result ) ;
2024-03-27 09:46:13 -07:00
}
2023-09-19 14:20:14 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-03-28 13:11:09 -05:00
#[ ignore ] // No longer a stack overflow problem, instead it causes an engine internal error.
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_pipes_on_pipes ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " pipes_on_pipes " ) ;
2023-09-19 14:20:14 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " pipes_on_pipes " , & result ) ;
2023-09-19 14:20:14 -07:00
}
2023-09-19 16:05:53 -07:00
2023-11-08 15:06:41 -06:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_cylinder ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " cylinder " ) ;
2023-11-08 15:06:41 -06:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cylinder " , & result ) ;
2023-11-08 15:06:41 -06:00
}
2023-09-20 19:35:37 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_execute_kittycad_svg ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " kittycad_svg " ) ;
2023-09-20 19:35:37 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " kittycad_svg " , & result ) ;
2023-09-20 19:35:37 -07:00
}
2023-09-19 16:05:53 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_member_expression_sketch_group ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " member_expression_sketch_group " ) ;
2023-09-19 16:05:53 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " member_expression_sketch_group " , & result ) ;
2023-09-19 16:05:53 -07:00
}
2023-09-25 12:14:41 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_helix_defaults ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " helix_defaults " ) ;
2024-03-25 17:07:53 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " helix_defaults " , & result ) ;
2024-03-25 17:07:53 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_helix_defaults_negative_extrude ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " helix_defaults_negative_extrude " ) ;
2024-03-25 17:07:53 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " helix_defaults_negative_extrude " , & result ) ;
2024-03-25 17:07:53 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_helix_ccw ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " helix_ccw " ) ;
2024-03-25 17:07:53 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " helix_ccw " , & result ) ;
2024-03-25 17:07:53 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_helix_with_length ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " helix_with_length " ) ;
2024-03-25 17:07:53 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " helix_with_length " , & result ) ;
2024-03-25 17:07:53 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_dimensions_match ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " dimensions_match " ) ;
2024-03-25 17:07:53 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " dimensions_match " , & result ) ;
2024-03-25 17:07:53 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_close_arc ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " close_arc " ) ;
2023-09-25 12:14:41 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " close_arc " , & result ) ;
2023-09-25 12:14:41 -07:00
}
2023-09-25 15:25:58 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_negative_args ( ) {
2024-07-31 15:07:56 -05:00
let code = kcl_input! ( " negative_args " ) ;
2023-09-25 15:25:58 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " negative_args " , & result ) ;
2023-09-25 15:25:58 -07:00
}
2023-09-29 14:41:14 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_basic_tangential_arc_with_point ( ) {
2023-09-29 14:41:14 -07:00
let code = r #" const boxSketch = startSketchAt([0, 0])
| > line ( [ 0 , 10 ] , % )
2024-08-30 13:44:20 -05:00
| > tangentialArcToRelative ( [ - 5 , 5 ] , % )
2023-09-29 14:41:14 -07:00
| > line ( [ 5 , - 15 ] , % )
| > extrude ( 10 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " tangential_arc_with_point " , & result ) ;
2023-09-29 14:41:14 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_basic_tangential_arc_to ( ) {
2023-09-29 14:41:14 -07:00
let code = r #" const boxSketch = startSketchAt([0, 0])
| > line ( [ 0 , 10 ] , % )
2023-10-12 11:50:54 -05:00
| > tangentialArcTo ( [ - 5 , 15 ] , % )
2023-09-29 14:41:14 -07:00
| > line ( [ 5 , - 15 ] , % )
| > extrude ( 10 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " tangential_arc_to " , & result ) ;
2023-09-29 14:41:14 -07:00
}
2023-10-05 14:27:48 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_different_planes_same_drawing ( ) {
2023-10-05 14:27:48 -07:00
let code = r #" const width = 5
const height = 10
const length = 12
fn box = ( sk1 , sk2 , scale , plane ) = > {
const boxsketch = startSketchOn ( plane )
| > startProfileAt ( [ sk1 , sk2 ] , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return boxsketch
}
box ( 0 , 0 , 5 , ' xy ' )
box ( 10 , 23 , 8 , ' xz ' )
box ( 30 , 43 , 18 , ' - xy ' )
let thing = box ( - 12 , - 15 , 10 , ' yz ' )
box ( - 20 , - 5 , 10 , ' xy ' ) " #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " different_planes_same_drawing " , & result ) ;
2023-10-05 14:27:48 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_lots_of_planes ( ) {
2023-10-05 14:27:48 -07:00
let code = r #" const sigmaAllow = 15000 // psi
const width = 11 // inch
const p = 150 // Force on shelf - lbs
const distance = 12 // inches
const FOS = 2
const thickness = sqrt ( distance * p * FOS * 6 / ( sigmaAllow * width ) )
const filletR = thickness * 2
const shelfMountL = 9
const wallMountL = 8
const bracket = startSketchOn ( ' XY ' )
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , wallMountL ] , % )
2023-10-12 11:50:54 -05:00
| > tangentialArc ( { radius : filletR , offset : 90 } , % )
2023-10-05 14:27:48 -07:00
| > line ( [ - shelfMountL , 0 ] , % )
| > line ( [ 0 , - thickness ] , % )
| > line ( [ shelfMountL , 0 ] , % )
2023-10-12 11:50:54 -05:00
| > tangentialArc ( {
2023-10-05 14:27:48 -07:00
radius : filletR - thickness ,
offset : - 90
} , % )
| > line ( [ 0 , - wallMountL ] , % )
| > close ( % )
| > extrude ( width , % )
const part001 = startSketchOn ( ' XY ' )
| > startProfileAt ( [ - 15.53 , - 10.28 ] , % )
| > line ( [ 10.49 , - 2.08 ] , % )
| > line ( [ 10.42 , 8.47 ] , % )
| > line ( [ - 19.16 , 5.1 ] , % )
| > close ( % )
| > extrude ( 4 , % )
const part002 = startSketchOn ( ' - XZ ' )
| > startProfileAt ( [ - 9.35 , 19.18 ] , % )
| > line ( [ 32.14 , - 2.47 ] , % )
| > line ( [ 8.39 , - 3.73 ] , % )
| > close ( % )
const part003 = startSketchOn ( ' - XZ ' )
| > startProfileAt ( [ 13.82 , 16.51 ] , % )
| > line ( [ - 6.24 , - 30.82 ] , % )
| > line ( [ 8.39 , - 3.73 ] , % )
| > close ( % )
const part004 = startSketchOn ( ' YZ ' )
| > startProfileAt ( [ 19.04 , 20.22 ] , % )
| > line ( [ 9.44 , - 30.16 ] , % )
| > line ( [ 8.39 , - 3.73 ] , % )
| > close ( % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " lots_of_planes " , & result ) ;
2023-10-05 14:27:48 -07:00
}
2023-10-13 12:02:46 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_holes ( ) {
2024-03-01 14:23:30 -08:00
let code = r #" const square = startSketchOn('XY')
2023-10-13 12:02:46 -07:00
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ 10 , 0 ] , % )
| > line ( [ 0 , - 10 ] , % )
| > close ( % )
2024-09-23 22:42:51 +10:00
| > hole ( circle ( { center : [ 2 , 2 ] , radius : . 5 } , % ) , % )
| > hole ( circle ( { center : [ 2 , 8 ] , radius : . 5 } , % ) , % )
2023-10-13 12:02:46 -07:00
| > extrude ( 2 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " holes " , & result ) ;
2023-10-13 12:02:46 -07:00
}
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
#[ tokio::test(flavor = " multi_thread " ) ]
async fn optional_params ( ) {
let code = r #"
2024-03-01 14:23:30 -08:00
fn other_circle = ( pos , radius , tag ? ) = > {
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > arc ( { angle_end : 360 , angle_start : 0 , radius : radius } , % )
| > close ( % )
2024-04-25 02:31:18 -07:00
| > extrude ( 2 , % )
2024-02-11 15:08:54 -08:00
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
return sg
}
2024-02-11 15:08:54 -08:00
2024-03-01 14:23:30 -08:00
const thing = other_circle ( [ 2 , 2 ] , 20 )
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " optional_params " , & result ) ;
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
}
2023-10-13 12:02:46 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_rounded_with_holes ( ) {
2024-03-01 14:23:30 -08:00
let code = r #" fn tarc = (to, sketchGroup, tag?) => {
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
return tangentialArcTo ( to , sketchGroup , tag )
}
2023-10-13 12:02:46 -07:00
fn roundedRectangle = ( pos , w , l , cornerRadius ) = > {
const rr = startSketchOn ( ' XY ' )
| > startProfileAt ( [ pos [ 0 ] - w / 2 , 0 ] , % )
| > lineTo ( [ pos [ 0 ] - w / 2 , pos [ 1 ] - l / 2 + cornerRadius ] , % )
2024-06-24 14:45:07 -07:00
| > tarc ( [ pos [ 0 ] - w / 2 + cornerRadius , pos [ 1 ] - l / 2 ] , % , $arc0 )
2023-10-13 12:02:46 -07:00
| > lineTo ( [ pos [ 0 ] + w / 2 - cornerRadius , pos [ 1 ] - l / 2 ] , % )
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
| > tarc ( [ pos [ 0 ] + w / 2 , pos [ 1 ] - l / 2 + cornerRadius ] , % )
2023-10-13 12:02:46 -07:00
| > lineTo ( [ pos [ 0 ] + w / 2 , pos [ 1 ] + l / 2 - cornerRadius ] , % )
2024-06-24 14:45:07 -07:00
| > tarc ( [ pos [ 0 ] + w / 2 - cornerRadius , pos [ 1 ] + l / 2 ] , % , $arc2 )
2023-10-13 12:02:46 -07:00
| > lineTo ( [ pos [ 0 ] - w / 2 + cornerRadius , pos [ 1 ] + l / 2 ] , % )
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
| > tarc ( [ pos [ 0 ] - w / 2 , pos [ 1 ] + l / 2 - cornerRadius ] , % )
2023-10-13 12:02:46 -07:00
| > close ( % )
return rr
}
const holeRadius = 1
const holeIndex = 6
const part = roundedRectangle ( [ 0 , 0 ] , 20 , 20 , 4 )
2024-09-23 22:42:51 +10:00
| > hole ( circle ( { center : [ - holeIndex , holeIndex ] , radius : holeRadius } , % ) , % )
| > hole ( circle ( { center : [ holeIndex , holeIndex ] , radius : holeRadius } , % ) , % )
| > hole ( circle ( { center : [ - holeIndex , - holeIndex ] , radius : holeRadius } , % ) , % )
| > hole ( circle ( { center : [ holeIndex , - holeIndex ] , radius : holeRadius } , % ) , % )
2023-10-13 12:02:46 -07:00
| > extrude ( 2 , % )
2024-02-20 17:55:06 -08:00
" #;
2023-10-13 12:02:46 -07:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " rounded_with_holes " , & result ) ;
2023-10-13 12:02:46 -07:00
}
2023-11-09 13:08:11 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_top_level_expression ( ) {
2024-09-23 22:42:51 +10:00
let code = r # "startSketchOn('XY') |> circle({ center: [0,0], radius: 22 }, %) |> extrude(14, %)"# ;
2023-11-09 13:08:11 -08:00
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " top_level_expression " , & result ) ;
2023-11-09 13:08:11 -08:00
}
2024-02-11 15:08:54 -08:00
2024-04-23 15:59:12 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_linear_basic_with_math ( ) {
2024-04-23 15:59:12 -07:00
let code = r #" const num = 12
const distance = 5
const part = startSketchOn ( ' XY ' )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : 2 } , % )
2024-04-23 15:59:12 -07:00
| > patternLinear2d ( { axis : [ 0 , 1 ] , repetitions : num - 1 , distance : distance - 1 } , % )
| > extrude ( 1 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_linear_basic_with_math " , & result ) ;
2024-04-23 15:59:12 -07:00
}
2024-02-11 15:08:54 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_linear_basic ( ) {
2024-03-07 14:53:37 -08:00
let code = r #" const part = startSketchOn('XY')
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : 2 } , % )
2024-04-23 15:59:12 -07:00
| > patternLinear2d ( { axis : [ 0 , 1 ] , repetitions : 12 , distance : 4 } , % )
| > extrude ( 1 , % )
2024-02-11 15:08:54 -08:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_linear_basic " , & result ) ;
2024-02-11 15:08:54 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_linear_basic_3d ( ) {
2024-03-01 14:23:30 -08:00
let code = r #" const part = startSketchOn('XY')
2024-02-11 15:08:54 -08:00
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 1 ] , % )
| > line ( [ 1 , 0 ] , % )
| > line ( [ 0 , - 1 ] , % )
| > close ( % )
| > extrude ( 1 , % )
2024-03-12 12:54:45 -07:00
| > patternLinear3d ( { axis : [ 1 , 0 , 1 ] , repetitions : 3 , distance : 6 } , % )
2024-02-11 15:08:54 -08:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_linear_basic_3d " , & result ) ;
2024-02-11 15:08:54 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_linear_basic_negative_distance ( ) {
2024-03-07 14:53:37 -08:00
let code = r #" const part = startSketchOn('XY')
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : 2 } , % )
2024-03-12 12:54:45 -07:00
| > patternLinear2d ( { axis : [ 0 , 1 ] , repetitions : 12 , distance : - 2 } , % )
2024-04-25 02:31:18 -07:00
| > extrude ( 1 , % )
2024-02-11 15:08:54 -08:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_linear_basic_negative_distance " , & result ) ;
2024-02-11 15:08:54 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_linear_basic_negative_axis ( ) {
2024-03-07 14:53:37 -08:00
let code = r #" const part = startSketchOn('XY')
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : 2 } , % )
2024-03-12 12:54:45 -07:00
| > patternLinear2d ( { axis : [ 0 , - 1 ] , repetitions : 12 , distance : 2 } , % )
2024-04-25 02:31:18 -07:00
| > extrude ( 1 , % )
2024-02-11 15:08:54 -08:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_linear_basic_negative_axis " , & result ) ;
2024-02-11 15:08:54 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_linear_basic_holes ( ) {
2024-03-07 14:53:37 -08:00
let code = r #" const circles = startSketchOn('XY')
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 5 , 5 ] , radius : 1 } , % )
2024-03-12 12:54:45 -07:00
| > patternLinear2d ( { axis : [ 1 , 1 ] , repetitions : 12 , distance : 3 } , % )
2024-02-11 15:08:54 -08:00
const rectangle = startSketchOn ( ' XY ' )
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 50 ] , % )
| > line ( [ 50 , 0 ] , % )
| > line ( [ 0 , - 50 ] , % )
| > close ( % )
| > hole ( circles , % )
2024-04-25 02:31:18 -07:00
| > extrude ( 10 , % )
2024-02-11 15:08:54 -08:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_linear_basic_holes " , & result ) ;
2024-02-11 15:08:54 -08:00
}
2024-02-12 12:18:37 -08:00
2024-02-13 13:20:49 -06:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_circular_basic_2d ( ) {
2024-03-07 14:53:37 -08:00
let code = r #" const part = startSketchOn('XY')
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : 2 } , % )
2024-03-12 12:54:45 -07:00
| > patternCircular2d ( { center : [ 20 , 20 ] , repetitions : 12 , arcDegrees : 210 , rotateDuplicates : true } , % )
2024-04-25 02:31:18 -07:00
| > extrude ( 1 , % )
2024-02-13 13:20:49 -06:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_circular_basic_2d " , & result ) ;
2024-02-13 13:20:49 -06:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_circular_basic_3d ( ) {
2024-03-01 14:23:30 -08:00
let code = r #" const part = startSketchOn('XY')
2024-02-13 13:20:49 -06:00
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 1 ] , % )
| > line ( [ 1 , 0 ] , % )
| > line ( [ 0 , - 1 ] , % )
| > close ( % )
| > extrude ( 1 , % )
2024-03-12 12:54:45 -07:00
| > patternCircular3d ( { axis : [ 0 , 0 , 1 ] , center : [ - 20 , - 20 , - 20 ] , repetitions : 40 , arcDegrees : 360 , rotateDuplicates : false } , % )
2024-02-13 13:20:49 -06:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_circular_basic_3d " , & result ) ;
2024-02-13 13:20:49 -06:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_patterns_circular_3d_tilted_axis ( ) {
2024-03-01 14:23:30 -08:00
let code = r #" const part = startSketchOn('XY')
2024-02-13 13:20:49 -06:00
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 1 ] , % )
| > line ( [ 1 , 0 ] , % )
| > line ( [ 0 , - 1 ] , % )
| > close ( % )
| > extrude ( 1 , % )
2024-03-12 12:54:45 -07:00
| > patternCircular3d ( { axis : [ 1 , 1 , 0 ] , center : [ 10 , 0 , 10 ] , repetitions : 10 , arcDegrees : 360 , rotateDuplicates : true } , % )
2024-02-13 13:20:49 -06:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " patterns_circular_3d_tilted_axis " , & result ) ;
2024-02-13 13:20:49 -06:00
}
2024-02-12 12:18:37 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_file_doesnt_exist ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("thing.obj")"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-02-12 12:18:37 -08:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([14, 33])], message: "File `thing.obj` does not exist." }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_obj_with_mtl ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("tests/executor/inputs/cube.obj")"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_obj_with_mtl " , & result ) ;
2024-02-12 12:18:37 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_obj_with_mtl_units ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("tests/executor/inputs/cube.obj", {type: "obj", units: "m"})"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_obj_with_mtl_units " , & result ) ;
2024-02-12 12:18:37 -08:00
}
2024-07-17 15:55:59 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_stl ( ) {
2024-07-17 15:55:59 -07:00
let code = r # "const model = import("tests/executor/inputs/2-5-long-m8-chc-screw.stl")"# ;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_stl " , & result ) ;
2024-07-17 15:55:59 -07:00
}
2024-02-12 12:18:37 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_gltf_with_bin ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("tests/executor/inputs/cube.gltf")"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_gltf_with_bin " , & result ) ;
2024-02-12 12:18:37 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_gltf_embedded ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("tests/executor/inputs/cube-embedded.gltf")"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_gltf_embedded " , & result ) ;
2024-02-12 12:18:37 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_glb ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("tests/executor/inputs/cube.glb")"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_glb " , & result ) ;
2024-02-12 12:18:37 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_glb_no_assign ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "import("tests/executor/inputs/cube.glb")"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " import_glb_no_assign " , & result ) ;
2024-02-12 12:18:37 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_import_ext_doesnt_match ( ) {
2024-02-12 12:18:37 -08:00
let code = r # "const model = import("tests/executor/inputs/cube.gltf", {type: "obj", units: "m"})"# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-02-12 12:18:37 -08:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([14, 82])], message: "The given format does not match the file extension. Expected: `gltf`, Given: `obj`" }"#
) ;
}
2024-02-20 17:55:06 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_cube_mm ( ) {
2024-02-20 17:55:06 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return sg
}
const myCube = cube ( [ 0 , 0 ] , 10 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cube_mm " , & result ) ;
2024-02-20 17:55:06 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_cube_cm ( ) {
2024-02-20 17:55:06 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return sg
}
const myCube = cube ( [ 0 , 0 ] , 10 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Cm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cube_cm " , & result ) ;
2024-02-20 17:55:06 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_cube_m ( ) {
2024-02-20 17:55:06 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return sg
}
const myCube = cube ( [ 0 , 0 ] , 10 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::M ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cube_m " , & result ) ;
2024-02-20 17:55:06 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_cube_in ( ) {
2024-02-20 17:55:06 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return sg
}
const myCube = cube ( [ 0 , 0 ] , 10 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::In ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cube_in " , & result ) ;
2024-02-20 17:55:06 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_cube_ft ( ) {
2024-02-20 17:55:06 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return sg
}
const myCube = cube ( [ 0 , 0 ] , 10 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Ft ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cube_ft " , & result ) ;
2024-02-20 17:55:06 -08:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_cube_yd ( ) {
2024-02-20 17:55:06 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
| > close ( % )
| > extrude ( scale , % )
return sg
}
const myCube = cube ( [ 0 , 0 ] , 10 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Yd ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " cube_yd " , & result ) ;
2024-02-20 17:55:06 -08:00
}
2024-02-22 19:07:17 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_error_sketch_on_arc_face ( ) {
2024-02-22 19:07:17 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
2024-08-30 13:44:20 -05:00
| > tangentialArcToRelative ( [ 0 , scale ] , % , $here )
2024-02-22 19:07:17 -08:00
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
| > close ( % )
| > extrude ( 20 , % )
2024-07-27 17:59:41 -07:00
const part002 = startSketchOn ( part001 , part001 . sketchGroup . tags . here )
2024-02-22 19:07:17 -08:00
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 5 , 0 ] , % )
| > line ( [ 5 , 5 ] , % )
| > line ( [ 0 , 5 ] , % )
| > close ( % )
| > extrude ( 1 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-02-22 19:07:17 -08:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-08-30 13:44:20 -05:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([94, 139]), SourceRange([222, 238])], message: "could not sketch tangential arc, because its center would be infinitely far away in the X direction" }"#
2024-02-22 19:07:17 -08:00
) ;
}
2024-02-26 14:54:42 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_sketch_on_face_of_face ( ) {
2024-02-26 14:54:42 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
| > close ( % )
| > extrude ( 20 , % )
const part002 = startSketchOn ( part001 , " end " )
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ 10 , 0 ] , % )
| > line ( [ 0 , - 10 ] , % )
| > close ( % )
| > extrude ( 5 , % )
const part003 = startSketchOn ( part002 , " end " )
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 5 ] , % )
| > line ( [ 5 , 0 ] , % )
| > line ( [ 0 , - 5 ] , % )
| > close ( % )
| > extrude ( 5 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " sketch_on_face_of_face " , & result ) ;
2024-02-26 14:54:42 -08:00
}
2024-03-05 12:46:05 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_stdlib_kcl_error_right_code_path ( ) {
2024-03-05 12:46:05 -08:00
let code = r #" const square = startSketchOn('XY')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ 10 , 0 ] , % )
| > line ( [ 0 , - 10 ] , % )
| > close ( % )
2024-09-23 22:42:51 +10:00
| > hole ( circle ( { center : [ 2 , 2 ] , radius : . 5 } ) , % )
| > hole ( circle ( { center : [ 2 , 8 ] , radius : . 5 } , % ) , % )
2024-03-05 12:46:05 -08:00
| > extrude ( 2 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-03-05 12:46:05 -08:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-09-23 22:42:51 +10:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([157, 195])], message: "Expected an argument at index 1" }"# ,
2024-03-05 12:46:05 -08:00
) ;
}
2024-03-07 14:53:37 -08:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_sketch_on_face_circle ( ) {
2024-03-07 14:53:37 -08:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
| > close ( % )
| > extrude ( 20 , % )
const part002 = startSketchOn ( part001 , " end " )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : 5 } , % )
2024-03-07 14:53:37 -08:00
| > extrude ( 5 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " sketch_on_face_circle " , & result ) ;
2024-03-07 14:53:37 -08:00
}
2024-03-07 15:35:26 -08:00
2024-03-11 13:37:22 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_stdlib_kcl_error_circle ( ) {
2024-03-11 13:37:22 -07:00
let code = r #" // Mounting Plate
// A flat piece of material, often metal or plastic, that serves as a support or base for attaching, securing, or mounting various types of equipment, devices, or components.
// Create a function that defines the body width and length of the mounting plate. Tag the corners so they can be passed through the fillet function.
fn rectShape = ( pos , w , l ) = > {
const rr = startSketchOn ( ' XY ' )
| > startProfileAt ( [ pos [ 0 ] - ( w / 2 ) , pos [ 1 ] - ( l / 2 ) ] , % )
2024-07-27 17:59:41 -07:00
| > lineTo ( [ pos [ 0 ] + w / 2 , pos [ 1 ] - ( l / 2 ) ] , % , $edge1 )
| > lineTo ( [ pos [ 0 ] + w / 2 , pos [ 1 ] + l / 2 ] , % , $edge2 )
| > lineTo ( [ pos [ 0 ] - ( w / 2 ) , pos [ 1 ] + l / 2 ] , % , $edge3 )
| > close ( % , $edge4 )
2024-03-11 13:37:22 -07:00
return rr
}
// Define the hole radius and x, y location constants
const holeRadius = 1
const holeIndex = 6
// Create the mounting plate extrusion, holes, and fillets
const part = rectShape ( [ 0 , 0 ] , 20 , 20 )
| > hole ( circle ( ' XY ' , [ - holeIndex , holeIndex ] , holeRadius ) , % )
| > hole ( circle ( ' XY ' , [ holeIndex , holeIndex ] , holeRadius ) , % )
| > hole ( circle ( ' XY ' , [ - holeIndex , - holeIndex ] , holeRadius ) , % )
| > hole ( circle ( ' XY ' , [ holeIndex , - holeIndex ] , holeRadius ) , % )
| > extrude ( 2 , % )
| > fillet ( {
radius : 4 ,
tags : [
2024-07-27 22:56:46 -07:00
getNextAdjacentEdge ( edge1 ) ,
getNextAdjacentEdge ( edge2 ) ,
getNextAdjacentEdge ( edge3 ) ,
getNextAdjacentEdge ( edge4 )
2024-03-11 13:37:22 -07:00
]
} , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-03-11 13:37:22 -07:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-09-23 22:42:51 +10:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([887, 936])], message: "Argument at index 0 was supposed to be type kcl_lib::std::shapes::CircleData but found string (text)" }"# ,
2024-03-11 13:37:22 -07:00
) ;
}
2024-03-20 20:44:52 -07:00
2024-03-26 19:07:16 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_simple_revolve ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' y ' } , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " simple_revolve " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_simple_revolve_uppercase ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' Y ' } , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " simple_revolve_uppercase " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_simple_revolve_negative ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' - Y ' , angle : 180 } , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " simple_revolve_negative " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_bad_angle_low ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' y ' , angle : - 455 } , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-03-26 19:07:16 -07:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-09-26 16:33:49 -07:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([278, 314])], message: "Expected angle to be between -360 and 360 and not 0, found `-455`" }"#
2024-03-26 19:07:16 -07:00
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_bad_angle_high ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' y ' , angle : 455 } , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-03-26 19:07:16 -07:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-09-26 16:33:49 -07:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([278, 313])], message: "Expected angle to be between -360 and 360 and not 0, found `455`" }"#
2024-03-26 19:07:16 -07:00
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_simple_revolve_custom_angle ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' y ' , angle : 180 } , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " simple_revolve_custom_angle " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_simple_revolve_custom_axis ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
2024-09-25 16:12:18 -07:00
| > revolve ( { axis : { custom : { axis : [ 0 , - 1 ] , origin : [ 0 , 0 ] } } , angle : 180 } , % )
2024-03-26 19:07:16 -07:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " simple_revolve_custom_axis " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_on_edge ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const box = startSketchOn('XY')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ 10 , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - 10 ] , % , $revolveAxis )
2024-03-26 19:07:16 -07:00
| > close ( % )
| > extrude ( 10 , % )
const sketch001 = startSketchOn ( box , " end " )
| > startProfileAt ( [ 5 , 10 ] , % )
| > line ( [ 0 , - 10 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > close ( % )
2024-07-27 22:56:46 -07:00
| > revolve ( { axis : getOppositeEdge ( revolveAxis ) , angle : 90 } , % )
2024-03-26 19:07:16 -07:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " revolve_on_edge " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_on_edge_get_edge ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const box = startSketchOn('XY')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ 10 , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - 10 ] , % , $revolveAxis )
2024-03-26 19:07:16 -07:00
| > close ( % )
| > extrude ( 10 , % )
2024-07-27 17:59:41 -07:00
const sketch001 = startSketchOn ( box , revolveAxis )
2024-03-26 19:07:16 -07:00
| > startProfileAt ( [ 5 , 10 ] , % )
| > line ( [ 0 , - 10 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > close ( % )
2024-07-27 22:56:46 -07:00
| > revolve ( { axis : revolveAxis , angle : 90 } , % )
2024-03-26 19:07:16 -07:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-04-15 19:37:59 -07:00
assert! ( result . is_err ( ) ) ;
2024-08-29 15:27:00 -07:00
//this fails right now, but slightly differently, lets just say its enough for it to fail - mike
//assert_eq!(
// result.err().unwrap().to_string(),
// r#"engine: KclErrorDetails { source_ranges: [SourceRange([346, 390])], message: "Modeling command failed: [ApiError { error_code: InternalEngine, message: \"Solid3D revolve failed: sketch profile must lie entirely on one side of the revolution axis\" }]" }"#
//);
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_on_face_circle_edge ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const box = startSketchOn('XY')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 20 ] , % )
| > line ( [ 20 , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - 20 ] , % , $revolveAxis )
2024-03-26 19:07:16 -07:00
| > close ( % )
| > extrude ( 20 , % )
const sketch001 = startSketchOn ( box , " END " )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 10 , 10 ] , radius : 4 } , % )
2024-03-26 19:07:16 -07:00
| > revolve ( {
angle : 90 ,
2024-07-27 22:56:46 -07:00
axis : getOppositeEdge ( revolveAxis )
2024-03-26 19:07:16 -07:00
} , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " revolve_on_face_circle_edge " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_on_face_circle ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const box = startSketchOn('XY')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 20 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 20 , 0 ] , % , $revolveAxis )
2024-03-26 19:07:16 -07:00
| > line ( [ 0 , - 20 ] , % )
| > close ( % )
| > extrude ( 20 , % )
const sketch001 = startSketchOn ( box , " END " )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 10 , 10 ] , radius : 4 } , % )
2024-03-26 19:07:16 -07:00
| > revolve ( {
angle : - 90 ,
axis : ' y '
} , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " revolve_on_face_circle " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_revolve_on_face ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const box = startSketchOn('XY')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ 10 , 0 ] , % )
| > line ( [ 0 , - 10 ] , % )
2024-07-27 17:59:41 -07:00
| > close ( % , $revolveAxis )
2024-03-26 19:07:16 -07:00
| > extrude ( 10 , % )
const sketch001 = startSketchOn ( box , " end " )
| > startProfileAt ( [ 5 , 10 ] , % )
| > line ( [ 0 , - 10 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , 10 ] , % )
| > close ( % )
| > revolve ( {
axis : ' y ' ,
angle : - 90 ,
} , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " revolve_on_face " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_basic_revolve_circle ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const sketch001 = startSketchOn('XY')
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 15 , 0 ] , radius : 5 } , % )
2024-03-26 19:07:16 -07:00
| > revolve ( {
angle : 360 ,
axis : ' y '
} , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " basic_revolve_circle " , & result ) ;
2024-03-26 19:07:16 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_simple_revolve_sketch_on_edge ( ) {
2024-03-26 19:07:16 -07:00
let code = r #" const part001 = startSketchOn('XY')
| > startProfileAt ( [ 4 , 12 ] , % )
| > line ( [ 2 , 0 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ 4 , - 6 ] , % )
| > line ( [ 0 , - 6 ] , % )
| > line ( [ - 3.75 , - 4.5 ] , % )
| > line ( [ 0 , - 5.5 ] , % )
| > line ( [ - 2 , 0 ] , % )
| > close ( % )
| > revolve ( { axis : ' y ' , angle : 180 } , % )
const part002 = startSketchOn ( part001 , ' end ' )
| > startProfileAt ( [ 4.5 , - 5 ] , % )
| > line ( [ 0 , 5 ] , % )
| > line ( [ 5 , 0 ] , % )
| > line ( [ 0 , - 5 ] , % )
| > close ( % )
| > extrude ( 5 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " simple_revolve_sketch_on_edge " , & result ) ;
2024-03-26 19:07:16 -07:00
}
2024-03-29 15:06:11 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_plumbus_fillets ( ) {
2024-07-22 19:43:40 -04:00
let code = r #" fn make_circle = (ext, face, pos, radius) => {
2024-06-24 22:39:04 -07:00
const sg = startSketchOn ( ext , face )
2024-03-29 15:06:11 -07:00
| > startProfileAt ( [ pos [ 0 ] + radius , pos [ 1 ] ] , % )
| > arc ( {
angle_end : 360 ,
angle_start : 0 ,
radius : radius
2024-07-22 19:43:40 -04:00
} , % , $arc1 )
2024-03-29 15:06:11 -07:00
| > close ( % )
return sg
}
2024-07-22 19:43:40 -04:00
fn pentagon = ( len ) = > {
2024-03-29 15:06:11 -07:00
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( [ - len / 2 , - len / 2 ] , % )
2024-07-22 19:43:40 -04:00
| > angledLine ( { angle : 0 , length : len } , % , $a )
2024-03-29 15:06:11 -07:00
| > angledLine ( {
2024-07-27 22:56:46 -07:00
angle : segAng ( a ) + 180 - 108 ,
2024-03-29 15:06:11 -07:00
length : len
2024-07-22 19:43:40 -04:00
} , % , $b )
2024-03-29 15:06:11 -07:00
| > angledLine ( {
2024-07-27 22:56:46 -07:00
angle : segAng ( b ) + 180 - 108 ,
2024-03-29 15:06:11 -07:00
length : len
2024-07-22 19:43:40 -04:00
} , % , $c )
2024-03-29 15:06:11 -07:00
| > angledLine ( {
2024-07-27 22:56:46 -07:00
angle : segAng ( c ) + 180 - 108 ,
2024-03-29 15:06:11 -07:00
length : len
2024-06-24 22:39:04 -07:00
} , % , $d )
2024-03-29 15:06:11 -07:00
| > angledLine ( {
2024-07-27 22:56:46 -07:00
angle : segAng ( d ) + 180 - 108 ,
2024-03-29 15:06:11 -07:00
length : len
} , % )
return sg
}
2024-07-22 19:43:40 -04:00
const p = pentagon ( 32 )
2024-04-03 16:42:58 -05:00
| > extrude ( 10 , % )
2024-03-29 15:06:11 -07:00
2024-07-22 19:43:40 -04:00
const circle0 = make_circle ( p , p . sketchGroup . tags . a , [ 0 , 0 ] , 2.5 )
const plumbus0 = circle0
2024-04-03 16:42:58 -05:00
| > extrude ( 10 , % )
2024-03-29 15:06:11 -07:00
| > fillet ( {
radius : 0.5 ,
2024-07-29 21:30:25 -07:00
tags : [ circle0 . tags . arc1 , getOppositeEdge ( circle0 . tags . arc1 ) ]
2024-03-29 15:06:11 -07:00
} , % )
2024-07-22 19:43:40 -04:00
const circle1 = make_circle ( p , p . sketchGroup . tags . b , [ 0 , 0 ] , 2.5 )
const plumbus1 = circle1
2024-05-22 18:50:54 -05:00
| > extrude ( 10 , % )
| > fillet ( {
radius : 0.5 ,
2024-07-29 21:30:25 -07:00
tags : [ circle1 . tags . arc1 , getOppositeEdge ( circle1 . tags . arc1 ) ]
2024-05-22 18:50:54 -05:00
} , % )
2024-03-29 15:06:11 -07:00
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " plumbus_fillets " , & result ) ;
2024-03-29 15:06:11 -07:00
}
2024-04-02 18:28:50 -07:00
2024-04-15 17:18:32 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_empty_file_is_ok ( ) {
2024-04-15 17:18:32 -07:00
let code = r # ""# ;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-04-15 17:18:32 -07:00
assert! ( result . is_ok ( ) ) ;
}
2024-04-02 18:28:50 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_member_expression_in_params ( ) {
2024-04-02 18:28:50 -07:00
let code = r #" fn capScrew = (originStart, length, dia, capDia, capHeadLength) => {
const screwHead = startSketchOn ( {
plane : {
origin : {
x : originStart [ 0 ] ,
y : originStart [ 1 ] ,
z : originStart [ 2 ] ,
} ,
x_axis : { x : 0 , y : 0 , z : - 1 } ,
y_axis : { x : 1 , y : 0 , z : 0 } ,
z_axis : { x : 0 , y : 1 , z : 0 }
}
} )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : capDia / 2 } , % )
2024-04-02 18:28:50 -07:00
| > extrude ( capHeadLength , % )
const screw = startSketchOn ( screwHead , " start " )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : dia / 2 } , % )
2024-04-02 18:28:50 -07:00
| > extrude ( length , % )
return screw
}
capScrew ( [ 0 , 0.5 , 0 ] , 50 , 37.5 , 50 , 25 )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " member_expression_in_params " , & result ) ;
2024-04-02 18:28:50 -07:00
}
2024-04-10 18:51:09 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-09-03 13:34:31 -07:00
async fn kcl_test_bracket_with_fillets ( ) {
2024-04-10 18:51:09 -07:00
let code = r #" // Shelf Bracket
// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.
const sigmaAllow = 35000 // psi
const width = 6 // inch
const p = 300 // Force on shelf - lbs
const distance = 12 // inches
const M = 12 * 300 / 2 // Moment experienced at fixed end of bracket
const FOS = 2 // Factor of safety of 2
const shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
const wallMountL = 8 // the length of the bracket
// Calculate the thickness off the allowable bending stress and factor of safety
const thickness = sqrt ( 6 * M * FOS / ( width * sigmaAllow ) )
// 0.25 inch fillet radius
const filletR = 0.25
// Sketch the bracket and extrude with fillets
const bracket = startSketchOn ( ' XY ' )
| > startProfileAt ( [ 0 , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , wallMountL ] , % , $outerEdge )
2024-04-10 18:51:09 -07:00
| > line ( [ - shelfMountL , 0 ] , % )
| > line ( [ 0 , - thickness ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ shelfMountL - thickness , 0 ] , % , $innerEdge )
2024-04-10 18:51:09 -07:00
| > line ( [ 0 , - wallMountL + thickness ] , % )
| > close ( % )
| > extrude ( width , % )
| > fillet ( {
radius : filletR ,
2024-07-27 22:56:46 -07:00
tags : [ getNextAdjacentEdge ( innerEdge ) ]
2024-04-10 18:51:09 -07:00
} , % )
| > fillet ( {
radius : filletR + thickness ,
2024-07-27 22:56:46 -07:00
tags : [ getNextAdjacentEdge ( outerEdge ) ]
2024-04-10 18:51:09 -07:00
} , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-09-03 13:34:31 -07:00
assert! ( result . is_ok ( ) ) ;
2024-04-10 18:51:09 -07:00
}
2024-05-20 21:59:56 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_error_empty_start_sketch_on_string ( ) {
2024-05-20 21:59:56 -07:00
let code = r #" const part001 = startSketchOn('-XZ')
| > startProfileAt ( [ 75.75 , 184.25 ] , % )
| > line ( [ 190.03 , - 118.13 ] , % )
| > line ( [ - 33.38 , - 202.86 ] , % )
| > line ( [ - 315.86 , - 64.2 ] , % )
| > tangentialArcTo ( [ - 147.66 , 121.34 ] , % )
| > close ( % )
| > extrude ( 100 , % )
const secondSketch = startSketchOn ( part001 , ' ' )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ - 20 , 50 ] , radius : 40 } , % )
2024-05-20 21:59:56 -07:00
| > extrude ( 20 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-05-20 21:59:56 -07:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-08-13 16:25:09 -04:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([272, 298])], message: "Argument at index 1 was supposed to be type kcl_lib::std::sketch::FaceTag but found string (text)" }"#
2024-05-20 21:59:56 -07:00
) ;
}
2024-05-21 00:49:57 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_error_user_function_wrong_args ( ) {
2024-05-21 00:49:57 -07:00
let code = r #" const length = .750
const width = 0.500
const height = 0.500
const dia = 4
fn squareHole = ( l , w ) = > {
const squareHoleSketch = startSketchOn ( ' XY ' )
| > startProfileAt ( [ - width / 2 , - length / 2 ] , % )
| > lineTo ( [ width / 2 , - length / 2 ] , % )
| > lineTo ( [ width / 2 , length / 2 ] , % )
| > lineTo ( [ - width / 2 , length / 2 ] , % )
| > close ( % )
return squareHoleSketch
}
const extrusion = startSketchOn ( ' XY ' )
2024-09-23 22:42:51 +10:00
| > circle ( { center : [ 0 , 0 ] , radius : dia / 2 } , % )
2024-05-21 00:49:57 -07:00
| > hole ( squareHole ( length , width , height ) , % )
| > extrude ( height , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
2024-05-21 00:49:57 -07:00
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-09-23 22:42:51 +10:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([92, 364]), SourceRange([464, 497])], message: "Expected 2 arguments, got 3" }"#
2024-05-21 00:49:57 -07:00
) ;
}
2024-05-21 23:35:33 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_xz_plane ( ) {
2024-05-21 23:35:33 -07:00
let code = r #" const part001 = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > lineTo ( [ 100 , 100 ] , % )
| > lineTo ( [ 100 , 0 ] , % )
| > close ( % )
| > extrude ( 5 + 7 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " xz_plane " , & result ) ;
2024-05-21 23:35:33 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_neg_xz_plane ( ) {
2024-05-21 23:35:33 -07:00
let code = r #" const part001 = startSketchOn('-XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > lineTo ( [ 100 , 100 ] , % )
| > lineTo ( [ 100 , 0 ] , % )
| > close ( % )
| > extrude ( 5 + 7 , % )
" #;
2024-06-06 16:01:41 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " neg_xz_plane " , & result ) ;
2024-05-21 23:35:33 -07:00
}
2024-06-17 13:35:44 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_linear_pattern3d_a_pattern ( ) {
2024-06-17 13:35:44 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 2 ] , % )
| > line ( [ 3 , 1 ] , % )
| > line ( [ 0 , - 4 ] , % )
| > close ( % )
| > extrude ( 1 , % )
const pattn1 = patternLinear3d ( {
axis : [ 1 , 0 , 0 ] ,
repetitions : 6 ,
distance : 6
} , exampleSketch )
const pattn2 = patternLinear3d ( {
axis : [ 0 , 0 , 1 ] ,
distance : 1 ,
repetitions : 6
} , pattn1 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " linear_pattern3d_a_pattern " , & result ) ;
2024-06-17 13:35:44 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_circular_pattern3d_a_pattern ( ) {
2024-06-17 13:35:44 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 0 , 2 ] , % )
| > line ( [ 3 , 1 ] , % )
| > line ( [ 0 , - 4 ] , % )
| > close ( % )
| > extrude ( 1 , % )
const pattn1 = patternLinear3d ( {
axis : [ 1 , 0 , 0 ] ,
repetitions : 6 ,
distance : 6
} , exampleSketch )
const pattn2 = patternCircular3d ( { axis : [ 0 , 0 , 1 ] , center : [ - 20 , - 20 , - 20 ] , repetitions : 40 , arcDegrees : 360 , rotateDuplicates : false } , pattn1 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " circular_pattern3d_a_pattern " , & result ) ;
2024-06-17 13:35:44 -07:00
}
2024-06-21 16:44:31 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_array_of_sketches ( ) {
2024-06-21 16:44:31 -07:00
let code = r #" const plane001 = startSketchOn('XZ')
const profile001 = plane001
| > startProfileAt ( [ 40.82 , 240.82 ] , % )
| > line ( [ 235.72 , - 8.16 ] , % )
| > line ( [ 13.27 , - 253.07 ] , % )
| > line ( [ - 247.97 , - 19.39 ] , % )
| > lineTo ( [ profileStartX ( % ) , profileStartY ( % ) ] , % )
| > close ( % )
const profile002 = plane001
| > startProfileAt ( [ 47.17 , - 71.91 ] , % )
| > line ( [ 247.96 , - 4.03 ] , % )
| > line ( [ - 17.26 , - 116.79 ] , % )
| > line ( [ - 235.87 , 12.66 ] , % )
| > lineTo ( [ profileStartX ( % ) , profileStartY ( % ) ] , % )
| > close ( % )
const sketch001 = [ profile001 , profile002 ]
extrude ( 10 , sketch001 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " array_of_sketches " , & result ) ;
2024-06-21 16:44:31 -07:00
}
2024-06-21 19:54:18 -07:00
2024-06-22 14:31:37 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_sketch_on_face_after_fillets_referencing_face ( ) {
2024-06-22 14:31:37 -07:00
let code = r #" // Shelf Bracket
// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.
// Define our bracket feet lengths
const shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
const wallMountL = 6 // the length of the bracket
// Define constants required to calculate the thickness needed to support 300 lbs
const sigmaAllow = 35000 // psi
const width = 6 // inch
const p = 300 // Force on shelf - lbs
const L = 12 // inches
const M = L * p / 2 // Moment experienced at fixed end of bracket
const FOS = 2 // Factor of safety of 2 to be conservative
// Calculate the thickness off the bending stress and factor of safety
const thickness = sqrt ( 6 * M * FOS / ( width * sigmaAllow ) )
// 0.25 inch fillet radius
const filletR = 0.25
// Sketch the bracket and extrude with fillets
const bracket = startSketchOn ( ' XY ' )
| > startProfileAt ( [ 0 , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , wallMountL ] , % , $outerEdge )
| > line ( [ - shelfMountL , 0 ] , % , $seg01 )
2024-06-22 14:31:37 -07:00
| > line ( [ 0 , - thickness ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ shelfMountL - thickness , 0 ] , % , $innerEdge )
2024-06-22 14:31:37 -07:00
| > line ( [ 0 , - wallMountL + thickness ] , % )
| > close ( % )
| > extrude ( width , % )
| > fillet ( {
radius : filletR ,
tags : [
2024-09-03 13:34:31 -07:00
getNextAdjacentEdge ( innerEdge )
2024-06-22 14:31:37 -07:00
]
} , % )
| > fillet ( {
radius : filletR + thickness ,
tags : [
2024-09-03 13:34:31 -07:00
getNextAdjacentEdge ( outerEdge )
2024-06-22 14:31:37 -07:00
]
} , % )
2024-07-27 17:59:41 -07:00
const sketch001 = startSketchOn ( bracket , seg01 )
2024-06-22 14:31:37 -07:00
| > startProfileAt ( [ 4.28 , 3.83 ] , % )
| > line ( [ 2.17 , - 0.03 ] , % )
| > line ( [ - 0.07 , - 1.8 ] , % )
| > line ( [ - 2.07 , 0.05 ] , % )
| > lineTo ( [ profileStartX ( % ) , profileStartY ( % ) ] , % )
| > close ( % )
| > extrude ( 10 , % )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " sketch_on_face_after_fillets_referencing_face " , & result ) ;
2024-06-22 14:31:37 -07:00
}
2024-06-21 19:54:18 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_circular_pattern3d_array_of_extrudes ( ) {
2024-06-21 19:54:18 -07:00
let code = r #" const plane001 = startSketchOn('XZ')
const sketch001 = plane001
| > startProfileAt ( [ 40.82 , 240.82 ] , % )
| > line ( [ 235.72 , - 8.16 ] , % )
| > line ( [ 13.27 , - 253.07 ] , % )
| > line ( [ - 247.97 , - 19.39 ] , % )
| > lineTo ( [ profileStartX ( % ) , profileStartY ( % ) ] , % )
| > close ( % )
| > extrude ( 10 , % )
const sketch002 = plane001
| > startProfileAt ( [ 47.17 , - 71.91 ] , % )
| > line ( [ 247.96 , - 4.03 ] , % )
| > line ( [ - 17.26 , - 116.79 ] , % )
| > line ( [ - 235.87 , 12.66 ] , % )
| > lineTo ( [ profileStartX ( % ) , profileStartY ( % ) ] , % )
| > close ( % )
| > extrude ( 10 , % )
let extrudes = [ sketch001 , sketch002 ]
const pattn1 = patternLinear3d ( {
axis : [ 0 , 1 , 0 ] ,
repetitions : 2 ,
distance : 20
} , extrudes )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " pattern3d_array_of_extrudes " , & result ) ;
2024-06-21 19:54:18 -07:00
}
2024-06-22 14:31:37 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_fillets_referencing_other_fillets ( ) {
2024-06-22 14:31:37 -07:00
let code = r #" // Z-Bracket
// Z-brackets are designed to affix or hang objects from a wall by securing them to the wall's studs. These brackets offer support and mounting solutions for bulky or heavy items that may be challenging to attach directly. Serving as a protective feature, Z-brackets help prevent heavy loads from moving or toppling, enhancing safety in the environment where they are used.
// Define constants
const foot1Length = 4
const height = 4
const foot2Length = 5
const width = 4
const filletRad = 0.25
const thickness = 0.125
const cornerFilletRad = 0.5
const holeDia = 0.5
const sketch001 = startSketchOn ( " XZ " )
| > startProfileAt ( [ - foot1Length , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , thickness ] , % , $cornerFillet1 )
2024-06-22 14:31:37 -07:00
| > line ( [ foot1Length , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , height ] , % , $fillet1 )
2024-06-22 14:31:37 -07:00
| > line ( [ foot2Length , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - thickness ] , % , $cornerFillet2 )
2024-06-22 14:31:37 -07:00
| > line ( [ - foot2Length + thickness , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - height ] , % , $fillet2 )
2024-06-22 14:31:37 -07:00
| > close ( % )
const baseExtrusion = extrude ( width , sketch001 )
| > fillet ( {
radius : cornerFilletRad ,
2024-07-27 22:56:46 -07:00
tags : [ cornerFillet1 , cornerFillet2 , getOppositeEdge ( cornerFillet1 ) , getOppositeEdge ( cornerFillet2 ) ] ,
2024-06-22 14:31:37 -07:00
} , % )
| > fillet ( {
radius : filletRad ,
2024-07-27 22:56:46 -07:00
tags : [ getPreviousAdjacentEdge ( fillet1 ) , getPreviousAdjacentEdge ( fillet2 ) ]
2024-06-22 14:31:37 -07:00
} , % )
| > fillet ( {
radius : filletRad + thickness ,
2024-07-27 22:56:46 -07:00
tags : [ getNextAdjacentEdge ( fillet1 ) , getNextAdjacentEdge ( fillet2 ) ] ,
2024-06-22 14:31:37 -07:00
} , % )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " fillets_referencing_other_fillets " , & result ) ;
2024-06-22 14:31:37 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_chamfers_referencing_other_chamfers ( ) {
2024-06-22 14:31:37 -07:00
let code = r #" // Z-Bracket
// Z-brackets are designed to affix or hang objects from a wall by securing them to the wall's studs. These brackets offer support and mounting solutions for bulky or heavy items that may be challenging to attach directly. Serving as a protective feature, Z-brackets help prevent heavy loads from moving or toppling, enhancing safety in the environment where they are used.
// Define constants
const foot1Length = 4
const height = 4
const foot2Length = 5
const width = 4
const chamferRad = 0.25
const thickness = 0.125
const cornerChamferRad = 0.5
const holeDia = 0.5
const sketch001 = startSketchOn ( " XZ " )
| > startProfileAt ( [ - foot1Length , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , thickness ] , % , $cornerChamfer1 )
2024-06-22 14:31:37 -07:00
| > line ( [ foot1Length , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , height ] , % , $chamfer1 )
2024-06-22 14:31:37 -07:00
| > line ( [ foot2Length , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - thickness ] , % , $cornerChamfer2 )
2024-06-22 14:31:37 -07:00
| > line ( [ - foot2Length + thickness , 0 ] , % )
2024-07-27 17:59:41 -07:00
| > line ( [ 0 , - height ] , % , $chamfer2 )
2024-06-22 14:31:37 -07:00
| > close ( % )
const baseExtrusion = extrude ( width , sketch001 )
| > chamfer ( {
length : cornerChamferRad ,
2024-07-27 22:56:46 -07:00
tags : [ cornerChamfer1 , cornerChamfer2 , getOppositeEdge ( cornerChamfer1 ) , getOppositeEdge ( cornerChamfer2 ) ] ,
2024-06-22 14:31:37 -07:00
} , % )
| > chamfer ( {
length : chamferRad ,
2024-07-27 22:56:46 -07:00
tags : [ getPreviousAdjacentEdge ( chamfer1 ) , getPreviousAdjacentEdge ( chamfer2 ) ]
2024-06-22 14:31:37 -07:00
} , % )
| > chamfer ( {
length : chamferRad + thickness ,
2024-07-27 22:56:46 -07:00
tags : [ getNextAdjacentEdge ( chamfer1 ) , getNextAdjacentEdge ( chamfer2 ) ] ,
2024-06-22 14:31:37 -07:00
} , % )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " chamfers_referencing_other_chamfers " , & result ) ;
2024-06-22 14:31:37 -07:00
}
2024-06-22 16:22:32 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-08-13 16:25:09 -04:00
async fn kcl_test_shell_with_tag ( ) {
2024-06-22 16:22:32 -07:00
let code = r #" const sketch001 = startSketchOn('XZ')
| > startProfileAt ( [ 61.74 , 206.13 ] , % )
2024-07-27 17:59:41 -07:00
| > xLine ( 305.11 , % , $seg01 )
2024-06-22 16:22:32 -07:00
| > yLine ( - 291.85 , % )
2024-07-27 22:56:46 -07:00
| > xLine ( - segLen ( seg01 ) , % )
2024-06-22 16:22:32 -07:00
| > lineTo ( [ profileStartX ( % ) , profileStartY ( % ) ] , % )
| > close ( % )
| > extrude ( 40.14 , % )
| > shell ( {
2024-07-27 17:59:41 -07:00
faces : [ seg01 ] ,
2024-06-22 16:22:32 -07:00
thickness : 3.14 ,
} , % )
" #;
2024-08-13 16:25:09 -04:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
assert_out ( " shell_with_tag " , & result ) ;
2024-06-22 16:22:32 -07:00
}
2024-06-23 19:19:24 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_linear_pattern3d_filleted_sketch ( ) {
2024-06-23 19:19:24 -07:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
2024-07-27 17:59:41 -07:00
| > close ( % , $line1 )
2024-06-23 19:19:24 -07:00
| > extrude ( 20 , % )
| > fillet ( {
radius : 10 ,
2024-07-27 22:56:46 -07:00
tags : [ getOppositeEdge ( line1 ) ]
2024-06-23 19:19:24 -07:00
} , % )
const pattn1 = patternLinear3d ( {
axis : [ 1 , 0 , 0 ] ,
repetitions : 3 ,
distance : 40
} , part001 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " linear_pattern3d_filleted_sketch " , & result ) ;
2024-06-23 19:19:24 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_circular_pattern3d_filleted_sketch ( ) {
2024-06-23 19:19:24 -07:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
2024-07-27 17:59:41 -07:00
| > close ( % , $line1 )
2024-06-23 19:19:24 -07:00
| > extrude ( 20 , % )
| > fillet ( {
radius : 10 ,
2024-07-27 22:56:46 -07:00
tags : [ getOppositeEdge ( line1 ) ]
2024-06-23 19:19:24 -07:00
} , % )
const pattn2 = patternCircular3d ( { axis : [ 0 , 0 , 1 ] , center : [ - 20 , - 20 , - 20 ] , repetitions : 4 , arcDegrees : 360 , rotateDuplicates : false } , part001 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " circular_pattern3d_filleted_sketch " , & result ) ;
2024-06-23 19:19:24 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_circular_pattern3d_chamfered_sketch ( ) {
2024-06-23 19:19:24 -07:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
2024-07-27 17:59:41 -07:00
| > close ( % , $line1 )
2024-06-23 19:19:24 -07:00
| > extrude ( 20 , % )
| > chamfer ( {
length : 10 ,
2024-07-27 22:56:46 -07:00
tags : [ getOppositeEdge ( line1 ) ]
2024-06-23 19:19:24 -07:00
} , % )
const pattn2 = patternCircular3d ( { axis : [ 0 , 0 , 1 ] , center : [ - 20 , - 20 , - 20 ] , repetitions : 4 , arcDegrees : 360 , rotateDuplicates : false } , part001 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " circular_pattern3d_chamfered_sketch " , & result ) ;
2024-06-23 19:19:24 -07:00
}
2024-06-23 23:04:32 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_tag_chamfer_with_more_than_one_edge_should_fail ( ) {
2024-06-23 23:04:32 -07:00
let code = r #" fn cube = (pos, scale) => {
const sg = startSketchOn ( ' XY ' )
| > startProfileAt ( pos , % )
| > line ( [ 0 , scale ] , % )
| > line ( [ scale , 0 ] , % )
| > line ( [ 0 , - scale ] , % )
return sg
}
const part001 = cube ( [ 0 , 0 ] , 20 )
2024-07-27 17:59:41 -07:00
| > close ( % , $line1 )
2024-06-23 23:04:32 -07:00
| > extrude ( 20 , % )
| > chamfer ( {
length : 10 ,
2024-07-27 22:56:46 -07:00
tags : [ line1 , getOppositeEdge ( line1 ) ]
2024-07-27 17:59:41 -07:00
} , % , $chamfer1 )
2024-06-23 23:04:32 -07:00
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-07-27 22:56:46 -07:00
r # "type: KclErrorDetails { source_ranges: [SourceRange([271, 357])], message: "You can only tag one edge at a time with a tagged chamfer. Either delete the tag for the chamfer fn if you don't need it OR separate into individual chamfer functions for each tag." }"#
2024-06-23 23:04:32 -07:00
) ;
}
2024-06-24 14:45:07 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_duplicate_tags_should_error ( ) {
2024-06-24 14:45:07 -07:00
let code = r #" fn triangle = (len) => {
return startSketchOn ( ' XY ' )
| > startProfileAt ( [ - len / 2 , - len / 2 ] , % )
| > angledLine ( { angle : 0 , length : len } , % , $a )
| > angledLine ( {
2024-07-27 22:56:46 -07:00
angle : segAng ( a ) + 120 ,
2024-06-24 14:45:07 -07:00
length : len
} , % , $b )
| > angledLine ( {
2024-07-27 22:56:46 -07:00
angle : segAng ( b ) + 120 ,
2024-06-24 14:45:07 -07:00
length : len
} , % , $a )
}
let p = triangle ( 200 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-07-27 22:56:46 -07:00
r # "value already defined: KclErrorDetails { source_ranges: [SourceRange([311, 313]), SourceRange([326, 339])], message: "Cannot redefine `a`" }"#
2024-06-24 14:45:07 -07:00
) ;
}
2024-06-25 10:35:48 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_global_tags ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " global-tags " ) ;
2024-06-25 10:35:48 -07:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " global_tags " , & result ) ;
2024-06-25 10:35:48 -07:00
}
2024-06-27 22:20:51 -05:00
2024-07-27 22:56:46 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_extrude_inside_fn_with_tags ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " extrude-inside-fn-with-tags " ) ;
2024-07-27 22:56:46 -07:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " extrude-inside-fn-with-tags " , & result ) ;
2024-07-27 22:56:46 -07:00
}
2024-06-27 22:20:51 -05:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_pattern_vase ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " pattern_vase " ) ;
2024-06-27 22:20:51 -05:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " pattern_vase " , & result ) ;
2024-06-27 22:20:51 -05:00
}
2024-07-05 15:37:30 -07:00
2024-07-05 16:53:13 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_scoped_tags ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " scoped-tags " ) ;
2024-07-05 16:53:13 -07:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " scoped_tags " , & result ) ;
2024-07-05 16:53:13 -07:00
}
2024-07-05 15:37:30 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_order_sketch_extrude_in_order ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " order-sketch-extrude-in-order " ) ;
2024-07-05 15:37:30 -07:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " order-sketch-extrude-in-order " , & result ) ;
2024-07-05 15:37:30 -07:00
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_order_sketch_extrude_out_of_order ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " order-sketch-extrude-out-of-order " ) ;
2024-07-05 15:37:30 -07:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " order-sketch-extrude-out-of-order " , & result ) ;
2024-07-05 15:37:30 -07:00
}
2024-07-09 23:39:59 -04:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_extrude_custom_plane ( ) {
2024-07-30 11:14:37 -05:00
let code = kcl_input! ( " extrude-custom-plane " ) ;
2024-07-09 23:39:59 -04:00
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await . unwrap ( ) ;
2024-07-30 11:14:37 -05:00
assert_out ( " extrude-custom-plane " , & result ) ;
2024-07-09 23:39:59 -04:00
}
2024-07-28 16:09:54 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_arc_error_same_start_end ( ) {
2024-07-28 16:09:54 -07:00
let code = r #" startSketchOn('XY')
| > startProfileAt ( [ 10 , 0 ] , % )
| > arc ( {
angle_start : 180 ,
angle_end : 180 ,
radius : 1.5
} , % )
| > close ( % )
| > patternCircular2d ( {
arcDegrees : 360 ,
center : [ 0 , 0 ] ,
repetitions : 5 ,
rotateDuplicates : true
} , % )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([57, 140])], message: "Arc start and end angles must be different" }"#
) ;
}
2024-07-28 20:36:18 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_to_x_90 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > angledLineToX ( { angle : 90 , to : 10 } , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ - 10 , 0 ] , % )
| > close ( % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([78, 117])], message: "Cannot have an x constrained angle of 90 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_to_x_270 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > angledLineToX ( { angle : 270 , to : 10 } , % )
| > line ( [ 0 , 10 ] , % )
| > line ( [ - 10 , 0 ] , % )
| > close ( % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([78, 118])], message: "Cannot have an x constrained angle of 270 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_to_y_0 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > angledLineToY ( { angle : 0 , to : 20 } , % )
| > line ( [ - 20 , 0 ] , % )
| > angledLineToY ( { angle : 70 , to : 10 } , % )
| > close ( % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([78, 116])], message: "Cannot have a y constrained angle of 0 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_to_y_180 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > angledLineToY ( { angle : 180 , to : 20 } , % )
| > line ( [ - 20 , 0 ] , % )
| > angledLineToY ( { angle : 70 , to : 10 } , % )
| > close ( % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([78, 118])], message: "Cannot have a y constrained angle of 180 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_of_x_length_90 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const sketch001 = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > angledLineOfXLength ( { angle : 90 , length : 10 } , % , $edge1 )
| > angledLineOfXLength ( { angle : - 15 , length : 20 } , % , $edge2 )
| > line ( [ 0 , - 5 ] , % )
| > close ( % , $edge3 )
const extrusion = extrude ( 10 , sketch001 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([74, 131])], message: "Cannot have an x constrained angle of 90 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_of_x_length_270 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const sketch001 = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > angledLineOfXLength ( { angle : 90 , length : 10 } , % , $edge1 )
| > angledLineOfXLength ( { angle : - 15 , length : 20 } , % , $edge2 )
| > line ( [ 0 , - 5 ] , % )
| > close ( % , $edge3 )
const extrusion = extrude ( 10 , sketch001 )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([74, 131])], message: "Cannot have an x constrained angle of 90 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_of_y_length_0 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 10 , 0 ] , % )
| > angledLineOfYLength ( { angle : 0 , length : 10 } , % )
| > line ( [ 0 , 10 ] , % )
| > angledLineOfYLength ( { angle : 135 , length : 10 } , % )
| > line ( [ - 10 , 0 ] , % )
| > line ( [ 0 , - 30 ] , % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([100, 148])], message: "Cannot have a y constrained angle of 0 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_of_y_length_180 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 10 , 0 ] , % )
| > angledLineOfYLength ( { angle : 180 , length : 10 } , % )
| > line ( [ 0 , 10 ] , % )
| > angledLineOfYLength ( { angle : 135 , length : 10 } , % )
| > line ( [ - 10 , 0 ] , % )
| > line ( [ 0 , - 30 ] , % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([100, 150])], message: "Cannot have a y constrained angle of 180 degrees" }"#
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_angled_line_of_y_length_negative_180 ( ) {
2024-07-28 20:36:18 -07:00
let code = r #" const exampleSketch = startSketchOn('XZ')
| > startProfileAt ( [ 0 , 0 ] , % )
| > line ( [ 10 , 0 ] , % )
| > angledLineOfYLength ( { angle : - 180 , length : 10 } , % )
| > line ( [ 0 , 10 ] , % )
| > angledLineOfYLength ( { angle : 135 , length : 10 } , % )
| > line ( [ - 10 , 0 ] , % )
| > line ( [ 0 , - 30 ] , % )
const example = extrude ( 10 , exampleSketch )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
r # "type: KclErrorDetails { source_ranges: [SourceRange([100, 151])], message: "Cannot have a y constrained angle of 180 degrees" }"#
) ;
}
2024-07-28 23:49:28 -07:00
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_error_inside_fn_also_has_source_range_of_call_site ( ) {
2024-07-28 23:49:28 -07:00
let code = r #" fn someFunction = (something) => {
startSketchOn ( something )
}
someFunction ( ' INVALID ' )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-08-13 16:25:09 -04:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([37, 61]), SourceRange([65, 88])], message: "Argument at index 0 was supposed to be type kcl_lib::std::sketch::SketchData but found string (text)" }"#
2024-07-28 23:49:28 -07:00
) ;
}
#[ tokio::test(flavor = " multi_thread " ) ]
2024-07-30 16:12:01 -05:00
async fn kcl_test_error_inside_fn_also_has_source_range_of_call_site_recursive ( ) {
2024-07-28 23:49:28 -07:00
let code = r #" fn someFunction = (something) => {
fn someNestedFunction = ( something2 ) = > {
startSketchOn ( something2 )
}
someNestedFunction ( something )
}
someFunction ( ' INVALID ' )
" #;
let result = execute_and_snapshot ( code , UnitLength ::Mm ) . await ;
assert! ( result . is_err ( ) ) ;
assert_eq! (
result . err ( ) . unwrap ( ) . to_string ( ) ,
2024-08-13 16:25:09 -04:00
r # "semantic: KclErrorDetails { source_ranges: [SourceRange([89, 114]), SourceRange([126, 155]), SourceRange([159, 182])], message: "Argument at index 0 was supposed to be type kcl_lib::std::sketch::SketchData but found string (text)" }"#
2024-07-28 23:49:28 -07:00
) ;
}