Kwargs: assert functions (#6406)

Closes https://github.com/KittyCAD/modeling-app/issues/6408
This commit is contained in:
Adam Chalmers
2025-04-22 12:44:52 -05:00
committed by GitHub
parent 8be36d3d16
commit f99e44e371
73 changed files with 4790 additions and 4034 deletions

View File

@ -167,53 +167,45 @@ description: Result of parsing computed_var.kcl
"expression": {
"arguments": [
{
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "ten",
"name": "isEqualTo",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
},
{
"commentStart": 0,
"end": 0,
"raw": "10",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 10.0,
"suffix": "None"
"arg": {
"commentStart": 0,
"end": 0,
"raw": "10",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 10.0,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"raw": "0.000001",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.000001,
"suffix": "None"
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "error",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "\"oops\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops"
}
},
{
"commentStart": 0,
"end": 0,
"raw": "\"oops\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops"
}
],
"callee": {
@ -223,7 +215,7 @@ description: Result of parsing computed_var.kcl
"name": {
"commentStart": 0,
"end": 0,
"name": "assertEqual",
"name": "assert",
"start": 0,
"type": "Identifier"
},
@ -234,8 +226,24 @@ description: Result of parsing computed_var.kcl
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "ten",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
}
},
"start": 0,
"type": "ExpressionStatement",
@ -402,53 +410,45 @@ description: Result of parsing computed_var.kcl
"expression": {
"arguments": [
{
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "one",
"name": "isEqualTo",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
},
{
"commentStart": 0,
"end": 0,
"raw": "1",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 1.0,
"suffix": "None"
"arg": {
"commentStart": 0,
"end": 0,
"raw": "1",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 1.0,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"raw": "0.0000001",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.0000001,
"suffix": "None"
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "error",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "\"oops\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops"
}
},
{
"commentStart": 0,
"end": 0,
"raw": "\"oops\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops"
}
],
"callee": {
@ -458,7 +458,7 @@ description: Result of parsing computed_var.kcl
"name": {
"commentStart": 0,
"end": 0,
"name": "assertEqual",
"name": "assert",
"start": 0,
"type": "Identifier"
},
@ -469,8 +469,24 @@ description: Result of parsing computed_var.kcl
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "one",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
}
},
"start": 0,
"type": "ExpressionStatement",
@ -482,53 +498,67 @@ description: Result of parsing computed_var.kcl
"expression": {
"arguments": [
{
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "PI",
"name": "isEqualTo",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
},
{
"commentStart": 0,
"end": 0,
"raw": "3",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 3.0,
"suffix": "None"
"arg": {
"commentStart": 0,
"end": 0,
"raw": "3",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 3.0,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"raw": "0.2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.2,
"suffix": "None"
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "tolerance",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "0.2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.2,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"raw": "\"oops pi\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops pi"
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "error",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "\"oops pi\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops pi"
}
}
],
"callee": {
@ -538,7 +568,7 @@ description: Result of parsing computed_var.kcl
"name": {
"commentStart": 0,
"end": 0,
"name": "assertEqual",
"name": "assert",
"start": 0,
"type": "Identifier"
},
@ -549,8 +579,24 @@ description: Result of parsing computed_var.kcl
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "PI",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
}
},
"start": 0,
"type": "ExpressionStatement",
@ -643,53 +689,67 @@ description: Result of parsing computed_var.kcl
"expression": {
"arguments": [
{
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "x",
"name": "isEqualTo",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
},
{
"commentStart": 0,
"end": 0,
"raw": "1",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 1.0,
"suffix": "None"
"arg": {
"commentStart": 0,
"end": 0,
"raw": "1",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 1.0,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"raw": "0.000001",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.000001,
"suffix": "None"
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "tolerance",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "0.000001",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.000001,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"raw": "\"oops cos\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops cos"
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "error",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "\"oops cos\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "oops cos"
}
}
],
"callee": {
@ -699,7 +759,7 @@ description: Result of parsing computed_var.kcl
"name": {
"commentStart": 0,
"end": 0,
"name": "assertEqual",
"name": "assert",
"start": 0,
"type": "Identifier"
},
@ -710,8 +770,24 @@ description: Result of parsing computed_var.kcl
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "x",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name",
"type": "Name"
}
},
"start": 0,
"type": "ExpressionStatement",
@ -765,6 +841,17 @@ description: Result of parsing computed_var.kcl
"type": "newLine"
}
}
],
"8": [
{
"commentStart": 0,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": [

View File

@ -5,14 +5,15 @@ arr = [0, 0, 0, 10]
i = 3
ten = arr[i]
assertEqual(ten, 10, 0.000001, "oops")
assert(ten, isEqualTo = 10, error = "oops")
p = "foo"
obj = { foo = 1, bar = 0 }
one = obj[p]
assertEqual(one, 1, 0.0000001, "oops")
assert(one, isEqualTo = 1, error = "oops")
assert(PI, isEqualTo = 3, tolerance = 0.2, error = "oops pi")
assertEqual(PI, 3, 0.2, "oops pi")
x = cos(2 * PI)
assertEqual(x, 1, 0.000001, "oops cos")
assert(x, isEqualTo = 1, tolerance = 0.000001, error = "oops cos")

View File

@ -9,14 +9,25 @@ arr = [0, 0, 0, 10]
i = 3
ten = arr[i]
assertEqual(ten, 10, 0.000001, "oops")
assert(ten, isEqualTo = 10, error = "oops")
p = "foo"
obj = { foo = 1, bar = 0 }
one = obj[p]
assertEqual(one, 1, 0.0000001, "oops")
assert(one, isEqualTo = 1, error = "oops")
assert(
PI,
isEqualTo = 3,
tolerance = 0.2,
error = "oops pi",
)
assertEqual(PI, 3, 0.2, "oops pi")
x = cos(2 * PI)
assertEqual(x, 1, 0.000001, "oops cos")
assert(
x,
isEqualTo = 1,
tolerance = 0.000001,
error = "oops cos",
)