Compare commits

..

5 Commits

37 changed files with 46 additions and 357 deletions

View File

@ -89,20 +89,16 @@ jobs:
- run: yarn build:wasm
- run: yarn simpleserver:ci
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
- name: Install Chromium Browser
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
run: yarn playwright install chromium --with-deps
- name: run unit tests
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
run: yarn test:nowatch
env:
VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
- name: check for changes
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
id: git-check
run: |
git add src/lang/std/artifactMapGraphs
@ -111,7 +107,7 @@ jobs:
else echo "modified=false" >> $GITHUB_OUTPUT
fi
- 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: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
@ -535,7 +531,7 @@ jobs:
project_id: kittycadapi
- 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:
path: artifact
glob: '*/Zoo*'
@ -543,13 +539,13 @@ jobs:
destination: ${{ env.BUCKET_DIR }}/${{ env.VERSION }}
- 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:
path: last_update.json
destination: ${{ env.BUCKET_DIR }}
- 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:
path: last_download.json
destination: ${{ env.BUCKET_DIR }}

File diff suppressed because one or more lines are too long

View File

@ -21,7 +21,6 @@ layout: manual
* [`arc`](kcl/arc)
* [`asin`](kcl/asin)
* [`assert`](kcl/assert)
* [`assertEqual`](kcl/assertEqual)
* [`assertGreaterThan`](kcl/assertGreaterThan)
* [`assertGreaterThanOrEq`](kcl/assertGreaterThanOrEq)
* [`assertLessThan`](kcl/assertLessThan)

View File

@ -54791,62 +54791,6 @@
"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",
"summary": "Check that a numerical value is greater than another at runtime,",
@ -223491,7 +223435,7 @@
},
{
"name": "xLine",
"summary": "Draw a line parallel to the X-axis, with the given length.",
"summary": "Draw a line on the x-axis.",
"description": "",
"tags": [],
"args": [
@ -230125,8 +230069,8 @@
},
{
"name": "xLineTo",
"summary": "Draw a line parallel to the X axis, that ends at the given X.",
"description": "E.g. if the previous line ended at (1, 1), then xLineTo(4) draws a line from (1, 1) to (4, 1)",
"summary": "Draw a line to a point on the x-axis.",
"description": "",
"tags": [],
"args": [
{
@ -236759,7 +236703,7 @@
},
{
"name": "yLine",
"summary": "Draw a line parallel to the Y-axis, with the given length.",
"summary": "Draw a line on the y-axis.",
"description": "",
"tags": [],
"args": [
@ -243393,8 +243337,8 @@
},
{
"name": "yLineTo",
"summary": "Draw a line parallel to the Y axis, that ends at the given Y.",
"description": "E.g. if the previous line ended at (1, 1), then yLineTo(4) draws a line from (1, 1) to (1, 4)",
"summary": "Draw a line to a point on the y-axis.",
"description": "",
"tags": [],
"args": [
{

View File

@ -1,10 +1,10 @@
---
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
---
Draw a line parallel to the X-axis, with the given length.
Draw a line on the x-axis.

View File

@ -1,12 +1,12 @@
---
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
---
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
xLineTo(to: number, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup

View File

@ -1,10 +1,10 @@
---
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
---
Draw a line parallel to the Y-axis, with the given length.
Draw a line on the y-axis.

View File

@ -1,12 +1,12 @@
---
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
---
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
yLineTo(to: number, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup

View File

@ -46,9 +46,9 @@ document.addEventListener('mousemove', (e) =>
const deg = (Math.PI * 2) / 360
const commonPoints = {
startAt: '[7.19, -9.7]',
num1: 7.25,
num2: 14.44,
startAt: '[0.75, -1.01]',
num1: 0.75,
num2: 1.5,
}
test.afterEach(async ({ context, page }, testInfo) => {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -1,6 +1,6 @@
{
"name": "untitled-app",
"version": "0.24.9",
"version": "0.24.8",
"private": true,
"dependencies": {
"@codemirror/autocomplete": "^6.17.0",

View File

@ -80,5 +80,5 @@
}
},
"productName": "Zoo Modeling App",
"version": "0.24.9"
"version": "0.24.8"
}

View File

@ -791,7 +791,6 @@ export function isSingleCursorInPipe(
const pathToNode = getNodePathFromSourceRange(ast, selection.range)
const nodeTypes = pathToNode.map(([, type]) => type)
if (nodeTypes.includes('FunctionExpression')) return false
if (!nodeTypes.includes('VariableDeclaration')) return false
if (nodeTypes.includes('PipeExpression')) return true
return false
}

View File

@ -458,9 +458,6 @@ async function GraphTheGraph(
await page.waitForSelector('#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
await element.screenshot({
path: `./e2e/playwright/temp3.png`,

View File

@ -1064,16 +1064,7 @@ export const modelingMachine = createMachine(
sketchPlaneId: '',
}),
'reset camera position': () =>
engineCommandManager.sendSceneCommand({
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 },
},
}),
sceneInfra.camControls.resetCameraPosition(),
'set new sketch metadata': assign((_, { data }) => ({
sketchDetails: data,
})),

View File

@ -2862,7 +2862,7 @@ impl MemberExpression {
// Actually evaluate memory to compute the property.
let prop = memory.get(&name, property_src)?;
let MemoryItem::UserVal(prop) = prop else {
return Err(KclError::Semantic(KclErrorDetails {
return Err(KclError::Syntax(KclErrorDetails {
source_ranges: property_sr,
message: format!(
"{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())
.map(Property::Number)
.ok_or_else(|| {
KclError::Semantic(KclErrorDetails {
KclError::Syntax(KclErrorDetails {
source_ranges: property_sr,
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()),
_ => {
return Err(KclError::Semantic(KclErrorDetails {
return Err(KclError::Syntax(KclErrorDetails {
source_ranges: property_sr,
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",
@ -2903,7 +2903,7 @@ impl MemberExpression {
if let Ok(x) = u64::try_from(x) {
Property::Number(x.try_into().unwrap())
} else {
return Err(KclError::Semantic(KclErrorDetails {
return Err(KclError::Syntax(KclErrorDetails {
source_ranges: property_sr,
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),
_ => {
return Err(KclError::Semantic(KclErrorDetails {
return Err(KclError::Syntax(KclErrorDetails {
source_ranges: vec![self.into()],
message: "Only strings or ints (>= 0) can be properties/indexes".to_owned(),
}));
@ -2943,7 +2943,7 @@ impl MemberExpression {
}))
} else {
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()],
}))
}
@ -2978,13 +2978,10 @@ impl MemberExpression {
),
source_ranges: vec![self.clone().into()],
})),
(being_indexed, _) => {
let t = human_friendly_type(being_indexed);
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()],
}))
}
(_, _) => Err(KclError::Semantic(KclErrorDetails {
message: "Only arrays and objects can be indexed".to_owned(),
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)]
mod tests {
use pretty_assertions::assert_eq;

View File

@ -67,27 +67,6 @@ pub async fn assert_gt(args: Args) -> Result<MemoryItem, KclError> {
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,
/// otherwise raise an error.
///

View File

@ -120,7 +120,6 @@ lazy_static! {
Box::new(crate::std::math::ToRadians),
Box::new(crate::std::polar::Polar),
Box::new(crate::std::assert::Assert),
Box::new(crate::std::assert::AssertEqual),
Box::new(crate::std::assert::AssertLessThan),
Box::new(crate::std::assert::AssertGreaterThan),
Box::new(crate::std::assert::AssertLessThanOrEq),

View File

@ -168,9 +168,7 @@ pub async fn x_line_to(args: Args) -> Result<MemoryItem, KclError> {
Ok(MemoryItem::SketchGroup(new_sketch_group))
}
/// Draw a line parallel to the X axis, that ends at the given X.
/// E.g. if the previous line ended at (1, 1),
/// then xLineTo(4) draws a line from (1, 1) to (4, 1)
/// Draw a line to a point on the x-axis.
///
/// ```no_run
/// 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))
}
/// Draw a line parallel to the Y axis, that ends at the given Y.
/// E.g. if the previous line ended at (1, 1),
/// then yLineTo(4) draws a line from (1, 1) to (1, 4)
/// Draw a line to a point on the y-axis.
///
/// ```no_run
/// const exampleSketch = startSketchOn("XZ")
@ -340,7 +336,7 @@ pub async fn x_line(args: Args) -> Result<MemoryItem, KclError> {
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
/// const exampleSketch = startSketchOn('XZ')
@ -382,7 +378,7 @@ pub async fn y_line(args: Args) -> Result<MemoryItem, KclError> {
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
/// const exampleSketch = startSketchOn('XZ')

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

View File

@ -4,7 +4,8 @@ const arr = [0, 0, 0, 10]
const i = 3
const ten = arr[i]
assertEqual(ten, 10, 0.000001, "oops")
assertLessThanOrEq(ten, 10, "oops")
assertGreaterThanOrEq(ten, 10, "oops2")
const p = "foo"
const obj = {
@ -13,4 +14,5 @@ const obj = {
}
const one = obj[p]
assertEqual(one, 1, 0.0000001, "oops")
assertLessThanOrEq(one, 1, "oops")
assertGreaterThanOrEq(one, 1, "oops2")

View File

@ -1,2 +0,0 @@
let arr = []
let x = arr[0]

View File

@ -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")

View File

@ -1,2 +0,0 @@
let arr = [1, 2, 3]
let x = arr[1.2]

View File

@ -1,3 +0,0 @@
let arr = [1, 2, 3]
let i = -1
let x = arr[i]

View File

@ -1,2 +0,0 @@
let arr = [1, 2, 3]
let x = arr["s"]

View File

@ -1,2 +0,0 @@
let num = 999
let x = num[3]

View File

@ -1,2 +0,0 @@
let b = true
let x = b["property"]

View File

@ -1,2 +0,0 @@
let obj = {key: 123}
let num = obj[3]

View File

@ -1,2 +0,0 @@
let obj = {}
let k = obj["age"]

View File

@ -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")

View File

@ -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.
const MIN_DIFF: f64 = 0.99;
mod no_visuals;
// mod server;
macro_rules! kcl_input {
($file:literal) => {

View File

@ -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"
);