Compare commits
5 Commits
v0.24.9
...
franknoiro
Author | SHA1 | Date | |
---|---|---|---|
e1da72a0ae | |||
ec2d1999a7 | |||
95683f1cc1 | |||
f48f1c21c1 | |||
5cdf2de89a |
12
.github/workflows/ci.yml
vendored
@ -89,20 +89,16 @@ jobs:
|
|||||||
- run: yarn build:wasm
|
- run: yarn build:wasm
|
||||||
|
|
||||||
- run: yarn simpleserver:ci
|
- run: yarn simpleserver:ci
|
||||||
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
|
|
||||||
|
|
||||||
- name: Install Chromium Browser
|
- name: Install Chromium Browser
|
||||||
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
|
|
||||||
run: yarn playwright install chromium --with-deps
|
run: yarn playwright install chromium --with-deps
|
||||||
|
|
||||||
- name: run unit tests
|
- name: run unit tests
|
||||||
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
|
|
||||||
run: yarn test:nowatch
|
run: yarn test:nowatch
|
||||||
env:
|
env:
|
||||||
VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
|
VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
|
||||||
|
|
||||||
- name: check for changes
|
- name: check for changes
|
||||||
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
|
|
||||||
id: git-check
|
id: git-check
|
||||||
run: |
|
run: |
|
||||||
git add src/lang/std/artifactMapGraphs
|
git add src/lang/std/artifactMapGraphs
|
||||||
@ -111,7 +107,7 @@ jobs:
|
|||||||
else echo "modified=false" >> $GITHUB_OUTPUT
|
else echo "modified=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
- name: Commit changes, if any
|
- name: Commit changes, if any
|
||||||
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' && steps.git-check.outputs.modified == 'true' }}
|
if: steps.git-check.outputs.modified == 'true'
|
||||||
run: |
|
run: |
|
||||||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git config --local user.name "github-actions[bot]"
|
git config --local user.name "github-actions[bot]"
|
||||||
@ -535,7 +531,7 @@ jobs:
|
|||||||
project_id: kittycadapi
|
project_id: kittycadapi
|
||||||
|
|
||||||
- name: Upload release files to public bucket
|
- name: Upload release files to public bucket
|
||||||
uses: google-github-actions/upload-cloud-storage@v2.1.1
|
uses: google-github-actions/upload-cloud-storage@v2.1.0
|
||||||
with:
|
with:
|
||||||
path: artifact
|
path: artifact
|
||||||
glob: '*/Zoo*'
|
glob: '*/Zoo*'
|
||||||
@ -543,13 +539,13 @@ jobs:
|
|||||||
destination: ${{ env.BUCKET_DIR }}/${{ env.VERSION }}
|
destination: ${{ env.BUCKET_DIR }}/${{ env.VERSION }}
|
||||||
|
|
||||||
- name: Upload update endpoint to public bucket
|
- name: Upload update endpoint to public bucket
|
||||||
uses: google-github-actions/upload-cloud-storage@v2.1.1
|
uses: google-github-actions/upload-cloud-storage@v2.1.0
|
||||||
with:
|
with:
|
||||||
path: last_update.json
|
path: last_update.json
|
||||||
destination: ${{ env.BUCKET_DIR }}
|
destination: ${{ env.BUCKET_DIR }}
|
||||||
|
|
||||||
- name: Upload download endpoint to public bucket
|
- name: Upload download endpoint to public bucket
|
||||||
uses: google-github-actions/upload-cloud-storage@v2.1.1
|
uses: google-github-actions/upload-cloud-storage@v2.1.0
|
||||||
with:
|
with:
|
||||||
path: last_download.json
|
path: last_download.json
|
||||||
destination: ${{ env.BUCKET_DIR }}
|
destination: ${{ env.BUCKET_DIR }}
|
||||||
|
@ -21,7 +21,6 @@ layout: manual
|
|||||||
* [`arc`](kcl/arc)
|
* [`arc`](kcl/arc)
|
||||||
* [`asin`](kcl/asin)
|
* [`asin`](kcl/asin)
|
||||||
* [`assert`](kcl/assert)
|
* [`assert`](kcl/assert)
|
||||||
* [`assertEqual`](kcl/assertEqual)
|
|
||||||
* [`assertGreaterThan`](kcl/assertGreaterThan)
|
* [`assertGreaterThan`](kcl/assertGreaterThan)
|
||||||
* [`assertGreaterThanOrEq`](kcl/assertGreaterThanOrEq)
|
* [`assertGreaterThanOrEq`](kcl/assertGreaterThanOrEq)
|
||||||
* [`assertLessThan`](kcl/assertLessThan)
|
* [`assertLessThan`](kcl/assertLessThan)
|
||||||
|
@ -54791,62 +54791,6 @@
|
|||||||
"const myVar = true\nassert(myVar, \"should always be true\")"
|
"const myVar = true\nassert(myVar, \"should always be true\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "assertEqual",
|
|
||||||
"summary": "Check that a numerical value equals another at runtime,",
|
|
||||||
"description": "otherwise raise an error.",
|
|
||||||
"tags": [],
|
|
||||||
"args": [
|
|
||||||
{
|
|
||||||
"name": "left",
|
|
||||||
"type": "number",
|
|
||||||
"schema": {
|
|
||||||
"type": "number",
|
|
||||||
"format": "double"
|
|
||||||
},
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "right",
|
|
||||||
"type": "number",
|
|
||||||
"schema": {
|
|
||||||
"type": "number",
|
|
||||||
"format": "double"
|
|
||||||
},
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "epsilon",
|
|
||||||
"type": "number",
|
|
||||||
"schema": {
|
|
||||||
"type": "number",
|
|
||||||
"format": "double"
|
|
||||||
},
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "message",
|
|
||||||
"type": "string",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"returnValue": {
|
|
||||||
"name": "",
|
|
||||||
"type": "()",
|
|
||||||
"schema": {
|
|
||||||
"type": "null"
|
|
||||||
},
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"unpublished": false,
|
|
||||||
"deprecated": false,
|
|
||||||
"examples": [
|
|
||||||
"let n = 1.0285\nlet m = 1.0286\nassertEqual(n, m, 0.01, \"n is within the given tolerance for m\")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "assertGreaterThan",
|
"name": "assertGreaterThan",
|
||||||
"summary": "Check that a numerical value is greater than another at runtime,",
|
"summary": "Check that a numerical value is greater than another at runtime,",
|
||||||
@ -223491,7 +223435,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "xLine",
|
"name": "xLine",
|
||||||
"summary": "Draw a line parallel to the X-axis, with the given length.",
|
"summary": "Draw a line on the x-axis.",
|
||||||
"description": "",
|
"description": "",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"args": [
|
"args": [
|
||||||
@ -230125,8 +230069,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "xLineTo",
|
"name": "xLineTo",
|
||||||
"summary": "Draw a line parallel to the X axis, that ends at the given X.",
|
"summary": "Draw a line to a point on the x-axis.",
|
||||||
"description": "E.g. if the previous line ended at (1, 1), then xLineTo(4) draws a line from (1, 1) to (4, 1)",
|
"description": "",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"args": [
|
"args": [
|
||||||
{
|
{
|
||||||
@ -236759,7 +236703,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "yLine",
|
"name": "yLine",
|
||||||
"summary": "Draw a line parallel to the Y-axis, with the given length.",
|
"summary": "Draw a line on the y-axis.",
|
||||||
"description": "",
|
"description": "",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"args": [
|
"args": [
|
||||||
@ -243393,8 +243337,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "yLineTo",
|
"name": "yLineTo",
|
||||||
"summary": "Draw a line parallel to the Y axis, that ends at the given Y.",
|
"summary": "Draw a line to a point on the y-axis.",
|
||||||
"description": "E.g. if the previous line ended at (1, 1), then yLineTo(4) draws a line from (1, 1) to (1, 4)",
|
"description": "",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"args": [
|
"args": [
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
---
|
---
|
||||||
title: "xLine"
|
title: "xLine"
|
||||||
excerpt: "Draw a line parallel to the X-axis, with the given length."
|
excerpt: "Draw a line on the x-axis."
|
||||||
layout: manual
|
layout: manual
|
||||||
---
|
---
|
||||||
|
|
||||||
Draw a line parallel to the X-axis, with the given length.
|
Draw a line on the x-axis.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: "xLineTo"
|
title: "xLineTo"
|
||||||
excerpt: "Draw a line parallel to the X axis, that ends at the given X."
|
excerpt: "Draw a line to a point on the x-axis."
|
||||||
layout: manual
|
layout: manual
|
||||||
---
|
---
|
||||||
|
|
||||||
Draw a line parallel to the X axis, that ends at the given X.
|
Draw a line to a point on the x-axis.
|
||||||
|
|
||||||
|
|
||||||
E.g. if the previous line ended at (1, 1), then xLineTo(4) draws a line from (1, 1) to (4, 1)
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
xLineTo(to: number, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup
|
xLineTo(to: number, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
---
|
---
|
||||||
title: "yLine"
|
title: "yLine"
|
||||||
excerpt: "Draw a line parallel to the Y-axis, with the given length."
|
excerpt: "Draw a line on the y-axis."
|
||||||
layout: manual
|
layout: manual
|
||||||
---
|
---
|
||||||
|
|
||||||
Draw a line parallel to the Y-axis, with the given length.
|
Draw a line on the y-axis.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: "yLineTo"
|
title: "yLineTo"
|
||||||
excerpt: "Draw a line parallel to the Y axis, that ends at the given Y."
|
excerpt: "Draw a line to a point on the y-axis."
|
||||||
layout: manual
|
layout: manual
|
||||||
---
|
---
|
||||||
|
|
||||||
Draw a line parallel to the Y axis, that ends at the given Y.
|
Draw a line to a point on the y-axis.
|
||||||
|
|
||||||
|
|
||||||
E.g. if the previous line ended at (1, 1), then yLineTo(4) draws a line from (1, 1) to (1, 4)
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
yLineTo(to: number, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup
|
yLineTo(to: number, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup
|
||||||
|
@ -46,9 +46,9 @@ document.addEventListener('mousemove', (e) =>
|
|||||||
const deg = (Math.PI * 2) / 360
|
const deg = (Math.PI * 2) / 360
|
||||||
|
|
||||||
const commonPoints = {
|
const commonPoints = {
|
||||||
startAt: '[7.19, -9.7]',
|
startAt: '[0.75, -1.01]',
|
||||||
num1: 7.25,
|
num1: 0.75,
|
||||||
num2: 14.44,
|
num2: 1.5,
|
||||||
}
|
}
|
||||||
|
|
||||||
test.afterEach(async ({ context, page }, testInfo) => {
|
test.afterEach(async ({ context, page }, testInfo) => {
|
||||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 29 KiB |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "untitled-app",
|
"name": "untitled-app",
|
||||||
"version": "0.24.9",
|
"version": "0.24.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/autocomplete": "^6.17.0",
|
"@codemirror/autocomplete": "^6.17.0",
|
||||||
|
@ -80,5 +80,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"productName": "Zoo Modeling App",
|
"productName": "Zoo Modeling App",
|
||||||
"version": "0.24.9"
|
"version": "0.24.8"
|
||||||
}
|
}
|
||||||
|
@ -791,7 +791,6 @@ export function isSingleCursorInPipe(
|
|||||||
const pathToNode = getNodePathFromSourceRange(ast, selection.range)
|
const pathToNode = getNodePathFromSourceRange(ast, selection.range)
|
||||||
const nodeTypes = pathToNode.map(([, type]) => type)
|
const nodeTypes = pathToNode.map(([, type]) => type)
|
||||||
if (nodeTypes.includes('FunctionExpression')) return false
|
if (nodeTypes.includes('FunctionExpression')) return false
|
||||||
if (!nodeTypes.includes('VariableDeclaration')) return false
|
|
||||||
if (nodeTypes.includes('PipeExpression')) return true
|
if (nodeTypes.includes('PipeExpression')) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -458,9 +458,6 @@ async function GraphTheGraph(
|
|||||||
await page.waitForSelector('#plotly-graph')
|
await page.waitForSelector('#plotly-graph')
|
||||||
const element = await page.$('#plotly-graph')
|
const element = await page.$('#plotly-graph')
|
||||||
|
|
||||||
// wait an extra bit for things to settle
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
await element.screenshot({
|
await element.screenshot({
|
||||||
path: `./e2e/playwright/temp3.png`,
|
path: `./e2e/playwright/temp3.png`,
|
||||||
|
@ -1064,16 +1064,7 @@ export const modelingMachine = createMachine(
|
|||||||
sketchPlaneId: '',
|
sketchPlaneId: '',
|
||||||
}),
|
}),
|
||||||
'reset camera position': () =>
|
'reset camera position': () =>
|
||||||
engineCommandManager.sendSceneCommand({
|
sceneInfra.camControls.resetCameraPosition(),
|
||||||
type: 'modeling_cmd_req',
|
|
||||||
cmd_id: uuidv4(),
|
|
||||||
cmd: {
|
|
||||||
type: 'default_camera_look_at',
|
|
||||||
center: { x: 0, y: 0, z: 0 },
|
|
||||||
vantage: { x: 0, y: -1250, z: 580 },
|
|
||||||
up: { x: 0, y: 0, z: 1 },
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
'set new sketch metadata': assign((_, { data }) => ({
|
'set new sketch metadata': assign((_, { data }) => ({
|
||||||
sketchDetails: data,
|
sketchDetails: data,
|
||||||
})),
|
})),
|
||||||
|
@ -2862,7 +2862,7 @@ impl MemberExpression {
|
|||||||
// Actually evaluate memory to compute the property.
|
// Actually evaluate memory to compute the property.
|
||||||
let prop = memory.get(&name, property_src)?;
|
let prop = memory.get(&name, property_src)?;
|
||||||
let MemoryItem::UserVal(prop) = prop else {
|
let MemoryItem::UserVal(prop) = prop else {
|
||||||
return Err(KclError::Semantic(KclErrorDetails {
|
return Err(KclError::Syntax(KclErrorDetails {
|
||||||
source_ranges: property_sr,
|
source_ranges: property_sr,
|
||||||
message: format!(
|
message: format!(
|
||||||
"{name} is not a valid property/index, you can only use a string or int (>= 0) here",
|
"{name} is not a valid property/index, you can only use a string or int (>= 0) here",
|
||||||
@ -2876,17 +2876,17 @@ impl MemberExpression {
|
|||||||
.and_then(|x| usize::try_from(x).ok())
|
.and_then(|x| usize::try_from(x).ok())
|
||||||
.map(Property::Number)
|
.map(Property::Number)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
KclError::Semantic(KclErrorDetails {
|
KclError::Syntax(KclErrorDetails {
|
||||||
source_ranges: property_sr,
|
source_ranges: property_sr,
|
||||||
message: format!(
|
message: format!(
|
||||||
"{name}'s value is not a valid property/index, you can only use a string or int (>= 0) here",
|
"{name} is not a valid property/index, you can only use a string or int (>= 0) here",
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
JValue::String(ref x) => Property::String(x.to_owned()),
|
JValue::String(ref x) => Property::String(x.to_owned()),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(KclError::Semantic(KclErrorDetails {
|
return Err(KclError::Syntax(KclErrorDetails {
|
||||||
source_ranges: property_sr,
|
source_ranges: property_sr,
|
||||||
message: format!(
|
message: format!(
|
||||||
"{name} is not a valid property/index, you can only use a string to get the property of an object, or an int (>= 0) to get an item in an array",
|
"{name} is not a valid property/index, you can only use a string to get the property of an object, or an int (>= 0) to get an item in an array",
|
||||||
@ -2903,7 +2903,7 @@ impl MemberExpression {
|
|||||||
if let Ok(x) = u64::try_from(x) {
|
if let Ok(x) = u64::try_from(x) {
|
||||||
Property::Number(x.try_into().unwrap())
|
Property::Number(x.try_into().unwrap())
|
||||||
} else {
|
} else {
|
||||||
return Err(KclError::Semantic(KclErrorDetails {
|
return Err(KclError::Syntax(KclErrorDetails {
|
||||||
source_ranges: property_sr,
|
source_ranges: property_sr,
|
||||||
message: format!("{x} is not a valid index, indices must be whole numbers >= 0"),
|
message: format!("{x} is not a valid index, indices must be whole numbers >= 0"),
|
||||||
}));
|
}));
|
||||||
@ -2911,7 +2911,7 @@ impl MemberExpression {
|
|||||||
}
|
}
|
||||||
LiteralValue::String(s) => Property::String(s),
|
LiteralValue::String(s) => Property::String(s),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(KclError::Semantic(KclErrorDetails {
|
return Err(KclError::Syntax(KclErrorDetails {
|
||||||
source_ranges: vec![self.into()],
|
source_ranges: vec![self.into()],
|
||||||
message: "Only strings or ints (>= 0) can be properties/indexes".to_owned(),
|
message: "Only strings or ints (>= 0) can be properties/indexes".to_owned(),
|
||||||
}));
|
}));
|
||||||
@ -2943,7 +2943,7 @@ impl MemberExpression {
|
|||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Err(KclError::UndefinedValue(KclErrorDetails {
|
Err(KclError::UndefinedValue(KclErrorDetails {
|
||||||
message: format!("Property '{property}' not found in object"),
|
message: format!("Property {property} not found in object"),
|
||||||
source_ranges: vec![self.clone().into()],
|
source_ranges: vec![self.clone().into()],
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -2978,13 +2978,10 @@ impl MemberExpression {
|
|||||||
),
|
),
|
||||||
source_ranges: vec![self.clone().into()],
|
source_ranges: vec![self.clone().into()],
|
||||||
})),
|
})),
|
||||||
(being_indexed, _) => {
|
(_, _) => Err(KclError::Semantic(KclErrorDetails {
|
||||||
let t = human_friendly_type(being_indexed);
|
message: "Only arrays and objects can be indexed".to_owned(),
|
||||||
Err(KclError::Semantic(KclErrorDetails {
|
|
||||||
message: format!("Only arrays and objects can be indexed, but you're trying to index a {t}"),
|
|
||||||
source_ranges: vec![self.clone().into()],
|
source_ranges: vec![self.clone().into()],
|
||||||
}))
|
})),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4073,17 +4070,6 @@ impl ConstraintLevels {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn human_friendly_type(j: JValue) -> &'static str {
|
|
||||||
match j {
|
|
||||||
JValue::Null => "null",
|
|
||||||
JValue::Bool(_) => "boolean (true/false value)",
|
|
||||||
JValue::Number(_) => "number",
|
|
||||||
JValue::String(_) => "string (text)",
|
|
||||||
JValue::Array(_) => "array (list)",
|
|
||||||
JValue::Object(_) => "object",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
@ -67,27 +67,6 @@ pub async fn assert_gt(args: Args) -> Result<MemoryItem, KclError> {
|
|||||||
args.make_null_user_val()
|
args.make_null_user_val()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check that a numerical value equals another at runtime,
|
|
||||||
/// otherwise raise an error.
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// let n = 1.0285
|
|
||||||
/// let m = 1.0286
|
|
||||||
/// assertEqual(n, m, 0.01, "n is within the given tolerance for m")
|
|
||||||
/// ```
|
|
||||||
#[stdlib {
|
|
||||||
name = "assertEqual",
|
|
||||||
}]
|
|
||||||
async fn inner_assert_equal(left: f64, right: f64, epsilon: f64, message: &str, args: &Args) -> Result<(), KclError> {
|
|
||||||
_assert((right - left).abs() < epsilon, message, args).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn assert_equal(args: Args) -> Result<MemoryItem, KclError> {
|
|
||||||
let (left, right, epsilon, description): (f64, f64, f64, String) = args.get_data()?;
|
|
||||||
inner_assert_equal(left, right, epsilon, &description, &args).await?;
|
|
||||||
args.make_null_user_val()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that a numerical value is greater than another at runtime,
|
/// Check that a numerical value is greater than another at runtime,
|
||||||
/// otherwise raise an error.
|
/// otherwise raise an error.
|
||||||
///
|
///
|
||||||
|
@ -120,7 +120,6 @@ lazy_static! {
|
|||||||
Box::new(crate::std::math::ToRadians),
|
Box::new(crate::std::math::ToRadians),
|
||||||
Box::new(crate::std::polar::Polar),
|
Box::new(crate::std::polar::Polar),
|
||||||
Box::new(crate::std::assert::Assert),
|
Box::new(crate::std::assert::Assert),
|
||||||
Box::new(crate::std::assert::AssertEqual),
|
|
||||||
Box::new(crate::std::assert::AssertLessThan),
|
Box::new(crate::std::assert::AssertLessThan),
|
||||||
Box::new(crate::std::assert::AssertGreaterThan),
|
Box::new(crate::std::assert::AssertGreaterThan),
|
||||||
Box::new(crate::std::assert::AssertLessThanOrEq),
|
Box::new(crate::std::assert::AssertLessThanOrEq),
|
||||||
|
@ -168,9 +168,7 @@ pub async fn x_line_to(args: Args) -> Result<MemoryItem, KclError> {
|
|||||||
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw a line parallel to the X axis, that ends at the given X.
|
/// Draw a line to a point on the x-axis.
|
||||||
/// E.g. if the previous line ended at (1, 1),
|
|
||||||
/// then xLineTo(4) draws a line from (1, 1) to (4, 1)
|
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// const exampleSketch = startSketchOn('XZ')
|
/// const exampleSketch = startSketchOn('XZ')
|
||||||
@ -216,9 +214,7 @@ pub async fn y_line_to(args: Args) -> Result<MemoryItem, KclError> {
|
|||||||
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw a line parallel to the Y axis, that ends at the given Y.
|
/// Draw a line to a point on the y-axis.
|
||||||
/// E.g. if the previous line ended at (1, 1),
|
|
||||||
/// then yLineTo(4) draws a line from (1, 1) to (1, 4)
|
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// const exampleSketch = startSketchOn("XZ")
|
/// const exampleSketch = startSketchOn("XZ")
|
||||||
@ -340,7 +336,7 @@ pub async fn x_line(args: Args) -> Result<MemoryItem, KclError> {
|
|||||||
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw a line parallel to the X-axis, with the given length.
|
/// Draw a line on the x-axis.
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// const exampleSketch = startSketchOn('XZ')
|
/// const exampleSketch = startSketchOn('XZ')
|
||||||
@ -382,7 +378,7 @@ pub async fn y_line(args: Args) -> Result<MemoryItem, KclError> {
|
|||||||
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw a line parallel to the Y-axis, with the given length.
|
/// Draw a line on the y-axis.
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// const exampleSketch = startSketchOn('XZ')
|
/// const exampleSketch = startSketchOn('XZ')
|
||||||
|
Before Width: | Height: | Size: 70 KiB |
@ -4,7 +4,8 @@ const arr = [0, 0, 0, 10]
|
|||||||
const i = 3
|
const i = 3
|
||||||
const ten = arr[i]
|
const ten = arr[i]
|
||||||
|
|
||||||
assertEqual(ten, 10, 0.000001, "oops")
|
assertLessThanOrEq(ten, 10, "oops")
|
||||||
|
assertGreaterThanOrEq(ten, 10, "oops2")
|
||||||
|
|
||||||
const p = "foo"
|
const p = "foo"
|
||||||
const obj = {
|
const obj = {
|
||||||
@ -13,4 +14,5 @@ const obj = {
|
|||||||
}
|
}
|
||||||
const one = obj[p]
|
const one = obj[p]
|
||||||
|
|
||||||
assertEqual(one, 1, 0.0000001, "oops")
|
assertLessThanOrEq(one, 1, "oops")
|
||||||
|
assertGreaterThanOrEq(one, 1, "oops2")
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
let arr = []
|
|
||||||
let x = arr[0]
|
|
@ -1,18 +0,0 @@
|
|||||||
// This tests indexing an array.
|
|
||||||
|
|
||||||
const array = [90, 91, 92]
|
|
||||||
|
|
||||||
// Test: literal index.
|
|
||||||
|
|
||||||
const result0 = array[1]
|
|
||||||
|
|
||||||
assertLessThanOrEq(result0, 91, "Literal property lookup")
|
|
||||||
assertGreaterThanOrEq(result0, 91, "Literal property lookup")
|
|
||||||
|
|
||||||
// Test: computed index.
|
|
||||||
|
|
||||||
const i = int(1 + 0)
|
|
||||||
const result1 = array[i]
|
|
||||||
|
|
||||||
assertLessThanOrEq(result1, 91, "Computed property lookup")
|
|
||||||
assertGreaterThanOrEq(result1, 91, "Computed property lookup")
|
|
@ -1,2 +0,0 @@
|
|||||||
let arr = [1, 2, 3]
|
|
||||||
let x = arr[1.2]
|
|
@ -1,3 +0,0 @@
|
|||||||
let arr = [1, 2, 3]
|
|
||||||
let i = -1
|
|
||||||
let x = arr[i]
|
|
@ -1,2 +0,0 @@
|
|||||||
let arr = [1, 2, 3]
|
|
||||||
let x = arr["s"]
|
|
@ -1,2 +0,0 @@
|
|||||||
let num = 999
|
|
||||||
let x = num[3]
|
|
@ -1,2 +0,0 @@
|
|||||||
let b = true
|
|
||||||
let x = b["property"]
|
|
@ -1,2 +0,0 @@
|
|||||||
let obj = {key: 123}
|
|
||||||
let num = obj[3]
|
|
@ -1,2 +0,0 @@
|
|||||||
let obj = {}
|
|
||||||
let k = obj["age"]
|
|
@ -1,40 +0,0 @@
|
|||||||
// This tests evaluating properties of objects.
|
|
||||||
|
|
||||||
const obj = {
|
|
||||||
foo: 1,
|
|
||||||
bar: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test: the property is a literal.
|
|
||||||
|
|
||||||
const one_a = obj["foo"]
|
|
||||||
|
|
||||||
assertLessThanOrEq(one_a, 1, "Literal property lookup")
|
|
||||||
assertGreaterThanOrEq(one_a, 1, "Literal property lookup")
|
|
||||||
|
|
||||||
// Test: the property is a variable,
|
|
||||||
// which must be evaluated before looking it up.
|
|
||||||
|
|
||||||
const p = "foo"
|
|
||||||
const one_b = obj[p]
|
|
||||||
|
|
||||||
assertLessThanOrEq(one_b, 1, "Computed property lookup")
|
|
||||||
assertGreaterThanOrEq(one_b, 1, "Computed property lookup")
|
|
||||||
|
|
||||||
// Test: multiple literal properties.
|
|
||||||
|
|
||||||
const obj2 = {
|
|
||||||
inner: obj,
|
|
||||||
}
|
|
||||||
|
|
||||||
const one_c = obj2.inner["foo"]
|
|
||||||
|
|
||||||
assertLessThanOrEq(one_c, 1, "Literal property lookup")
|
|
||||||
assertGreaterThanOrEq(one_c, 1, "Literal property lookup")
|
|
||||||
|
|
||||||
// Test: multiple properties, mix of literal and computed.
|
|
||||||
|
|
||||||
const one_d = obj2.inner[p]
|
|
||||||
|
|
||||||
assertLessThanOrEq(one_d, 1, "Computed property lookup")
|
|
||||||
assertGreaterThanOrEq(one_d, 1, "Computed property lookup")
|
|
@ -4,7 +4,7 @@ use kcl_lib::{settings::types::UnitLength, test_server::execute_and_snapshot};
|
|||||||
/// i.e. how different the current model snapshot can be from the previous saved one.
|
/// i.e. how different the current model snapshot can be from the previous saved one.
|
||||||
const MIN_DIFF: f64 = 0.99;
|
const MIN_DIFF: f64 = 0.99;
|
||||||
|
|
||||||
mod no_visuals;
|
// mod server;
|
||||||
|
|
||||||
macro_rules! kcl_input {
|
macro_rules! kcl_input {
|
||||||
($file:literal) => {
|
($file:literal) => {
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
use kcl_lib::{ast::types::Program, errors::KclError, executor::ExecutorContext};
|
|
||||||
|
|
||||||
macro_rules! gen_test {
|
|
||||||
($file:ident) => {
|
|
||||||
#[tokio::test]
|
|
||||||
async fn $file() {
|
|
||||||
let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl"));
|
|
||||||
run(&code).await;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! gen_test_fail {
|
|
||||||
($file:ident, $expected:literal) => {
|
|
||||||
#[tokio::test]
|
|
||||||
async fn $file() {
|
|
||||||
let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl"));
|
|
||||||
let actual = run_fail(&code).await;
|
|
||||||
assert_eq!(actual.get_message(), $expected);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run(code: &str) {
|
|
||||||
let (ctx, program) = setup(code).await;
|
|
||||||
|
|
||||||
ctx.run(&program, None).await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn setup(program: &str) -> (ExecutorContext, Program) {
|
|
||||||
let tokens = kcl_lib::token::lexer(program).unwrap();
|
|
||||||
let parser = kcl_lib::parser::Parser::new(tokens);
|
|
||||||
let program = parser.ast().unwrap();
|
|
||||||
let ctx = kcl_lib::executor::ExecutorContext {
|
|
||||||
engine: std::sync::Arc::new(Box::new(
|
|
||||||
kcl_lib::engine::conn_mock::EngineConnection::new().await.unwrap(),
|
|
||||||
)),
|
|
||||||
fs: std::sync::Arc::new(kcl_lib::fs::FileManager::new()),
|
|
||||||
stdlib: std::sync::Arc::new(kcl_lib::std::StdLib::new()),
|
|
||||||
settings: Default::default(),
|
|
||||||
is_mock: true,
|
|
||||||
};
|
|
||||||
(ctx, program)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_fail(code: &str) -> KclError {
|
|
||||||
let (ctx, program) = setup(code).await;
|
|
||||||
let Err(e) = ctx.run(&program, None).await else {
|
|
||||||
panic!("Expected this KCL program to fail, but it (incorrectly) never threw an error.");
|
|
||||||
};
|
|
||||||
e
|
|
||||||
}
|
|
||||||
|
|
||||||
gen_test!(property_of_object);
|
|
||||||
gen_test!(index_of_array);
|
|
||||||
gen_test_fail!(
|
|
||||||
invalid_index_str,
|
|
||||||
"semantic: Only integers >= 0 can be used as the index of an array, but you're using a string"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
invalid_index_negative,
|
|
||||||
"semantic: i's value is not a valid property/index, you can only use a string or int (>= 0) here"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
invalid_index_fractional,
|
|
||||||
"semantic: Only strings or ints (>= 0) can be properties/indexes"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
invalid_member_object,
|
|
||||||
"semantic: Only arrays and objects can be indexed, but you're trying to index a number"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
invalid_member_object_prop,
|
|
||||||
"semantic: Only arrays and objects can be indexed, but you're trying to index a boolean (true/false value)"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
non_string_key_of_object,
|
|
||||||
"semantic: Only strings can be used as the property of an object, but you're using a number"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
array_index_oob,
|
|
||||||
"undefined value: The array doesn't have any item at index 0"
|
|
||||||
);
|
|
||||||
gen_test_fail!(
|
|
||||||
object_prop_not_found,
|
|
||||||
"undefined value: Property 'age' not found in object"
|
|
||||||
);
|
|