Compare commits

..

4 Commits

29 changed files with 6073 additions and 574 deletions

View File

@ -59,6 +59,7 @@ layout: manual
* [`legAngX`](kcl/legAngX)
* [`legAngY`](kcl/legAngY)
* [`legLen`](kcl/legLen)
* [`len`](kcl/len)
* [`line`](kcl/line)
* [`lineTo`](kcl/lineTo)
* [`ln`](kcl/ln)

37
docs/kcl/len.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,8 +17,8 @@ push(array: [KclValue], elem: KclValue) -> KclValue
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array to push to. | Yes |
| `elem` | [`KclValue`](/docs/kcl/types/KclValue) | The element to push to the array. | Yes |
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes |
| `elem` | [`KclValue`](/docs/kcl/types/KclValue) | Any KCL value. | Yes |
### Returns
@ -29,7 +29,7 @@ push(array: [KclValue], elem: KclValue) -> KclValue
```js
arr = [1, 2, 3]
new_arr = push(arr, elem = 4)
new_arr = push(arr, 4)
assertEqual(new_arr[3], 4, 0.00001, "4 was added to the end of the array")
```

View File

@ -17,9 +17,9 @@ reduce(array: [KclValue], start: KclValue, reduce_fn: FunctionParam) -> KclValue
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array to reduce. | Yes |
| `start` | [`KclValue`](/docs/kcl/types/KclValue) | The starting value for the reduction. | Yes |
| `reduce_fn` | `FunctionParam` | The function to reduce the array with. | Yes |
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes |
| `start` | [`KclValue`](/docs/kcl/types/KclValue) | Any KCL value. | Yes |
| `reduce_fn` | `FunctionParam` | | Yes |
### Returns
@ -38,7 +38,7 @@ fn add(a, b) {
// It uses the `reduce` function, to call the `add` function on every
// element of the `arr` parameter. The starting value is 0.
fn sum(arr) {
return reduce(arr, start = 0, reduce_fn = add)
return reduce(arr, 0, add)
}
/* The above is basically like this pseudo-code:
@ -61,7 +61,7 @@ assertEqual(sum([1, 2, 3]), 6, 0.00001, "1 + 2 + 3 summed is 6")
// an anonymous `add` function as its parameter, instead of declaring a
// named function outside.
arr = [1, 2, 3]
sum = reduce(arr, start = 0, reduce_fn = fn(i, result_so_far) {
sum = reduce(arr, 0, fn(i, result_so_far) {
return i + result_so_far
})
@ -85,7 +85,7 @@ fn decagon(radius) {
// Use a `reduce` to draw the remaining decagon sides.
// For each number in the array 1..10, run the given function,
// which takes a partially-sketched decagon and adds one more edge to it.
fullDecagon = reduce([1..10], start = startOfDecagonSketch, reduce_fn = fn(i, partialDecagon) {
fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) {
// Draw one edge of the decagon.
x = cos(stepAngle * i) * radius
y = sin(stepAngle * i) * radius

File diff suppressed because it is too large Load Diff

View File

@ -368,20 +368,13 @@ export class LanguageServerPlugin implements PluginValue {
sortText,
filterText,
}) => {
const detailText = [
deprecated ? 'Deprecated' : undefined,
labelDetails ? labelDetails.detail : detail,
]
// Don't let undefined appear.
.filter(Boolean)
.join(' ')
const completion: Completion & {
filterText: string
sortText?: string
apply: string
} = {
label,
detail: detailText,
detail: labelDetails ? labelDetails.detail : detail,
apply: label,
type: kind && CompletionItemKindMap[kind].toLowerCase(),
sortText: sortText ?? label,
@ -389,11 +382,7 @@ export class LanguageServerPlugin implements PluginValue {
}
if (documentation) {
completion.info = () => {
const deprecatedHtml = deprecated
? '<p><strong>Deprecated</strong></p>'
: ''
const htmlString =
deprecatedHtml + formatMarkdownContents(documentation)
const htmlString = formatMarkdownContents(documentation)
const htmlNode = document.createElement('div')
htmlNode.style.display = 'contents'
htmlNode.innerHTML = htmlString

View File

@ -1755,3 +1755,24 @@ mod array_elem_pop_fail {
super::execute(TEST_NAME, false).await
}
}
mod array_length {
const TEST_NAME: &str = "array_length";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[test]
fn unparse() {
super::unparse(TEST_NAME)
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}

View File

@ -1,6 +1,9 @@
use derive_docs::stdlib;
use super::{args::Arg, Args, FnAsArg};
use super::{
args::{Arg, FromArgs},
Args, FnAsArg,
};
use crate::{
errors::{KclError, KclErrorDetails},
execution::{ExecState, FunctionParam, KclValue},
@ -9,47 +12,14 @@ use crate::{
/// Apply a function to each element of an array.
pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let array = args.get_unlabeled_kw_arg("array")?;
// Check that the array is an array
let array: Vec<KclValue> = match array {
KclValue::Array { value, meta: _ } => value,
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!(
"Expected an array to map, but got a value of type {}",
array.human_friendly_type()
),
}))
}
};
// Check that the map_fn is a function
let map_fn_kclvalue: KclValue = args.get_kw_arg("map_fn")?;
match map_fn_kclvalue {
KclValue::Function { .. } => (),
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!(
"Expected map_fn to be a function, but got a value of type {}",
map_fn_kclvalue.human_friendly_type()
),
}))
}
}
// Extract the function from the KclValue
let map_fn: FnAsArg<'_> = args.get_kw_arg("map_fn")?;
let (array, f): (Vec<KclValue>, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?;
let meta = vec![args.source_range.into()];
let map_fn = FunctionParam {
inner: map_fn.func,
fn_expr: map_fn.expr,
inner: f.func,
fn_expr: f.expr,
meta: meta.clone(),
ctx: args.ctx.clone(),
memory: *map_fn.memory,
memory: *f.memory,
};
let new_array = inner_map(array, map_fn, exec_state, &args).await?;
Ok(KclValue::Array { value: new_array, meta })
@ -71,7 +41,7 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// // which is the return value from `map`.
/// circles = map(
/// [1..3],
/// map_fn = drawCircle
/// drawCircle
/// )
/// ```
/// ```no_run
@ -79,7 +49,7 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// // Call `map`, using an anonymous function instead of a named one.
/// circles = map(
/// [1..3],
/// map_fn = fn(id) {
/// fn(id) {
/// return startSketchOn("XY")
/// |> circle({ center: [id * 2 * r, 0], radius: r}, %)
/// }
@ -87,12 +57,6 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// ```
#[stdlib {
name = "map",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to map.",
map_fn = "The function to map the array with.",
}
}]
async fn inner_map<'a>(
array: Vec<KclValue>,
@ -127,43 +91,13 @@ async fn call_map_closure<'a>(
/// For each item in an array, update a value.
pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let array_val = args.get_unlabeled_kw_arg("array")?;
let start = args.get_kw_arg("start")?;
let reduce_fn_kclvalue: KclValue = args.get_kw_arg("reduce_fn")?;
let array: Vec<KclValue> = match array_val {
KclValue::Array { value, meta: _ } => value,
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!("You can't reduce a value of type {}", array_val.human_friendly_type()),
}))
}
};
// Check that the reduce_fn is a function
match reduce_fn_kclvalue {
KclValue::Function { .. } => (),
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!(
"Expected reduce_fn to be a function, but got a value of type {}",
reduce_fn_kclvalue.human_friendly_type()
),
}))
}
}
// Extract the function from the KclValue
let reduce_fn: FnAsArg<'_> = args.get_kw_arg("reduce_fn")?;
let (array, start, f): (Vec<KclValue>, KclValue, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?;
let reduce_fn = FunctionParam {
inner: reduce_fn.func,
fn_expr: reduce_fn.expr,
inner: f.func,
fn_expr: f.expr,
meta: vec![args.source_range.into()],
ctx: args.ctx.clone(),
memory: *reduce_fn.memory,
memory: *f.memory,
};
inner_reduce(array, start, reduce_fn, exec_state, &args).await
}
@ -177,7 +111,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// // This function adds an array of numbers.
/// // It uses the `reduce` function, to call the `add` function on every
/// // element of the `arr` parameter. The starting value is 0.
/// fn sum(arr) { return reduce(arr, start = 0, reduce_fn = add) }
/// fn sum(arr) { return reduce(arr, 0, add) }
///
/// /*
/// The above is basically like this pseudo-code:
@ -197,7 +131,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// // an anonymous `add` function as its parameter, instead of declaring a
/// // named function outside.
/// arr = [1, 2, 3]
/// sum = reduce(arr, start = 0, reduce_fn = (i, result_so_far) => { return i + result_so_far })
/// sum = reduce(arr, 0, (i, result_so_far) => { return i + result_so_far })
///
/// // We use `assertEqual` to check that our `sum` function gives the
/// // expected result. It's good to check your work!
@ -216,7 +150,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// // Use a `reduce` to draw the remaining decagon sides.
/// // For each number in the array 1..10, run the given function,
/// // which takes a partially-sketched decagon and adds one more edge to it.
/// fullDecagon = reduce([1..10], start = startOfDecagonSketch, reduce_fn = fn(i, partialDecagon) {
/// fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) {
/// // Draw one edge of the decagon.
/// x = cos(stepAngle * i) * radius
/// y = sin(stepAngle * i) * radius
@ -249,13 +183,6 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// ```
#[stdlib {
name = "reduce",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to reduce.",
start = "The starting value for the reduction.",
reduce_fn = "The function to reduce the array with.",
}
}]
async fn inner_reduce<'a>(
array: Vec<KclValue>,
@ -300,17 +227,11 @@ async fn call_reduce_closure<'a>(
///
/// ```no_run
/// arr = [1, 2, 3]
/// new_arr = push(arr, elem = 4)
/// new_arr = push(arr, 4)
/// assertEqual(new_arr[3], 4, 0.00001, "4 was added to the end of the array")
/// ```
#[stdlib {
name = "push",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to push to.",
elem = "The element to push to the array.",
}
}]
async fn inner_push(mut array: Vec<KclValue>, elem: KclValue, args: &Args) -> Result<KclValue, KclError> {
// Unwrap the KclValues to JValues for manipulation
@ -323,8 +244,7 @@ async fn inner_push(mut array: Vec<KclValue>, elem: KclValue, args: &Args) -> Re
pub async fn push(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
// Extract the array and the element from the arguments
let val = args.get_unlabeled_kw_arg("array")?;
let elem = args.get_kw_arg("elem")?;
let (val, elem): (KclValue, KclValue) = FromArgs::from_args(&args, 0)?;
let meta = vec![args.source_range];
let KclValue::Array { value: array, meta: _ } = val else {
@ -388,3 +308,40 @@ pub async fn pop(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
inner_pop(array, &args).await
}
/// Get the length of an array.
///
/// Returns the number of elements in an array.
///
/// ```no_run
/// arr = [1, 2, 3]
/// length = len(arr)
/// assertEqual(length, 3, 0.00001, "The length of the array is 3")
/// ```
#[stdlib {
name = "len",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to get the length of.",
}
}]
async fn inner_len(array: Vec<KclValue>, args: &Args) -> Result<KclValue, KclError> {
Ok(KclValue::Number {
value: array.len() as f64,
meta: vec![args.source_range.into()],
})
}
pub async fn len(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let val = args.get_unlabeled_kw_arg("array")?;
let meta = vec![args.source_range];
let KclValue::Array { value: array, meta: _ } = val else {
let actual_type = val.human_friendly_type();
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: meta,
message: format!("You can't get the length of a value of type {actual_type}, only an array"),
}));
};
inner_len(array, &args).await
}

View File

@ -108,6 +108,7 @@ lazy_static! {
Box::new(crate::std::array::Reduce),
Box::new(crate::std::array::Map),
Box::new(crate::std::array::Push),
Box::new(crate::std::array::Len),
Box::new(crate::std::array::Pop),
Box::new(crate::std::chamfer::Chamfer),
Box::new(crate::std::fillet::Fillet),

View File

@ -1,8 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing argument_error.kcl
snapshot_kind: text
---
{
"Ok": {
@ -63,39 +61,39 @@ snapshot_kind: text
"type": "VariableDeclaration"
},
{
"end": 47,
"end": 38,
"expression": {
"arguments": [
{
"type": "LabeledArg",
"label": {
"type": "Identifier",
"name": "map_fn"
},
"arg": {
"elements": [
{
"end": 42,
"raw": "0",
"start": 41,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
{
"end": 45,
"raw": "1",
"start": 44,
"type": "Literal",
"type": "Literal",
"value": 1.0
}
],
"end": 46,
"start": 40,
"type": "ArrayExpression",
"type": "ArrayExpression"
}
"end": 29,
"name": "f",
"start": 28,
"type": "Identifier",
"type": "Identifier"
},
{
"elements": [
{
"end": 33,
"raw": "0",
"start": 32,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
{
"end": 36,
"raw": "1",
"start": 35,
"type": "Literal",
"type": "Literal",
"value": 1.0
}
],
"end": 37,
"start": 31,
"type": "ArrayExpression",
"type": "ArrayExpression"
}
],
"callee": {
@ -104,24 +102,17 @@ snapshot_kind: text
"start": 24,
"type": "Identifier"
},
"end": 47,
"end": 38,
"start": 24,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"end": 29,
"name": "f",
"start": 28,
"type": "Identifier",
"type": "Identifier"
}
"type": "CallExpression",
"type": "CallExpression"
},
"start": 24,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 48,
"end": 39,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [

View File

@ -1,14 +1,12 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 133
description: Error from executing argument_error.kcl
snapshot_kind: text
---
KCL Semantic error
KCL Type error
× semantic: Expected an array to map, but got a value of type Function
╭─[5:1]
× type: Expected an array but found Function
╭─[5:5]
4 │
5 │ map(f, map_fn = [0, 1])
· ──────────────────────
5 │ map(f, [0, 1])
·
╰────

View File

@ -2,4 +2,4 @@ fn f(i) {
return 5
}
map(f, map_fn = [0, 1])
map(f, [0, 1])

View File

@ -1,8 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing array_elem_push.kcl
snapshot_kind: text
---
{
"Ok": {
@ -59,53 +57,46 @@ snapshot_kind: text
},
{
"declaration": {
"end": 45,
"end": 39,
"id": {
"end": 23,
"name": "newArr1",
"end": 24,
"name": "new_arr1",
"start": 16,
"type": "Identifier"
},
"init": {
"arguments": [
{
"type": "LabeledArg",
"label": {
"type": "Identifier",
"name": "elem"
},
"arg": {
"end": 44,
"raw": "4",
"start": 43,
"type": "Literal",
"type": "Literal",
"value": 4.0
}
"end": 35,
"name": "arr",
"start": 32,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 38,
"raw": "4",
"start": 37,
"type": "Literal",
"type": "Literal",
"value": 4.0
}
],
"callee": {
"end": 30,
"end": 31,
"name": "push",
"start": 26,
"start": 27,
"type": "Identifier"
},
"end": 45,
"start": 26,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"end": 34,
"name": "arr",
"start": 31,
"type": "Identifier",
"type": "Identifier"
}
"end": 39,
"start": 27,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 16,
"type": "VariableDeclarator"
},
"end": 45,
"end": 39,
"kind": "const",
"start": 16,
"type": "VariableDeclaration",
@ -113,654 +104,647 @@ snapshot_kind: text
},
{
"declaration": {
"end": 79,
"end": 68,
"id": {
"end": 53,
"name": "newArr2",
"start": 46,
"end": 48,
"name": "new_arr2",
"start": 40,
"type": "Identifier"
},
"init": {
"arguments": [
{
"type": "LabeledArg",
"label": {
"type": "Identifier",
"name": "elem"
},
"arg": {
"end": 78,
"raw": "5",
"start": 77,
"type": "Literal",
"type": "Literal",
"value": 5.0
}
"end": 64,
"name": "new_arr1",
"start": 56,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 67,
"raw": "5",
"start": 66,
"type": "Literal",
"type": "Literal",
"value": 5.0
}
],
"callee": {
"end": 60,
"end": 55,
"name": "push",
"start": 56,
"start": 51,
"type": "Identifier"
},
"end": 79,
"start": 56,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"end": 68,
"name": "newArr1",
"start": 61,
"type": "Identifier",
"type": "Identifier"
}
"end": 68,
"start": 51,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 46,
"start": 40,
"type": "VariableDeclarator"
},
"end": 79,
"end": 68,
"kind": "const",
"start": 46,
"start": 40,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 152,
"end": 142,
"expression": {
"arguments": [
{
"computed": false,
"end": 102,
"end": 92,
"object": {
"end": 99,
"name": "newArr1",
"start": 92,
"end": 89,
"name": "new_arr1",
"start": 81,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 101,
"end": 91,
"raw": "0",
"start": 100,
"start": 90,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
"start": 92,
"start": 81,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 105,
"end": 95,
"raw": "1",
"start": 104,
"start": 94,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
{
"end": 114,
"end": 104,
"raw": "0.00001",
"start": 107,
"start": 97,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 151,
"end": 141,
"raw": "\"element 0 should not have changed\"",
"start": 116,
"start": 106,
"type": "Literal",
"type": "Literal",
"value": "element 0 should not have changed"
}
],
"callee": {
"end": 91,
"end": 80,
"name": "assertEqual",
"start": 80,
"start": 69,
"type": "Identifier"
},
"end": 152,
"start": 80,
"end": 142,
"start": 69,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 80,
"start": 69,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 225,
"end": 216,
"expression": {
"arguments": [
{
"computed": false,
"end": 175,
"end": 166,
"object": {
"end": 172,
"name": "newArr1",
"start": 165,
"end": 163,
"name": "new_arr1",
"start": 155,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 174,
"end": 165,
"raw": "1",
"start": 173,
"start": 164,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
"start": 165,
"start": 155,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 169,
"raw": "2",
"start": 168,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 178,
"raw": "2",
"start": 177,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 187,
"raw": "0.00001",
"start": 180,
"start": 171,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 224,
"end": 215,
"raw": "\"element 1 should not have changed\"",
"start": 189,
"start": 180,
"type": "Literal",
"type": "Literal",
"value": "element 1 should not have changed"
}
],
"callee": {
"end": 164,
"end": 154,
"name": "assertEqual",
"start": 153,
"start": 143,
"type": "Identifier"
},
"end": 225,
"start": 153,
"end": 216,
"start": 143,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 153,
"start": 143,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 298,
"end": 290,
"expression": {
"arguments": [
{
"computed": false,
"end": 248,
"end": 240,
"object": {
"end": 245,
"name": "newArr1",
"start": 238,
"end": 237,
"name": "new_arr1",
"start": 229,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 247,
"end": 239,
"raw": "2",
"start": 246,
"start": 238,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
"start": 238,
"start": 229,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 251,
"end": 243,
"raw": "3",
"start": 250,
"start": 242,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
{
"end": 260,
"end": 252,
"raw": "0.00001",
"start": 253,
"start": 245,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 297,
"end": 289,
"raw": "\"element 2 should not have changed\"",
"start": 262,
"start": 254,
"type": "Literal",
"type": "Literal",
"value": "element 2 should not have changed"
}
],
"callee": {
"end": 237,
"end": 228,
"name": "assertEqual",
"start": 226,
"start": 217,
"type": "Identifier"
},
"end": 298,
"start": 226,
"end": 290,
"start": 217,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 226,
"start": 217,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 373,
"end": 366,
"expression": {
"arguments": [
{
"computed": false,
"end": 321,
"end": 314,
"object": {
"end": 318,
"name": "newArr1",
"start": 311,
"end": 311,
"name": "new_arr1",
"start": 303,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 320,
"end": 313,
"raw": "3",
"start": 319,
"start": 312,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
"start": 311,
"start": 303,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 324,
"end": 317,
"raw": "4",
"start": 323,
"start": 316,
"type": "Literal",
"type": "Literal",
"value": 4.0
},
{
"end": 333,
"end": 326,
"raw": "0.00001",
"start": 326,
"start": 319,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 372,
"end": 365,
"raw": "\"4 was added to the end of the array\"",
"start": 335,
"start": 328,
"type": "Literal",
"type": "Literal",
"value": "4 was added to the end of the array"
}
],
"callee": {
"end": 310,
"end": 302,
"name": "assertEqual",
"start": 299,
"start": 291,
"type": "Identifier"
},
"end": 373,
"start": 299,
"end": 366,
"start": 291,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 299,
"start": 291,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 446,
"end": 440,
"expression": {
"arguments": [
{
"computed": false,
"end": 396,
"end": 390,
"object": {
"end": 393,
"name": "newArr2",
"start": 386,
"end": 387,
"name": "new_arr2",
"start": 379,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 395,
"end": 389,
"raw": "0",
"start": 394,
"start": 388,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
"start": 386,
"start": 379,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 399,
"end": 393,
"raw": "1",
"start": 398,
"start": 392,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
{
"end": 408,
"end": 402,
"raw": "0.00001",
"start": 401,
"start": 395,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 445,
"end": 439,
"raw": "\"element 0 should not have changed\"",
"start": 410,
"start": 404,
"type": "Literal",
"type": "Literal",
"value": "element 0 should not have changed"
}
],
"callee": {
"end": 385,
"end": 378,
"name": "assertEqual",
"start": 374,
"start": 367,
"type": "Identifier"
},
"end": 446,
"start": 374,
"end": 440,
"start": 367,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 374,
"start": 367,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 519,
"end": 514,
"expression": {
"arguments": [
{
"computed": false,
"end": 469,
"end": 464,
"object": {
"end": 466,
"name": "newArr2",
"start": 459,
"end": 461,
"name": "new_arr2",
"start": 453,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 468,
"end": 463,
"raw": "1",
"start": 467,
"start": 462,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
"start": 459,
"start": 453,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 472,
"end": 467,
"raw": "2",
"start": 471,
"start": 466,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 481,
"end": 476,
"raw": "0.00001",
"start": 474,
"start": 469,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 518,
"end": 513,
"raw": "\"element 1 should not have changed\"",
"start": 483,
"start": 478,
"type": "Literal",
"type": "Literal",
"value": "element 1 should not have changed"
}
],
"callee": {
"end": 458,
"end": 452,
"name": "assertEqual",
"start": 447,
"start": 441,
"type": "Identifier"
},
"end": 519,
"start": 447,
"end": 514,
"start": 441,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 447,
"start": 441,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 592,
"end": 588,
"expression": {
"arguments": [
{
"computed": false,
"end": 542,
"end": 538,
"object": {
"end": 539,
"name": "newArr2",
"start": 532,
"end": 535,
"name": "new_arr2",
"start": 527,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 541,
"end": 537,
"raw": "2",
"start": 540,
"start": 536,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
"start": 532,
"start": 527,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 545,
"end": 541,
"raw": "3",
"start": 544,
"start": 540,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
{
"end": 554,
"end": 550,
"raw": "0.00001",
"start": 547,
"start": 543,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 591,
"end": 587,
"raw": "\"element 2 should not have changed\"",
"start": 556,
"start": 552,
"type": "Literal",
"type": "Literal",
"value": "element 2 should not have changed"
}
],
"callee": {
"end": 531,
"end": 526,
"name": "assertEqual",
"start": 520,
"start": 515,
"type": "Identifier"
},
"end": 592,
"start": 520,
"end": 588,
"start": 515,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 520,
"start": 515,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 667,
"end": 664,
"expression": {
"arguments": [
{
"computed": false,
"end": 615,
"end": 612,
"object": {
"end": 612,
"name": "newArr2",
"start": 605,
"end": 609,
"name": "new_arr2",
"start": 601,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 614,
"end": 611,
"raw": "3",
"start": 613,
"start": 610,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
"start": 605,
"start": 601,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 618,
"end": 615,
"raw": "4",
"start": 617,
"start": 614,
"type": "Literal",
"type": "Literal",
"value": 4.0
},
{
"end": 627,
"end": 624,
"raw": "0.00001",
"start": 620,
"start": 617,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 666,
"end": 663,
"raw": "\"4 was added to the end of the array\"",
"start": 629,
"start": 626,
"type": "Literal",
"type": "Literal",
"value": "4 was added to the end of the array"
}
],
"callee": {
"end": 604,
"end": 600,
"name": "assertEqual",
"start": 593,
"start": 589,
"type": "Identifier"
},
"end": 667,
"start": 593,
"end": 664,
"start": 589,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 593,
"start": 589,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 742,
"end": 740,
"expression": {
"arguments": [
{
"computed": false,
"end": 690,
"end": 688,
"object": {
"end": 687,
"name": "newArr2",
"start": 680,
"end": 685,
"name": "new_arr2",
"start": 677,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 689,
"end": 687,
"raw": "4",
"start": 688,
"start": 686,
"type": "Literal",
"type": "Literal",
"value": 4.0
},
"start": 680,
"start": 677,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 693,
"end": 691,
"raw": "5",
"start": 692,
"start": 690,
"type": "Literal",
"type": "Literal",
"value": 5.0
},
{
"end": 702,
"end": 700,
"raw": "0.00001",
"start": 695,
"start": 693,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 741,
"end": 739,
"raw": "\"5 was added to the end of the array\"",
"start": 704,
"start": 702,
"type": "Literal",
"type": "Literal",
"value": "5 was added to the end of the array"
}
],
"callee": {
"end": 679,
"end": 676,
"name": "assertEqual",
"start": 668,
"start": 665,
"type": "Identifier"
},
"end": 742,
"start": 668,
"end": 740,
"start": 665,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 668,
"start": 665,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 743,
"end": 741,
"start": 0
}
}

View File

@ -1,12 +1,12 @@
arr = [1, 2, 3]
newArr1 = push(arr, elem = 4)
newArr2 = push(newArr1, elem = 5)
assertEqual(newArr1[0], 1, 0.00001, "element 0 should not have changed")
assertEqual(newArr1[1], 2, 0.00001, "element 1 should not have changed")
assertEqual(newArr1[2], 3, 0.00001, "element 2 should not have changed")
assertEqual(newArr1[3], 4, 0.00001, "4 was added to the end of the array")
assertEqual(newArr2[0], 1, 0.00001, "element 0 should not have changed")
assertEqual(newArr2[1], 2, 0.00001, "element 1 should not have changed")
assertEqual(newArr2[2], 3, 0.00001, "element 2 should not have changed")
assertEqual(newArr2[3], 4, 0.00001, "4 was added to the end of the array")
assertEqual(newArr2[4], 5, 0.00001, "5 was added to the end of the array")
new_arr1 = push(arr, 4)
new_arr2 = push(new_arr1, 5)
assertEqual(new_arr1[0], 1, 0.00001, "element 0 should not have changed")
assertEqual(new_arr1[1], 2, 0.00001, "element 1 should not have changed")
assertEqual(new_arr1[2], 3, 0.00001, "element 2 should not have changed")
assertEqual(new_arr1[3], 4, 0.00001, "4 was added to the end of the array")
assertEqual(new_arr2[0], 1, 0.00001, "element 0 should not have changed")
assertEqual(new_arr2[1], 2, 0.00001, "element 1 should not have changed")
assertEqual(new_arr2[2], 3, 0.00001, "element 2 should not have changed")
assertEqual(new_arr2[3], 4, 0.00001, "4 was added to the end of the array")
assertEqual(new_arr2[4], 5, 0.00001, "5 was added to the end of the array")

View File

@ -1,6 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 99
assertion_line: 92
description: Program memory after executing array_elem_push.kcl
snapshot_kind: text
---
@ -81,7 +81,7 @@ snapshot_kind: text
}
]
},
"newArr1": {
"new_arr1": {
"type": "Array",
"value": [
{
@ -129,8 +129,8 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
43,
44,
37,
38,
0
]
}
@ -140,14 +140,14 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
26,
45,
27,
39,
0
]
}
]
},
"newArr2": {
"new_arr2": {
"type": "Array",
"value": [
{
@ -195,8 +195,8 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
43,
44,
37,
38,
0
]
}
@ -208,8 +208,8 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
77,
78,
66,
67,
0
]
}
@ -219,8 +219,8 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
56,
79,
51,
68,
0
]
}

View File

@ -1,8 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing array_elem_push_fail.kcl
snapshot_kind: text
---
{
"Ok": {
@ -59,7 +57,7 @@ snapshot_kind: text
},
{
"declaration": {
"end": 47,
"end": 40,
"id": {
"end": 25,
"name": "pushedArr",
@ -69,19 +67,19 @@ snapshot_kind: text
"init": {
"arguments": [
{
"type": "LabeledArg",
"label": {
"type": "Identifier",
"name": "elem"
},
"arg": {
"end": 46,
"raw": "4",
"start": 45,
"type": "Literal",
"type": "Literal",
"value": 4.0
}
"end": 36,
"name": "arr",
"start": 33,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 39,
"raw": "4",
"start": 38,
"type": "Literal",
"type": "Literal",
"value": 4.0
}
],
"callee": {
@ -90,22 +88,15 @@ snapshot_kind: text
"start": 28,
"type": "Identifier"
},
"end": 47,
"end": 40,
"start": 28,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"end": 36,
"name": "arr",
"start": 33,
"type": "Identifier",
"type": "Identifier"
}
"type": "CallExpression",
"type": "CallExpression"
},
"start": 16,
"type": "VariableDeclarator"
},
"end": 47,
"end": 40,
"kind": "const",
"start": 16,
"type": "VariableDeclaration",
@ -113,46 +104,46 @@ snapshot_kind: text
},
{
"declaration": {
"end": 61,
"end": 54,
"id": {
"end": 52,
"end": 45,
"name": "fail",
"start": 48,
"start": 41,
"type": "Identifier"
},
"init": {
"computed": false,
"end": 61,
"end": 54,
"object": {
"end": 58,
"end": 51,
"name": "arr",
"start": 55,
"start": 48,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 60,
"end": 53,
"raw": "3",
"start": 59,
"start": 52,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
"start": 55,
"start": 48,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 48,
"start": 41,
"type": "VariableDeclarator"
},
"end": 61,
"end": 54,
"kind": "const",
"start": 48,
"start": 41,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
}
],
"end": 62,
"end": 55,
"start": 0
}
}

View File

@ -1,14 +1,12 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 133
description: Error from executing array_elem_push_fail.kcl
snapshot_kind: text
---
KCL UndefinedValue error
× undefined value: The array doesn't have any item at index 3
╭─[3:8]
2 │ pushedArr = push(arr, elem = 4)
2 │ pushedArr = push(arr, 4)
3 │ fail = arr[3]
· ──────
╰────

View File

@ -1,3 +1,3 @@
arr = [1, 2, 3]
pushedArr = push(arr, elem = 4)
pushedArr = push(arr, 4)
fail = arr[3]

View File

@ -0,0 +1,284 @@
---
source: kcl/src/simulation_tests.rs
description: Artifact commands array_length.kcl
---
[
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.7,
"g": 0.28,
"b": 0.28,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.28,
"g": 0.7,
"b": 0.28,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.28,
"g": 0.28,
"b": 0.7,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": -1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 0.0,
"y": -1.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": -1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "edge_lines_visible",
"hidden": false
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "set_scene_units",
"unit": "mm"
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
}
]

View File

@ -0,0 +1,282 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_length.kcl
---
{
"Ok": {
"body": [
{
"declaration": {
"end": 15,
"id": {
"end": 3,
"name": "arr",
"start": 0,
"type": "Identifier"
},
"init": {
"elements": [
{
"end": 8,
"raw": "1",
"start": 7,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
{
"end": 11,
"raw": "2",
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 14,
"raw": "3",
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3.0
}
],
"end": 15,
"start": 6,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 15,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declaration": {
"end": 34,
"id": {
"end": 23,
"name": "arr_len",
"start": 16,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 33,
"name": "arr",
"start": 30,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 29,
"name": "len",
"start": 26,
"type": "Identifier"
},
"end": 34,
"start": 26,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 16,
"type": "VariableDeclarator"
},
"end": 34,
"kind": "const",
"start": 16,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 99,
"expression": {
"arguments": [
{
"end": 54,
"name": "arr_len",
"start": 47,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 57,
"raw": "3",
"start": 56,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
{
"end": 66,
"raw": "0.00001",
"start": 59,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 98,
"raw": "\"The length of the array is 3\"",
"start": 68,
"type": "Literal",
"type": "Literal",
"value": "The length of the array is 3"
}
],
"callee": {
"end": 46,
"name": "assertEqual",
"start": 35,
"type": "Identifier"
},
"end": 99,
"start": 35,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 35,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declaration": {
"end": 115,
"id": {
"end": 110,
"name": "arr_empty",
"start": 101,
"type": "Identifier"
},
"init": {
"elements": [],
"end": 115,
"start": 113,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 101,
"type": "VariableDeclarator"
},
"end": 115,
"kind": "const",
"start": 101,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declaration": {
"end": 142,
"id": {
"end": 125,
"name": "len_empty",
"start": 116,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 141,
"name": "arr_empty",
"start": 132,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 131,
"name": "len",
"start": 128,
"type": "Identifier"
},
"end": 142,
"start": 128,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 116,
"type": "VariableDeclarator"
},
"end": 142,
"kind": "const",
"start": 116,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 209,
"expression": {
"arguments": [
{
"end": 164,
"name": "len_empty",
"start": 155,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 167,
"raw": "0",
"start": 166,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
{
"end": 176,
"raw": "0.00001",
"start": 169,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 208,
"raw": "\"The length of the array is 0\"",
"start": 178,
"type": "Literal",
"type": "Literal",
"value": "The length of the array is 0"
}
],
"callee": {
"end": 154,
"name": "assertEqual",
"start": 143,
"type": "Identifier"
},
"end": 209,
"start": 143,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 143,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 210,
"nonCodeMeta": {
"nonCodeNodes": {
"2": [
{
"end": 101,
"start": 99,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": []
},
"start": 0
}
}

View File

@ -0,0 +1,7 @@
arr = [1, 2, 3]
arr_len = len(arr)
assertEqual(arr_len, 3, 0.00001, "The length of the array is 3")
arr_empty = []
len_empty = len(arr_empty)
assertEqual(len_empty, 0, 0.00001, "The length of the array is 0")

View File

@ -0,0 +1,5 @@
---
source: kcl/src/simulation_tests.rs
description: Operations executed array_length.kcl
---
[]

View File

@ -0,0 +1,127 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing array_length.kcl
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "Number",
"value": 180.0,
"__meta": []
},
"QUARTER_TURN": {
"type": "Number",
"value": 90.0,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "Number",
"value": 270.0,
"__meta": []
},
"ZERO": {
"type": "Number",
"value": 0.0,
"__meta": []
},
"arr": {
"type": "Array",
"value": [
{
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
7,
8,
0
]
}
]
},
{
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
10,
11,
0
]
}
]
},
{
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
13,
14,
0
]
}
]
}
],
"__meta": [
{
"sourceRange": [
6,
15,
0
]
}
]
},
"arr_empty": {
"type": "Array",
"value": [],
"__meta": [
{
"sourceRange": [
113,
115,
0
]
}
]
},
"arr_len": {
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
26,
34,
0
]
}
]
},
"len_empty": {
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
128,
142,
0
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -1,8 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing double_map_fn.kcl
snapshot_kind: text
---
{
"Ok": {
@ -119,7 +117,7 @@ snapshot_kind: text
},
{
"declaration": {
"end": 119,
"end": 101,
"id": {
"end": 50,
"name": "ys",
@ -138,18 +136,17 @@ snapshot_kind: text
{
"arguments": [
{
"type": "LabeledArg",
"label": {
"type": "Identifier",
"name": "map_fn"
},
"arg": {
"end": 86,
"name": "increment",
"start": 77,
"type": "Identifier",
"type": "Identifier"
}
"end": 66,
"start": 65,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
},
{
"end": 77,
"name": "increment",
"start": 68,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
@ -158,53 +155,40 @@ snapshot_kind: text
"start": 61,
"type": "Identifier"
},
"end": 87,
"end": 78,
"start": 61,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"end": 66,
"start": 65,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"type": "LabeledArg",
"label": {
"type": "Identifier",
"name": "map_fn"
},
"arg": {
"end": 118,
"name": "increment",
"start": 109,
"type": "Identifier",
"type": "Identifier"
}
"end": 89,
"start": 88,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
},
{
"end": 100,
"name": "increment",
"start": 91,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 96,
"end": 87,
"name": "map",
"start": 93,
"start": 84,
"type": "Identifier"
},
"end": 119,
"start": 93,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"end": 98,
"start": 97,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
"end": 101,
"start": 84,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 119,
"end": 101,
"start": 53,
"type": "PipeExpression",
"type": "PipeExpression"
@ -212,14 +196,14 @@ snapshot_kind: text
"start": 48,
"type": "VariableDeclarator"
},
"end": 119,
"end": 101,
"kind": "const",
"start": 48,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
}
],
"end": 120,
"end": 102,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [

View File

@ -4,5 +4,5 @@ fn increment(i) {
xs = [0..2]
ys = xs
|> map(%, map_fn = increment)
|> map(%, map_fn = increment)
|> map(%, increment)
|> map(%, increment)

View File

@ -1,6 +1,5 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 99
description: Program memory after executing double_map_fn.kcl
snapshot_kind: text
---
@ -262,8 +261,8 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
93,
119,
84,
101,
0
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1169,25 +1169,25 @@ async fn kcl_test_plumbus_fillets() {
return sg
}
fn pentagon = (len) => {
fn pentagon = (sideLen) => {
sg = startSketchOn('XY')
|> startProfileAt([-len / 2, -len / 2], %)
|> angledLine({ angle: 0, length: len }, %, $a)
|> startProfileAt([-sideLen / 2, -sideLen / 2], %)
|> angledLine({ angle: 0, length: sideLen }, %, $a)
|> angledLine({
angle: segAng(a) + 180 - 108,
length: len
length: sideLen
}, %, $b)
|> angledLine({
angle: segAng(b) + 180 - 108,
length: len
length: sideLen
}, %, $c)
|> angledLine({
angle: segAng(c) + 180 - 108,
length: len
length: sideLen
}, %, $d)
|> angledLine({
angle: segAng(d) + 180 - 108,
length: len
length: sideLen
}, %)
return sg
@ -1653,17 +1653,17 @@ part001 = cube([0,0], 20)
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_duplicate_tags_should_error() {
let code = r#"fn triangle = (len) => {
let code = r#"fn triangle = (sideLen) => {
return startSketchOn('XY')
|> startProfileAt([-len / 2, -len / 2], %)
|> angledLine({ angle: 0, length: len }, %, $a)
|> startProfileAt([-sideLen / 2, -sideLen / 2], %)
|> angledLine({ angle: 0, length: sideLen }, %, $a)
|> angledLine({
angle: segAng(a) + 120,
length: len
length: sideLen
}, %, $b)
|> angledLine({
angle: segAng(b) + 120,
length: len
length: sideLen
}, %, $a)
}
@ -1674,7 +1674,7 @@ let p = triangle(200)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([311, 313, 0]), SourceRange([326, 339, 0])], message: "Cannot redefine `a`" }"#
r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([335, 337, 0]), SourceRange([350, 363, 0])], message: "Cannot redefine `a`" }"#
);
}