Compare commits

...

6 Commits

Author SHA1 Message Date
47c78fe8a3 A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) 2024-11-05 17:03:19 +00:00
24faa9fb8c Don't serialize "startNodes" if it's empty
This makes our snapshots and JSON less verbose.
2024-11-05 10:42:33 -06:00
d2ec1e5bd5 Don't serialize empty 'digest' on IfExprs 2024-11-05 10:42:30 -06:00
2abfbb9788 Move tests from no_visuals into simulation tests (#4367)
Now you can properly inspect program memory for the no_visuals tests, instead of relying on a lot of KCL asserts.
2024-11-05 02:34:22 +00:00
ad1cd56891 Deflake project settings override on desktop (#4370) 2024-10-31 21:42:52 -04:00
26951364cf KCL: More simulation tests (#4359)
Demonstrate simulation tests where we don't care about visuals, e.g. the double-map test. 

The `just new-sim-test` now accepts an optional argument, `render_to_png` which can be either  "true" or "false" (defaults to "true"). Tests like double_map that don't render anything can use false, rather than rendering an empty PNG with nothing in it.

This means the [tests under `no_visuals/`](https://github.com/KittyCAD/modeling-app/tree/v0.26.2/src/wasm-lib/tests/executor/inputs/no_visuals) can be entirely replaced by simulation tests. This is much better! For example, I moved `double_map.kcl` from a no_visuals test to a simulation test. Here's the file:

```
fn increment = (i) => {
  return i + 1
}

xs = [0..2]
ys = xs
  |> map(%, increment)
  |> map(%, increment)
```

Previously the `no_visuals` test just checked that the program ran successfully without panicking. Now the simulation test lets you see the value of `xs` and `ys` and immediately see they're correct. If our map logic changes (for example, we have an off-by-one error and don't apply the `map` to the last element) it'll show up in the program memory snapshot.
2024-10-31 11:43:14 -05:00
84 changed files with 24664 additions and 468 deletions

View File

@ -4,9 +4,9 @@ set -euo pipefail
if [[ ! -f "test-results/.last-run.json" ]]; then
# if no last run artifact, than run plawright normally
echo "run playwright normally"
if [[ "$3" == "ubuntu-latest" ]]; then
if [[ "$3" == ubuntu-latest* ]]; then
yarn test:playwright:browser:chrome:ubuntu -- --shard=$1/$2 || true
elif [[ "$3" == "windows-latest" ]]; then
elif [[ "$3" == windows-latest* ]]; then
yarn test:playwright:browser:chrome:windows -- --shard=$1/$2 || true
else
echo "Do not run playwright. Unable to detect os runtime."
@ -26,9 +26,9 @@ while [[ $retry -le $max_retrys ]]; do
if [[ $failed_tests -gt 0 ]]; then
echo "retried=true" >>$GITHUB_OUTPUT
echo "run playwright with last failed tests and retry $retry"
if [[ "$3" == "ubuntu-latest" ]]; then
if [[ "$3" == ubuntu-latest* ]]; then
yarn test:playwright:browser:chrome:ubuntu -- --last-failed || true
elif [[ "$3" == "windows-latest" ]]; then
elif [[ "$3" == windows-latest* ]]; then
yarn test:playwright:browser:chrome:windows -- --last-failed || true
else
echo "Do not run playwright. Unable to detect os runtime."

View File

@ -4,11 +4,11 @@ set -euo pipefail
if [[ ! -f "test-results/.last-run.json" ]]; then
# if no last run artifact, than run plawright normally
echo "run playwright normally"
if [[ "$1" == "ubuntu-latest" ]]; then
if [[ "$1" == ubuntu-latest* ]]; then
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn test:playwright:electron:ubuntu || true
elif [[ "$1" == "windows-latest" ]]; then
elif [[ "$1" == windows-latest* ]]; then
yarn test:playwright:electron:windows || true
elif [[ "$1" == "macos-14" ]]; then
elif [[ "$1" == macos-14* ]]; then
yarn test:playwright:electron:macos || true
else
echo "Do not run playwright. Unable to detect os runtime."
@ -28,11 +28,11 @@ while [[ $retry -le $max_retrys ]]; do
if [[ $failed_tests -gt 0 ]]; then
echo "retried=true" >>$GITHUB_OUTPUT
echo "run playwright with last failed tests and retry $retry"
if [[ "$1" == "ubuntu-latest" ]]; then
if [[ "$1" == ubuntu-latest* ]]; then
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn test:playwright:electron:ubuntu -- --last-failed || true
elif [[ "$1" == "windows-latest" ]]; then
elif [[ "$1" == windows-latest* ]]; then
yarn test:playwright:electron:windows -- --last-failed || true
elif [[ "$1" == "macos-14" ]]; then
elif [[ "$1" == macos-14* ]]; then
yarn test:playwright:electron:macos -- --last-failed || true
else
echo "Do not run playwright. Unable to detect os runtime."

View File

@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest-8-cores, windows-latest-8-cores]
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
runs-on: ${{ matrix.os }}
@ -227,7 +227,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-14]
os: [ubuntu-latest-8-cores, windows-latest-8-cores, macos-14-large]
timeout-minutes: 60
runs-on: ${{ matrix.os }}
needs: check-rust-changes
@ -287,7 +287,7 @@ jobs:
brew install gnu-sed
echo "/opt/homebrew/opt/gnu-sed/libexec/gnubin" >> $GITHUB_PATH
- name: Install vector
if: ${{ !startsWith(matrix.os, 'windows') }}
if: ${{ startsWith(matrix.os, 'ubuntu') }}
shell: bash
run: |
curl --proto '=https' --tlsv1.2 -sSfL https://sh.vector.dev > /tmp/vector.sh

View File

@ -93200,8 +93200,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -96944,8 +96943,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -100692,8 +100690,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -130888,8 +130885,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -135023,8 +135019,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -138765,8 +138760,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -142918,8 +142912,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -147053,8 +147046,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -150797,8 +150789,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {
@ -154539,8 +154530,7 @@
"NonCodeMeta": {
"type": "object",
"required": [
"nonCodeNodes",
"startNodes"
"nonCodeNodes"
],
"properties": {
"nonCodeNodes": {

View File

@ -985,7 +985,7 @@ test.describe('Editor tests', () => {
|> extrude(5, %)`)
})
test(
test.fixme(
`Can use the import stdlib function on a local OBJ file`,
{ tag: '@electron' },
async ({ browserName }, testInfo) => {

View File

@ -109,7 +109,7 @@ test.describe('when using the file tree to', () => {
const fromFile = 'main.kcl'
const toFile = 'hello.kcl'
test(
test.fixme(
`rename ${fromFile} to ${toFile}, and doesn't crash on reload and settings load`,
{ tag: '@electron' },
async ({ browser: _, tronApp }, testInfo) => {
@ -157,7 +157,7 @@ test.describe('when using the file tree to', () => {
}
)
test(
test.fixme(
`create many new untitled files they increment their names`,
{ tag: '@electron' },
async ({ browser: _, tronApp }, testInfo) => {
@ -298,7 +298,7 @@ test.describe('when using the file tree to', () => {
}
)
test(
test.fixme(
'loading small file, then large, then back to small',
{
tag: '@electron',

View File

@ -854,7 +854,7 @@ test(
}
)
test(
test.fixme(
'Deleting projects, can delete individual project, can still create projects after deleting all',
{ tag: '@electron' },
async ({ browserName }, testInfo) => {
@ -1490,7 +1490,6 @@ test(
'function_sketch.kcl',
'function_sketch_with_position.kcl',
'global-tags.kcl',
'helix_ccw.kcl',
'helix_defaults.kcl',
'helix_defaults_negative_extrude.kcl',
'helix_with_length.kcl',

View File

@ -1031,7 +1031,7 @@ test.describe('Grid visibility', { tag: '@snapshot' }, () => {
})
})
test('theme persists', async ({ page, context }) => {
test.fixme('theme persists', async ({ page, context }) => {
const u = await getUtils(page)
await context.addInitScript(async () => {
localStorage.setItem(

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -318,6 +318,7 @@ test.describe('Testing settings', () => {
timeout: 5_000,
})
.toContain(`themeColor = "${userThemeColor}"`)
// Only close the button after we've confirmed
})
await test.step('Set project theme color', async () => {
@ -344,14 +345,13 @@ test.describe('Testing settings', () => {
await test.step('Refresh the application and see project setting applied', async () => {
// Make sure we're done navigating before we reload
await expect(settingsCloseButton).not.toBeVisible()
await page.reload({ waitUntil: 'domcontentloaded' })
await page.reload({ waitUntil: 'domcontentloaded' })
await expect(logoLink).toHaveCSS('--primary-hue', projectThemeColor)
})
await test.step(`Navigate back to the home view and see user setting applied`, async () => {
await logoLink.click()
await page.screenshot({ path: 'out.png' })
await expect(logoLink).toHaveCSS('--primary-hue', userThemeColor)
})
@ -415,7 +415,7 @@ test.describe('Testing settings', () => {
)
// It was much easier to test the logo color than the background stream color.
test(
test.fixme(
'user settings reload on external change, on project and modeling view',
{ tag: '@electron' },
async ({ browserName }, testInfo) => {

View File

@ -256,181 +256,186 @@ test('First escape in tool pops you out of tool, second exits sketch mode', asyn
).not.toBeVisible()
})
test('Basic default modeling and sketch hotkeys work', async ({ page }) => {
const u = await getUtils(page)
test.fixme(
'Basic default modeling and sketch hotkeys work',
async ({ page }) => {
const u = await getUtils(page)
// This test can run long if it takes a little too long to load
// the engine.
test.setTimeout(90000)
// This test has a weird bug on ubuntu
test.skip(
process.platform === 'linux',
'weird playwright bug on ubuntu https://github.com/KittyCAD/modeling-app/issues/2444'
)
// Load the app with the code pane open
// This test can run long if it takes a little too long to load
// the engine.
test.setTimeout(90000)
// This test has a weird bug on ubuntu
// Funny, it's flaking on Windows too :). I think there is just something
// actually wrong.
test.skip(
process.platform === 'linux',
'weird playwright bug on ubuntu https://github.com/KittyCAD/modeling-app/issues/2444'
)
// Load the app with the code pane open
await test.step(`Set up test`, async () => {
await page.addInitScript(async () => {
localStorage.setItem(
'store',
JSON.stringify({
state: {
openPanes: ['code'],
},
version: 0,
await test.step(`Set up test`, async () => {
await page.addInitScript(async () => {
localStorage.setItem(
'store',
JSON.stringify({
state: {
openPanes: ['code'],
},
version: 0,
})
)
})
await page.setViewportSize({ width: 1200, height: 500 })
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
})
const codePane = page.locator('.cm-content')
const lineButton = page.getByRole('button', {
name: 'line Line',
exact: true,
})
const arcButton = page.getByRole('button', {
name: 'arc Tangential Arc',
exact: true,
})
const extrudeButton = page.getByRole('button', { name: 'Extrude' })
const commandBarComboBox = page.getByPlaceholder('Search commands')
const exitSketchButton = page.getByRole('button', { name: 'Exit Sketch' })
await test.step(`Type code with modeling hotkeys, shouldn't fire`, async () => {
await codePane.click()
await page.keyboard.type('//')
await page.keyboard.press('s')
await expect(commandBarComboBox).not.toBeVisible()
await page.keyboard.press('e')
await expect(commandBarComboBox).not.toBeVisible()
await expect(codePane).toHaveText('//se')
})
// Blur focus from the code editor, use the s command to sketch
await test.step(`Blur editor focus, enter sketch`, async () => {
/**
* TODO: There is a bug somewhere that causes this test to fail
* if you toggle the codePane closed before your trigger the
* start of the sketch.
* and a separate Safari-only bug that causes the test to fail
* if the pane is open the entire test. The maintainer of CodeMirror
* has pinpointed this to the unusual browser behavior:
* https://discuss.codemirror.net/t/how-to-force-unfocus-of-the-codemirror-element-in-safari/8095/3
*/
await blurCodeEditor()
await page.waitForTimeout(1000)
await page.keyboard.press('s')
await page.waitForTimeout(1000)
await page.mouse.move(800, 300, { steps: 5 })
await page.mouse.click(800, 300)
await page.waitForTimeout(1000)
await expect(lineButton).toHaveAttribute('aria-pressed', 'true', {
timeout: 15_000,
})
})
// Use some sketch hotkeys to create a sketch (l and a for now)
await test.step(`Incomplete sketch with hotkeys`, async () => {
await test.step(`Draw a line`, async () => {
await page.mouse.move(700, 200, { steps: 5 })
await page.mouse.click(700, 200)
await page.mouse.move(800, 250, { steps: 5 })
await page.mouse.click(800, 250)
})
await test.step(`Unequip line tool`, async () => {
await page.keyboard.press('l')
await expect(lineButton).not.toHaveAttribute('aria-pressed', 'true')
})
await test.step(`Draw a tangential arc`, async () => {
await page.keyboard.press('a')
await expect(arcButton).toHaveAttribute('aria-pressed', 'true', {
timeout: 10_000,
})
)
await page.mouse.move(1000, 100, { steps: 5 })
await page.mouse.click(1000, 100)
})
await test.step(`Unequip with escape, equip line tool`, async () => {
await page.keyboard.press('Escape')
await page.keyboard.press('l')
await page.waitForTimeout(50)
await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
})
})
await page.setViewportSize({ width: 1200, height: 500 })
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
})
const codePane = page.locator('.cm-content')
const lineButton = page.getByRole('button', {
name: 'line Line',
exact: true,
})
const arcButton = page.getByRole('button', {
name: 'arc Tangential Arc',
exact: true,
})
const extrudeButton = page.getByRole('button', { name: 'Extrude' })
const commandBarComboBox = page.getByPlaceholder('Search commands')
const exitSketchButton = page.getByRole('button', { name: 'Exit Sketch' })
await test.step(`Type code with sketch hotkeys, shouldn't fire`, async () => {
// Since there's code now, we have to get to the end of the line
await page.locator('.cm-line').last().click()
await page.keyboard.down('ControlOrMeta')
await page.keyboard.press('ArrowRight')
await page.keyboard.up('ControlOrMeta')
await test.step(`Type code with modeling hotkeys, shouldn't fire`, async () => {
await codePane.click()
await page.keyboard.type('//')
await page.keyboard.press('s')
await expect(commandBarComboBox).not.toBeVisible()
await page.keyboard.press('e')
await expect(commandBarComboBox).not.toBeVisible()
await expect(codePane).toHaveText('//se')
})
// Blur focus from the code editor, use the s command to sketch
await test.step(`Blur editor focus, enter sketch`, async () => {
/**
* TODO: There is a bug somewhere that causes this test to fail
* if you toggle the codePane closed before your trigger the
* start of the sketch.
* and a separate Safari-only bug that causes the test to fail
* if the pane is open the entire test. The maintainer of CodeMirror
* has pinpointed this to the unusual browser behavior:
* https://discuss.codemirror.net/t/how-to-force-unfocus-of-the-codemirror-element-in-safari/8095/3
*/
await blurCodeEditor()
await page.waitForTimeout(1000)
await page.keyboard.press('s')
await page.waitForTimeout(1000)
await page.mouse.move(800, 300, { steps: 5 })
await page.mouse.click(800, 300)
await page.waitForTimeout(1000)
await expect(lineButton).toHaveAttribute('aria-pressed', 'true', {
timeout: 15_000,
await page.keyboard.press('Enter')
await page.keyboard.type('//')
await page.keyboard.press('l')
await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
await page.keyboard.press('a')
await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
await expect(codePane).toContainText('//la')
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
})
})
// Use some sketch hotkeys to create a sketch (l and a for now)
await test.step(`Incomplete sketch with hotkeys`, async () => {
await test.step(`Draw a line`, async () => {
await test.step(`Close profile and exit sketch`, async () => {
await blurCodeEditor()
await page.mouse.move(700, 200, { steps: 5 })
await page.mouse.click(700, 200)
await page.mouse.move(800, 250, { steps: 5 })
await page.mouse.click(800, 250)
})
await test.step(`Unequip line tool`, async () => {
await page.keyboard.press('l')
await expect(lineButton).not.toHaveAttribute('aria-pressed', 'true')
})
await test.step(`Draw a tangential arc`, async () => {
await page.keyboard.press('a')
await expect(arcButton).toHaveAttribute('aria-pressed', 'true', {
timeout: 10_000,
})
await page.mouse.move(1000, 100, { steps: 5 })
await page.mouse.click(1000, 100)
})
await test.step(`Unequip with escape, equip line tool`, async () => {
// On close it will unequip the line tool.
await expect(lineButton).toHaveAttribute('aria-pressed', 'false')
await expect(exitSketchButton).toBeEnabled()
await page.keyboard.press('Escape')
await page.keyboard.press('l')
await page.waitForTimeout(50)
await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
await expect(
page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible()
})
})
await test.step(`Type code with sketch hotkeys, shouldn't fire`, async () => {
// Since there's code now, we have to get to the end of the line
await page.locator('.cm-line').last().click()
await page.keyboard.down('ControlOrMeta')
await page.keyboard.press('ArrowRight')
await page.keyboard.up('ControlOrMeta')
await page.keyboard.press('Enter')
await page.keyboard.type('//')
await page.keyboard.press('l')
await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
await page.keyboard.press('a')
await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
await expect(codePane).toContainText('//la')
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
})
await test.step(`Close profile and exit sketch`, async () => {
await blurCodeEditor()
await page.mouse.move(700, 200, { steps: 5 })
await page.mouse.click(700, 200)
// On close it will unequip the line tool.
await expect(lineButton).toHaveAttribute('aria-pressed', 'false')
await expect(exitSketchButton).toBeEnabled()
await page.keyboard.press('Escape')
await expect(
page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible()
})
// Extrude with e
await test.step(`Extrude the sketch`, async () => {
await page.mouse.click(750, 150)
await blurCodeEditor()
await expect(extrudeButton).toBeEnabled()
await page.keyboard.press('e')
await page.waitForTimeout(500)
await page.mouse.move(800, 200, { steps: 5 })
await page.mouse.click(800, 200)
await expect(page.getByRole('button', { name: 'Continue' })).toBeVisible({
timeout: 20_000,
// Extrude with e
await test.step(`Extrude the sketch`, async () => {
await page.mouse.click(750, 150)
await blurCodeEditor()
await expect(extrudeButton).toBeEnabled()
await page.keyboard.press('e')
await page.waitForTimeout(500)
await page.mouse.move(800, 200, { steps: 5 })
await page.mouse.click(800, 200)
await expect(page.getByRole('button', { name: 'Continue' })).toBeVisible({
timeout: 20_000,
})
await page.getByRole('button', { name: 'Continue' }).click()
await expect(
page.getByRole('button', { name: 'Submit command' })
).toBeVisible()
await page.getByRole('button', { name: 'Submit command' }).click()
await expect(page.locator('.cm-content')).toContainText('extrude(')
})
await page.getByRole('button', { name: 'Continue' }).click()
await expect(
page.getByRole('button', { name: 'Submit command' })
).toBeVisible()
await page.getByRole('button', { name: 'Submit command' }).click()
await expect(page.locator('.cm-content')).toContainText('extrude(')
})
// await codePaneButton.click()
// await expect(u.codeLocator).not.toBeVisible()
// await codePaneButton.click()
// await expect(u.codeLocator).not.toBeVisible()
/**
* work-around: to stop `keyboard.press()` from typing in the editor even when it should be blurred
*/
async function blurCodeEditor() {
await page.getByRole('button', { name: 'Commands' }).click()
await page.waitForTimeout(100)
await page.keyboard.press('Escape')
await page.waitForTimeout(100)
/**
* work-around: to stop `keyboard.press()` from typing in the editor even when it should be blurred
*/
async function blurCodeEditor() {
await page.getByRole('button', { name: 'Commands' }).click()
await page.waitForTimeout(100)
await page.keyboard.press('Escape')
await page.waitForTimeout(100)
}
}
})
)
test('Delete key does not navigate back', async ({ page }) => {
await page.setViewportSize({ width: 1200, height: 500 })

View File

@ -138,15 +138,15 @@ const FileTreeItem = ({
// the ReactNodes are destroyed, so is this listener :)
useFileSystemWatcher(
async (eventType, path) => {
// Prevents a cyclic read / write causing editor problems such as
// misplaced cursor positions.
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
return
}
// Don't try to read a file that was removed.
if (isCurrentFile && eventType !== 'unlink') {
// Prevents a cyclic read / write causing editor problems such as
// misplaced cursor positions.
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
return
}
let code = await window.electron.readFile(path, { encoding: 'utf-8' })
code = normalizeLineEndings(code)
codeManager.updateCodeStateEditor(code)
@ -194,11 +194,11 @@ const FileTreeItem = ({
// Show the renaming form
addCurrentItemToRenaming()
} else if (e.code === 'Space') {
handleClick()
void handleClick()
}
}
function handleClick() {
async function handleClick() {
if (fileOrDir.children !== null) return // Don't open directories
if (fileOrDir.name?.endsWith(FILE_EXT) === false && project?.path) {
@ -208,12 +208,10 @@ const FileTreeItem = ({
`import("${fileOrDir.path.replace(project.path, '.')}")\n` +
codeManager.code
)
// eslint-disable-next-line @typescript-eslint/no-floating-promises
codeManager.writeToFile()
await codeManager.writeToFile()
// Prevent seeing the model built one piece at a time when changing files
// eslint-disable-next-line @typescript-eslint/no-floating-promises
kclManager.executeCode(true)
await kclManager.executeCode(true)
} else {
// Let the lsp servers know we closed a file.
onFileClose(currentFile?.path || null, project?.path || null)
@ -242,7 +240,7 @@ const FileTreeItem = ({
style={{ paddingInlineStart: getIndentationCSS(level) }}
onClick={(e) => {
e.currentTarget.focus()
handleClick()
void handleClick()
}}
onKeyUp={handleKeyUp}
>
@ -501,6 +499,13 @@ export const FileTreeInner = ({
const isCurrentFile = loaderData.file?.path === path
const hasChanged = eventType === 'change'
if (isCurrentFile && hasChanged) return
// If it's a settings file we wrote to already from the app ignore it.
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
return
}
fileSend({ type: 'Refresh' })
},
[loaderData?.project?.path, fileContext.selectedDirectory.path].filter(

View File

@ -41,6 +41,7 @@ import { reportRejection } from 'lib/trap'
import { getAppSettingsFilePath } from 'lib/desktop'
import { isDesktop } from 'lib/isDesktop'
import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher'
import { codeManager } from 'lib/singletons'
type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T>
@ -200,13 +201,13 @@ export const SettingsAuthProviderBase = ({
console.error('Error executing AST after settings change', e)
}
},
persistSettings: ({ context, event }) => {
async persistSettings({ context, event }) {
// Without this, when a user changes the file, it'd
// create a detection loop with the file-system watcher.
if (event.doNotPersist) return
// eslint-disable-next-line @typescript-eslint/no-floating-promises
saveSettings(context, loadedProject?.project?.path)
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
return saveSettings(context, loadedProject?.project?.path)
},
},
}),
@ -220,7 +221,7 @@ export const SettingsAuthProviderBase = ({
}, [])
useFileSystemWatcher(
async () => {
async (eventType: string) => {
// If there is a projectPath but it no longer exists it means
// it was exterally removed. If we let the code past this condition
// execute it will recreate the directory due to code in
@ -234,6 +235,9 @@ export const SettingsAuthProviderBase = ({
}
}
// Only reload if there are changes. Ignore everything else.
if (eventType !== 'change') return
const data = await loadAndValidateSettings(loadedProject?.project?.path)
settingsSend({
type: 'Set all settings',

View File

@ -96,10 +96,10 @@ export class KclPlugin implements PluginValue {
const newCode = viewUpdate.state.doc.toString()
codeManager.code = newCode
// eslint-disable-next-line @typescript-eslint/no-floating-promises
codeManager.writeToFile()
this.scheduleUpdateDoc()
void codeManager.writeToFile().then(() => {
this.scheduleUpdateDoc()
})
}
scheduleUpdateDoc() {

View File

@ -26,6 +26,7 @@ export function useRefreshSettings(routeId: string = PATHS.INDEX) {
ctx.settings.send({
type: 'Set all settings',
settings: routeData,
doNotPersist: true,
})
}, [])
}

View File

@ -429,13 +429,9 @@ export class KclManager {
// Update the code state and the editor.
codeManager.updateCodeStateEditor(code)
// Write back to the file system.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
codeManager.writeToFile()
// execute the code.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.executeCode()
// Write back to the file system.
void codeManager.writeToFile().then(() => this.executeCode())
}
// There's overlapping responsibility between updateAst and executeAst.
// updateAst was added as it was used a lot before xState migration so makes the port easier.

View File

@ -121,20 +121,28 @@ export default class CodeManager {
// Only write our buffer contents to file once per second. Any faster
// and file-system watchers which read, will receive empty data during
// writes.
clearTimeout(this.timeoutWriter)
this.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
this.timeoutWriter = setTimeout(() => {
// Wait one event loop to give a chance for params to be set
// Save the file to disk
this._currentFilePath &&
return new Promise((resolve, reject) => {
this.timeoutWriter = setTimeout(() => {
if (!this._currentFilePath)
return reject(new Error('currentFilePath not set'))
// Wait one event loop to give a chance for params to be set
// Save the file to disk
window.electron
.writeFile(this._currentFilePath, this.code ?? '')
.then(resolve)
.catch((err: Error) => {
// TODO: add tracing per GH issue #254 (https://github.com/KittyCAD/modeling-app/issues/254)
console.error('error saving file', err)
toast.error('Error saving file, please check file permissions')
reject(err)
})
}, 1000)
}, 1000)
})
} else {
safeLSSetItem(PERSIST_CODE_KEY, this.code)
}

View File

@ -178,6 +178,7 @@ export async function loadAndValidateSettings(
if (err(appSettingsPayload)) return Promise.reject(appSettingsPayload)
let settingsNext = createSettings()
// Because getting the default directory is async, we need to set it after
if (onDesktop) {
settings.app.projectDirectory.default = await getInitialDefaultDir()

View File

@ -13,14 +13,14 @@ redo-kcl-stdlib-docs:
EXPECTORATE=overwrite {{cnr}} -p kcl-lib docs::gen_std_tests::test_generate_stdlib
# Create a new KCL deterministic simulation test case.
new-sim-test test_name kcl_program:
new-sim-test test_name kcl_program render_to_png="true":
# Each test file gets its own directory. This will contain the KCL program, and its
# snapshotted artifacts (e.g. serialized tokens, serialized ASTs, program memory,
# PNG snapshots, etc).
mkdir kcl/tests/{{test_name}}
echo "{{kcl_program}}" > kcl/tests/{{test_name}}/input.kcl
# Add the various tests for this new test case.
cat kcl/tests/simtest.tmpl | sed "s/TEST_NAME_HERE/{{test_name}}/" >> kcl/src/tests.rs
cat kcl/tests/simtest.tmpl | sed "s/TEST_NAME_HERE/{{test_name}}/" | sed "s/RENDER_TO_PNG/{{render_to_png}}/" >> kcl/src/simulation_tests.rs
# Run all the tests for the first time, in the right order.
{{cita}} -p kcl-lib -- tests::{{test_name}}::tokenize
{{cita}} -p kcl-lib -- tests::{{test_name}}::parse

View File

@ -1029,6 +1029,7 @@ pub enum NonCodeValue {
#[serde(rename_all = "camelCase")]
pub struct NonCodeMeta {
pub non_code_nodes: HashMap<usize, NodeList<NonCodeNode>>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub start_nodes: NodeList<NonCodeNode>,
#[serde(default, skip_serializing_if = "Option::is_none")]
@ -1059,6 +1060,7 @@ impl<'de> Deserialize<'de> for NonCodeMeta {
#[serde(rename_all = "camelCase")]
struct NonCodeMetaHelper {
non_code_nodes: HashMap<String, NodeList<NonCodeNode>>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
start_nodes: NodeList<NonCodeNode>,
}

View File

@ -25,6 +25,8 @@ pub struct IfExpression {
pub else_ifs: NodeList<ElseIf>,
pub final_else: BoxNode<IfBlock>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub digest: Option<Digest>,
}
@ -36,6 +38,8 @@ pub struct ElseIf {
pub cond: Expr,
pub then_val: BoxNode<IfBlock>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub digest: Option<Digest>,
}

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -60,8 +61,7 @@ expression: actual
}
}
]
},
"startNodes": []
}
},
"start": 14,
"type": "ArrayExpression",

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -60,8 +61,7 @@ expression: actual
}
}
]
},
"startNodes": []
}
},
"start": 14,
"type": "ArrayExpression",

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -30,8 +31,7 @@ expression: actual
}
}
]
},
"startNodes": []
}
},
"properties": [
{

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -30,8 +31,7 @@ expression: actual
}
}
]
},
"startNodes": []
}
},
"properties": [
{

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -106,8 +107,7 @@ expression: actual
}
}
]
},
"startNodes": []
}
},
"start": 19,
"type": "PipeExpression",

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -23,7 +24,6 @@ expression: actual
"type": "Literal",
"value": true
},
"digest": null,
"else_ifs": [],
"end": 74,
"final_else": {

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -23,7 +24,6 @@ expression: actual
"type": "Literal",
"value": true
},
"digest": null,
"else_ifs": [
{
"cond": {
@ -48,7 +48,6 @@ expression: actual
"type": "CallExpression",
"type": "CallExpression"
},
"digest": null,
"end": 90,
"start": 44,
"then_val": {

View File

@ -1,6 +1,7 @@
---
source: kcl/src/parser/parser_impl.rs
expression: actual
snapshot_kind: text
---
{
"body": [
@ -48,8 +49,7 @@ expression: actual
}
}
]
},
"startNodes": []
}
},
"start": 0
}

View File

@ -81,7 +81,7 @@ fn unparse(test_name: &str) {
);
}
async fn execute(test_name: &str) {
async fn execute(test_name: &str, render_to_png: bool) {
// Read the AST from disk.
let input = read("ast.snap", test_name);
let ast_res: Result<Node<Program>, KclError> = get(&input);
@ -93,7 +93,9 @@ async fn execute(test_name: &str) {
let exec_res = crate::test_server::execute_and_snapshot_ast(ast, crate::settings::types::UnitLength::Mm).await;
match exec_res {
Ok((program_memory, png)) => {
twenty_twenty::assert_image(format!("tests/{test_name}/rendered_model.png"), &png, 0.99);
if render_to_png {
twenty_twenty::assert_image(format!("tests/{test_name}/rendered_model.png"), &png, 0.99);
}
assert_snapshot(test_name, "Program memory after executing", || {
insta::assert_json_snapshot!("program_memory", program_memory);
});
@ -130,6 +132,303 @@ mod cube {
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME).await
super::execute(TEST_NAME, true).await
}
}
mod helix_ccw {
const TEST_NAME: &str = "helix_ccw";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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, true).await
}
}
mod double_map_fn {
const TEST_NAME: &str = "double_map_fn";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod property_of_object {
const TEST_NAME: &str = "property_of_object";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod index_of_array {
const TEST_NAME: &str = "index_of_array";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod comparisons {
const TEST_NAME: &str = "comparisons";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod array_range_expr {
const TEST_NAME: &str = "array_range_expr";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod array_range_negative_expr {
const TEST_NAME: &str = "array_range_negative_expr";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod sketch_in_object {
const TEST_NAME: &str = "sketch_in_object";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod if_else {
const TEST_NAME: &str = "if_else";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod add_lots {
const TEST_NAME: &str = "add_lots";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}
mod array_elem_push {
const TEST_NAME: &str = "array_elem_push";
/// Test tokenizing KCL.
#[test]
fn tokenize() {
super::tokenize(TEST_NAME)
}
/// 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
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fn f = (i) => {
return i * 2
}
x = f(0) + f(1) + f(2) + f(3) + f(4) + f(5) + f(6) + f(7) + f(8) + f(9) + f(10) + f(11) + f(12) + f(13) + f(14) + f(15) + f(16) + f(17) + f(18) + f(19) + f(20) + f(21) + f(22) + f(23) + f(24) + f(25) + f(26) + f(27) + f(28) + f(29) + f(30) + f(31) + f(32) + f(33) + f(34) + f(35) + f(36) + f(37) + f(38) + f(39) + f(40) + f(41) + f(42) + f(43) + f(44) + f(45) + f(46) + f(47) + f(48) + f(49) + f(50) + f(51) + f(52) + f(53) + f(54) + f(55) + f(56) + f(57) + f(58) + f(59) + f(60) + f(61) + f(62) + f(63) + f(64) + f(65) + f(66) + f(67) + f(68) + f(69) + f(70) + f(71) + f(72) + f(73) + f(74) + f(75) + f(76) + f(77) + f(78) + f(79) + f(80) + f(81) + f(82) + f(83) + f(84) + f(85) + f(86) + f(87) + f(88) + f(89) + f(90) + f(91) + f(92) + f(93) + f(94) + f(95) + f(96) + f(97) + f(98) + f(99) + f(100)
assertEqual(x, 10100, 0.1, "Big sum")

View File

@ -0,0 +1,150 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing add_lots.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"f": {
"type": "Function",
"expression": {
"body": {
"body": [
{
"argument": {
"end": 30,
"left": {
"end": 26,
"name": "i",
"start": 25,
"type": "Identifier",
"type": "Identifier"
},
"operator": "*",
"right": {
"end": 30,
"raw": "2",
"start": 29,
"type": "Literal",
"type": "Literal",
"value": 2
},
"start": 25,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
"end": 30,
"start": 18,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"end": 32,
"start": 14
},
"end": 32,
"params": [
{
"type": "Parameter",
"identifier": {
"end": 9,
"name": "i",
"start": 8,
"type": "Identifier"
},
"optional": false
}
],
"start": 7,
"type": "FunctionExpression"
},
"memory": {
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
},
"__meta": [
{
"sourceRange": [
7,
32
]
}
]
},
"x": {
"type": "UserVal",
"type": "UserVal",
"value": 10100.0,
"__meta": [
{
"sourceRange": [
38,
834
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,768 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_elem_push.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"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
},
{
"end": 11,
"raw": "2",
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 2
},
{
"end": 14,
"raw": "3",
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
}
],
"end": 15,
"start": 6,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 0,
"type": "VariableDeclarator"
}
],
"end": 15,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 39,
"id": {
"end": 24,
"name": "new_arr1",
"start": 16,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 35,
"name": "arr",
"start": 32,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 38,
"raw": "4",
"start": 37,
"type": "Literal",
"type": "Literal",
"value": 4
}
],
"callee": {
"end": 31,
"name": "push",
"start": 27,
"type": "Identifier"
},
"end": 39,
"optional": false,
"start": 27,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 16,
"type": "VariableDeclarator"
}
],
"end": 39,
"kind": "const",
"start": 16,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 68,
"id": {
"end": 48,
"name": "new_arr2",
"start": 40,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 64,
"name": "new_arr1",
"start": 56,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 67,
"raw": "5",
"start": 66,
"type": "Literal",
"type": "Literal",
"value": 5
}
],
"callee": {
"end": 55,
"name": "push",
"start": 51,
"type": "Identifier"
},
"end": 68,
"optional": false,
"start": 51,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 40,
"type": "VariableDeclarator"
}
],
"end": 68,
"kind": "const",
"start": 40,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 142,
"expression": {
"arguments": [
{
"computed": false,
"end": 92,
"object": {
"end": 89,
"name": "new_arr1",
"start": 81,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 91,
"raw": "0",
"start": 90,
"type": "Literal",
"type": "Literal",
"value": 0
},
"start": 81,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 95,
"raw": "1",
"start": 94,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 104,
"raw": "0.00001",
"start": 97,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 141,
"raw": "\"element 0 should not have changed\"",
"start": 106,
"type": "Literal",
"type": "Literal",
"value": "element 0 should not have changed"
}
],
"callee": {
"end": 80,
"name": "assertEqual",
"start": 69,
"type": "Identifier"
},
"end": 142,
"optional": false,
"start": 69,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 69,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 216,
"expression": {
"arguments": [
{
"computed": false,
"end": 166,
"object": {
"end": 163,
"name": "new_arr1",
"start": 155,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 165,
"raw": "1",
"start": 164,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 155,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 169,
"raw": "2",
"start": 168,
"type": "Literal",
"type": "Literal",
"value": 2
},
{
"end": 178,
"raw": "0.00001",
"start": 171,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 215,
"raw": "\"element 1 should not have changed\"",
"start": 180,
"type": "Literal",
"type": "Literal",
"value": "element 1 should not have changed"
}
],
"callee": {
"end": 154,
"name": "assertEqual",
"start": 143,
"type": "Identifier"
},
"end": 216,
"optional": false,
"start": 143,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 143,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 290,
"expression": {
"arguments": [
{
"computed": false,
"end": 240,
"object": {
"end": 237,
"name": "new_arr1",
"start": 229,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 239,
"raw": "2",
"start": 238,
"type": "Literal",
"type": "Literal",
"value": 2
},
"start": 229,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 243,
"raw": "3",
"start": 242,
"type": "Literal",
"type": "Literal",
"value": 3
},
{
"end": 252,
"raw": "0.00001",
"start": 245,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 289,
"raw": "\"element 2 should not have changed\"",
"start": 254,
"type": "Literal",
"type": "Literal",
"value": "element 2 should not have changed"
}
],
"callee": {
"end": 228,
"name": "assertEqual",
"start": 217,
"type": "Identifier"
},
"end": 290,
"optional": false,
"start": 217,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 217,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 366,
"expression": {
"arguments": [
{
"computed": false,
"end": 314,
"object": {
"end": 311,
"name": "new_arr1",
"start": 303,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 313,
"raw": "3",
"start": 312,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 303,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 317,
"raw": "4",
"start": 316,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 326,
"raw": "0.00001",
"start": 319,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 365,
"raw": "\"4 was added to the end of the array\"",
"start": 328,
"type": "Literal",
"type": "Literal",
"value": "4 was added to the end of the array"
}
],
"callee": {
"end": 302,
"name": "assertEqual",
"start": 291,
"type": "Identifier"
},
"end": 366,
"optional": false,
"start": 291,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 291,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 440,
"expression": {
"arguments": [
{
"computed": false,
"end": 390,
"object": {
"end": 387,
"name": "new_arr2",
"start": 379,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 389,
"raw": "0",
"start": 388,
"type": "Literal",
"type": "Literal",
"value": 0
},
"start": 379,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 393,
"raw": "1",
"start": 392,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 402,
"raw": "0.00001",
"start": 395,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 439,
"raw": "\"element 0 should not have changed\"",
"start": 404,
"type": "Literal",
"type": "Literal",
"value": "element 0 should not have changed"
}
],
"callee": {
"end": 378,
"name": "assertEqual",
"start": 367,
"type": "Identifier"
},
"end": 440,
"optional": false,
"start": 367,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 367,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 514,
"expression": {
"arguments": [
{
"computed": false,
"end": 464,
"object": {
"end": 461,
"name": "new_arr2",
"start": 453,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 463,
"raw": "1",
"start": 462,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 453,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 467,
"raw": "2",
"start": 466,
"type": "Literal",
"type": "Literal",
"value": 2
},
{
"end": 476,
"raw": "0.00001",
"start": 469,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 513,
"raw": "\"element 1 should not have changed\"",
"start": 478,
"type": "Literal",
"type": "Literal",
"value": "element 1 should not have changed"
}
],
"callee": {
"end": 452,
"name": "assertEqual",
"start": 441,
"type": "Identifier"
},
"end": 514,
"optional": false,
"start": 441,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 441,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 588,
"expression": {
"arguments": [
{
"computed": false,
"end": 538,
"object": {
"end": 535,
"name": "new_arr2",
"start": 527,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 537,
"raw": "2",
"start": 536,
"type": "Literal",
"type": "Literal",
"value": 2
},
"start": 527,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 541,
"raw": "3",
"start": 540,
"type": "Literal",
"type": "Literal",
"value": 3
},
{
"end": 550,
"raw": "0.00001",
"start": 543,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 587,
"raw": "\"element 2 should not have changed\"",
"start": 552,
"type": "Literal",
"type": "Literal",
"value": "element 2 should not have changed"
}
],
"callee": {
"end": 526,
"name": "assertEqual",
"start": 515,
"type": "Identifier"
},
"end": 588,
"optional": false,
"start": 515,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 515,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 664,
"expression": {
"arguments": [
{
"computed": false,
"end": 612,
"object": {
"end": 609,
"name": "new_arr2",
"start": 601,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 611,
"raw": "3",
"start": 610,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 601,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 615,
"raw": "4",
"start": 614,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 624,
"raw": "0.00001",
"start": 617,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 663,
"raw": "\"4 was added to the end of the array\"",
"start": 626,
"type": "Literal",
"type": "Literal",
"value": "4 was added to the end of the array"
}
],
"callee": {
"end": 600,
"name": "assertEqual",
"start": 589,
"type": "Identifier"
},
"end": 664,
"optional": false,
"start": 589,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 589,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 740,
"expression": {
"arguments": [
{
"computed": false,
"end": 688,
"object": {
"end": 685,
"name": "new_arr2",
"start": 677,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 687,
"raw": "4",
"start": 686,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 677,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 691,
"raw": "5",
"start": 690,
"type": "Literal",
"type": "Literal",
"value": 5
},
{
"end": 700,
"raw": "0.00001",
"start": 693,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 739,
"raw": "\"5 was added to the end of the array\"",
"start": 702,
"type": "Literal",
"type": "Literal",
"value": "5 was added to the end of the array"
}
],
"callee": {
"end": 676,
"name": "assertEqual",
"start": 665,
"type": "Identifier"
},
"end": 740,
"optional": false,
"start": 665,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 665,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 741,
"start": 0
}
}

View File

@ -0,0 +1,94 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing array_elem_push.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"arr": {
"type": "UserVal",
"type": "UserVal",
"value": [
1,
2,
3
],
"__meta": [
{
"sourceRange": [
6,
15
]
}
]
},
"new_arr1": {
"type": "UserVal",
"type": "UserVal",
"value": [
1,
2,
3,
4
],
"__meta": [
{
"sourceRange": [
27,
39
]
}
]
},
"new_arr2": {
"type": "UserVal",
"type": "UserVal",
"value": [
1,
2,
3,
4,
5
],
"__meta": [
{
"sourceRange": [
51,
68
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,855 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_range_expr.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 11,
"id": {
"end": 2,
"name": "r1",
"start": 0,
"type": "Identifier"
},
"init": {
"end": 11,
"endElement": {
"end": 10,
"raw": "4",
"start": 9,
"type": "Literal",
"type": "Literal",
"value": 4
},
"endInclusive": true,
"start": 5,
"startElement": {
"end": 7,
"raw": "0",
"start": 6,
"type": "Literal",
"type": "Literal",
"value": 0
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 0,
"type": "VariableDeclarator"
}
],
"end": 11,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 70,
"expression": {
"arguments": [
{
"computed": false,
"end": 29,
"object": {
"end": 26,
"name": "r1",
"start": 24,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 28,
"raw": "4",
"start": 27,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 24,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 32,
"raw": "4",
"start": 31,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 41,
"raw": "0.00001",
"start": 34,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 69,
"raw": "\"last element is included\"",
"start": 43,
"type": "Literal",
"type": "Literal",
"value": "last element is included"
}
],
"callee": {
"end": 23,
"name": "assertEqual",
"start": 12,
"type": "Identifier"
},
"end": 70,
"optional": false,
"start": 12,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 12,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 80,
"id": {
"end": 76,
"name": "four",
"start": 72,
"type": "Identifier"
},
"init": {
"end": 80,
"raw": "4",
"start": 79,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 72,
"type": "VariableDeclarator"
}
],
"end": 80,
"kind": "const",
"start": 72,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 89,
"id": {
"end": 85,
"name": "zero",
"start": 81,
"type": "Identifier"
},
"init": {
"end": 89,
"raw": "0",
"start": 88,
"type": "Literal",
"type": "Literal",
"value": 0
},
"start": 81,
"type": "VariableDeclarator"
}
],
"end": 89,
"kind": "const",
"start": 81,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 107,
"id": {
"end": 92,
"name": "r2",
"start": 90,
"type": "Identifier"
},
"init": {
"end": 107,
"endElement": {
"end": 106,
"name": "four",
"start": 102,
"type": "Identifier",
"type": "Identifier"
},
"endInclusive": true,
"start": 95,
"startElement": {
"end": 100,
"name": "zero",
"start": 96,
"type": "Identifier",
"type": "Identifier"
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 90,
"type": "VariableDeclarator"
}
],
"end": 107,
"kind": "const",
"start": 90,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 166,
"expression": {
"arguments": [
{
"computed": false,
"end": 125,
"object": {
"end": 122,
"name": "r2",
"start": 120,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 124,
"raw": "4",
"start": 123,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 120,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 128,
"raw": "4",
"start": 127,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 137,
"raw": "0.00001",
"start": 130,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 165,
"raw": "\"last element is included\"",
"start": 139,
"type": "Literal",
"type": "Literal",
"value": "last element is included"
}
],
"callee": {
"end": 119,
"name": "assertEqual",
"start": 108,
"type": "Identifier"
},
"end": 166,
"optional": false,
"start": 108,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 108,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 188,
"id": {
"end": 172,
"name": "five",
"start": 168,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 187,
"left": {
"end": 183,
"name": "four",
"start": 179,
"type": "Identifier",
"type": "Identifier"
},
"operator": "+",
"right": {
"end": 187,
"raw": "1",
"start": 186,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 179,
"type": "BinaryExpression",
"type": "BinaryExpression"
}
],
"callee": {
"end": 178,
"name": "int",
"start": 175,
"type": "Identifier"
},
"end": 188,
"optional": false,
"start": 175,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 168,
"type": "VariableDeclarator"
}
],
"end": 188,
"kind": "const",
"start": 168,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 206,
"id": {
"end": 191,
"name": "r3",
"start": 189,
"type": "Identifier"
},
"init": {
"end": 206,
"endElement": {
"end": 205,
"name": "five",
"start": 201,
"type": "Identifier",
"type": "Identifier"
},
"endInclusive": true,
"start": 194,
"startElement": {
"end": 199,
"name": "zero",
"start": 195,
"type": "Identifier",
"type": "Identifier"
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 189,
"type": "VariableDeclarator"
}
],
"end": 206,
"kind": "const",
"start": 189,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 275,
"expression": {
"arguments": [
{
"computed": false,
"end": 224,
"object": {
"end": 221,
"name": "r3",
"start": 219,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 223,
"raw": "4",
"start": 222,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 219,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 227,
"raw": "4",
"start": 226,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 236,
"raw": "0.00001",
"start": 229,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 274,
"raw": "\"second-to-last element is included\"",
"start": 238,
"type": "Literal",
"type": "Literal",
"value": "second-to-last element is included"
}
],
"callee": {
"end": 218,
"name": "assertEqual",
"start": 207,
"type": "Identifier"
},
"end": 275,
"optional": false,
"start": 207,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 207,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 334,
"expression": {
"arguments": [
{
"computed": false,
"end": 293,
"object": {
"end": 290,
"name": "r3",
"start": 288,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 292,
"raw": "5",
"start": 291,
"type": "Literal",
"type": "Literal",
"value": 5
},
"start": 288,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 296,
"raw": "5",
"start": 295,
"type": "Literal",
"type": "Literal",
"value": 5
},
{
"end": 305,
"raw": "0.00001",
"start": 298,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 333,
"raw": "\"last element is included\"",
"start": 307,
"type": "Literal",
"type": "Literal",
"value": "last element is included"
}
],
"callee": {
"end": 287,
"name": "assertEqual",
"start": 276,
"type": "Identifier"
},
"end": 334,
"optional": false,
"start": 276,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 276,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 373,
"id": {
"end": 338,
"name": "r4",
"start": 336,
"type": "Identifier"
},
"init": {
"end": 373,
"endElement": {
"arguments": [
{
"end": 371,
"left": {
"end": 367,
"name": "five",
"start": 363,
"type": "Identifier",
"type": "Identifier"
},
"operator": "-",
"right": {
"end": 371,
"raw": "1",
"start": 370,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 363,
"type": "BinaryExpression",
"type": "BinaryExpression"
}
],
"callee": {
"end": 362,
"name": "int",
"start": 359,
"type": "Identifier"
},
"end": 372,
"optional": false,
"start": 359,
"type": "CallExpression",
"type": "CallExpression"
},
"endInclusive": true,
"start": 341,
"startElement": {
"arguments": [
{
"end": 354,
"left": {
"end": 350,
"name": "zero",
"start": 346,
"type": "Identifier",
"type": "Identifier"
},
"operator": "+",
"right": {
"end": 354,
"raw": "1",
"start": 353,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 346,
"type": "BinaryExpression",
"type": "BinaryExpression"
}
],
"callee": {
"end": 345,
"name": "int",
"start": 342,
"type": "Identifier"
},
"end": 355,
"optional": false,
"start": 342,
"type": "CallExpression",
"type": "CallExpression"
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 336,
"type": "VariableDeclarator"
}
],
"end": 373,
"kind": "const",
"start": 336,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 426,
"expression": {
"arguments": [
{
"computed": false,
"end": 391,
"object": {
"end": 388,
"name": "r4",
"start": 386,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 390,
"raw": "0",
"start": 389,
"type": "Literal",
"type": "Literal",
"value": 0
},
"start": 386,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 394,
"raw": "1",
"start": 393,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 403,
"raw": "0.00001",
"start": 396,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 425,
"raw": "\"first element is 1\"",
"start": 405,
"type": "Literal",
"type": "Literal",
"value": "first element is 1"
}
],
"callee": {
"end": 385,
"name": "assertEqual",
"start": 374,
"type": "Identifier"
},
"end": 426,
"optional": false,
"start": 374,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 374,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 488,
"expression": {
"arguments": [
{
"computed": false,
"end": 444,
"object": {
"end": 441,
"name": "r4",
"start": 439,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 443,
"raw": "2",
"start": 442,
"type": "Literal",
"type": "Literal",
"value": 2
},
"start": 439,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 447,
"raw": "3",
"start": 446,
"type": "Literal",
"type": "Literal",
"value": 3
},
{
"end": 456,
"raw": "0.00001",
"start": 449,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 487,
"raw": "\"second-to-last element is 3\"",
"start": 458,
"type": "Literal",
"type": "Literal",
"value": "second-to-last element is 3"
}
],
"callee": {
"end": 438,
"name": "assertEqual",
"start": 427,
"type": "Identifier"
},
"end": 488,
"optional": false,
"start": 427,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 427,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 540,
"expression": {
"arguments": [
{
"computed": false,
"end": 506,
"object": {
"end": 503,
"name": "r4",
"start": 501,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 505,
"raw": "3",
"start": 504,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 501,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"end": 509,
"raw": "4",
"start": 508,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 518,
"raw": "0.00001",
"start": 511,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 539,
"raw": "\"last element is 4\"",
"start": 520,
"type": "Literal",
"type": "Literal",
"value": "last element is 4"
}
],
"callee": {
"end": 500,
"name": "assertEqual",
"start": 489,
"type": "Identifier"
},
"end": 540,
"optional": false,
"start": 489,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 489,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 541,
"nonCodeMeta": {
"nonCodeNodes": {
"1": [
{
"end": 72,
"start": 70,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"5": [
{
"end": 168,
"start": 166,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"9": [
{
"end": 336,
"start": 334,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
}
},
"start": 0
}
}

View File

@ -0,0 +1,155 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing array_range_expr.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"five": {
"type": "UserVal",
"type": "UserVal",
"value": 5,
"__meta": [
{
"sourceRange": [
175,
188
]
}
]
},
"four": {
"type": "UserVal",
"type": "UserVal",
"value": 4,
"__meta": [
{
"sourceRange": [
79,
80
]
}
]
},
"r1": {
"type": "UserVal",
"type": "UserVal",
"value": [
0,
1,
2,
3,
4
],
"__meta": [
{
"sourceRange": [
5,
11
]
}
]
},
"r2": {
"type": "UserVal",
"type": "UserVal",
"value": [
0,
1,
2,
3,
4
],
"__meta": [
{
"sourceRange": [
95,
107
]
}
]
},
"r3": {
"type": "UserVal",
"type": "UserVal",
"value": [
0,
1,
2,
3,
4,
5
],
"__meta": [
{
"sourceRange": [
194,
206
]
}
]
},
"r4": {
"type": "UserVal",
"type": "UserVal",
"value": [
1,
2,
3,
4
],
"__meta": [
{
"sourceRange": [
341,
373
]
}
]
},
"zero": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": [
{
"sourceRange": [
88,
89
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,152 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_range_negative_expr.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 19,
"id": {
"end": 2,
"name": "xs",
"start": 0,
"type": "Identifier"
},
"init": {
"end": 19,
"endElement": {
"end": 18,
"raw": "5",
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 5
},
"endInclusive": true,
"start": 5,
"startElement": {
"arguments": [
{
"argument": {
"end": 12,
"raw": "5",
"start": 11,
"type": "Literal",
"type": "Literal",
"value": 5
},
"end": 12,
"operator": "-",
"start": 10,
"type": "UnaryExpression",
"type": "UnaryExpression"
}
],
"callee": {
"end": 9,
"name": "int",
"start": 6,
"type": "Identifier"
},
"end": 13,
"optional": false,
"start": 6,
"type": "CallExpression",
"type": "CallExpression"
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 0,
"type": "VariableDeclarator"
}
],
"end": 19,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 72,
"expression": {
"arguments": [
{
"computed": false,
"end": 37,
"object": {
"end": 34,
"name": "xs",
"start": 32,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 36,
"raw": "0",
"start": 35,
"type": "Literal",
"type": "Literal",
"value": 0
},
"start": 32,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"argument": {
"end": 41,
"raw": "5",
"start": 40,
"type": "Literal",
"type": "Literal",
"value": 5
},
"end": 41,
"operator": "-",
"start": 39,
"type": "UnaryExpression",
"type": "UnaryExpression"
},
{
"end": 48,
"raw": "0.001",
"start": 43,
"type": "Literal",
"type": "Literal",
"value": 0.001
},
{
"end": 71,
"raw": "\"first element is -5\"",
"start": 50,
"type": "Literal",
"type": "Literal",
"value": "first element is -5"
}
],
"callee": {
"end": 31,
"name": "assertEqual",
"start": 20,
"type": "Identifier"
},
"end": 72,
"optional": false,
"start": 20,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 20,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 73,
"start": 0
}
}

View File

@ -1,2 +1,2 @@
xs = [int(-5)..5]
xs = [int(-5) .. 5]
assertEqual(xs[0], -5, 0.001, "first element is -5")

View File

@ -0,0 +1,65 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing array_range_negative_expr.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"xs": {
"type": "UserVal",
"type": "UserVal",
"value": [
-5,
-4,
-3,
-2,
-1,
0,
1,
2,
3,
4,
5
],
"__meta": [
{
"sourceRange": [
5,
19
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -0,0 +1,213 @@
---
source: kcl/src/simulation_tests.rs
description: Result of tokenizing array_range_negative_expr.kcl
snapshot_kind: text
---
{
"Ok": [
{
"type": "word",
"start": 0,
"end": 2,
"value": "xs"
},
{
"type": "whitespace",
"start": 2,
"end": 3,
"value": " "
},
{
"type": "operator",
"start": 3,
"end": 4,
"value": "="
},
{
"type": "whitespace",
"start": 4,
"end": 5,
"value": " "
},
{
"type": "brace",
"start": 5,
"end": 6,
"value": "["
},
{
"type": "word",
"start": 6,
"end": 9,
"value": "int"
},
{
"type": "brace",
"start": 9,
"end": 10,
"value": "("
},
{
"type": "operator",
"start": 10,
"end": 11,
"value": "-"
},
{
"type": "number",
"start": 11,
"end": 12,
"value": "5"
},
{
"type": "brace",
"start": 12,
"end": 13,
"value": ")"
},
{
"type": "whitespace",
"start": 13,
"end": 14,
"value": " "
},
{
"type": "doublePeriod",
"start": 14,
"end": 16,
"value": ".."
},
{
"type": "whitespace",
"start": 16,
"end": 17,
"value": " "
},
{
"type": "number",
"start": 17,
"end": 18,
"value": "5"
},
{
"type": "brace",
"start": 18,
"end": 19,
"value": "]"
},
{
"type": "whitespace",
"start": 19,
"end": 20,
"value": "\n"
},
{
"type": "word",
"start": 20,
"end": 31,
"value": "assertEqual"
},
{
"type": "brace",
"start": 31,
"end": 32,
"value": "("
},
{
"type": "word",
"start": 32,
"end": 34,
"value": "xs"
},
{
"type": "brace",
"start": 34,
"end": 35,
"value": "["
},
{
"type": "number",
"start": 35,
"end": 36,
"value": "0"
},
{
"type": "brace",
"start": 36,
"end": 37,
"value": "]"
},
{
"type": "comma",
"start": 37,
"end": 38,
"value": ","
},
{
"type": "whitespace",
"start": 38,
"end": 39,
"value": " "
},
{
"type": "operator",
"start": 39,
"end": 40,
"value": "-"
},
{
"type": "number",
"start": 40,
"end": 41,
"value": "5"
},
{
"type": "comma",
"start": 41,
"end": 42,
"value": ","
},
{
"type": "whitespace",
"start": 42,
"end": 43,
"value": " "
},
{
"type": "number",
"start": 43,
"end": 48,
"value": "0.001"
},
{
"type": "comma",
"start": 48,
"end": 49,
"value": ","
},
{
"type": "whitespace",
"start": 49,
"end": 50,
"value": " "
},
{
"type": "string",
"start": 50,
"end": 71,
"value": "\"first element is -5\""
},
{
"type": "brace",
"start": 71,
"end": 72,
"value": ")"
},
{
"type": "whitespace",
"start": 72,
"end": 73,
"value": "\n"
}
]
}

View File

@ -0,0 +1,658 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing comparisons.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"end": 26,
"expression": {
"arguments": [
{
"end": 13,
"left": {
"end": 8,
"raw": "3",
"start": 7,
"type": "Literal",
"type": "Literal",
"value": 3
},
"operator": "==",
"right": {
"end": 13,
"raw": "3",
"start": 12,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 7,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 25,
"raw": "\"equality\"",
"start": 15,
"type": "Literal",
"type": "Literal",
"value": "equality"
}
],
"callee": {
"end": 6,
"name": "assert",
"start": 0,
"type": "Identifier"
},
"end": 26,
"optional": false,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 0,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 67,
"expression": {
"arguments": [
{
"end": 44,
"left": {
"end": 37,
"raw": "3.0",
"start": 34,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
"operator": "==",
"right": {
"end": 44,
"raw": "3.0",
"start": 41,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
"start": 34,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 66,
"raw": "\"equality of floats\"",
"start": 46,
"type": "Literal",
"type": "Literal",
"value": "equality of floats"
}
],
"callee": {
"end": 33,
"name": "assert",
"start": 27,
"type": "Identifier"
},
"end": 67,
"optional": false,
"start": 27,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 27,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 98,
"expression": {
"arguments": [
{
"end": 81,
"left": {
"end": 76,
"raw": "3",
"start": 75,
"type": "Literal",
"type": "Literal",
"value": 3
},
"operator": "!=",
"right": {
"end": 81,
"raw": "4",
"start": 80,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 75,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 97,
"raw": "\"non-equality\"",
"start": 83,
"type": "Literal",
"type": "Literal",
"value": "non-equality"
}
],
"callee": {
"end": 74,
"name": "assert",
"start": 68,
"type": "Identifier"
},
"end": 98,
"optional": false,
"start": 68,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 68,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 143,
"expression": {
"arguments": [
{
"end": 116,
"left": {
"end": 109,
"raw": "3.0",
"start": 106,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
"operator": "!=",
"right": {
"end": 116,
"raw": "4.0",
"start": 113,
"type": "Literal",
"type": "Literal",
"value": 4.0
},
"start": 106,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 142,
"raw": "\"non-equality of floats\"",
"start": 118,
"type": "Literal",
"type": "Literal",
"value": "non-equality of floats"
}
],
"callee": {
"end": 105,
"name": "assert",
"start": 99,
"type": "Identifier"
},
"end": 143,
"optional": false,
"start": 99,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 99,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 163,
"expression": {
"arguments": [
{
"end": 156,
"left": {
"end": 152,
"raw": "3",
"start": 151,
"type": "Literal",
"type": "Literal",
"value": 3
},
"operator": "<",
"right": {
"end": 156,
"raw": "4",
"start": 155,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 151,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 162,
"raw": "\"lt\"",
"start": 158,
"type": "Literal",
"type": "Literal",
"value": "lt"
}
],
"callee": {
"end": 150,
"name": "assert",
"start": 144,
"type": "Identifier"
},
"end": 163,
"optional": false,
"start": 144,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 144,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 201,
"expression": {
"arguments": [
{
"end": 177,
"left": {
"end": 172,
"raw": "3",
"start": 171,
"type": "Literal",
"type": "Literal",
"value": 3
},
"operator": "<=",
"right": {
"end": 177,
"raw": "4",
"start": 176,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 171,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 200,
"raw": "\"lte but actually lt\"",
"start": 179,
"type": "Literal",
"type": "Literal",
"value": "lte but actually lt"
}
],
"callee": {
"end": 170,
"name": "assert",
"start": 164,
"type": "Identifier"
},
"end": 201,
"optional": false,
"start": 164,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 164,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 239,
"expression": {
"arguments": [
{
"end": 215,
"left": {
"end": 210,
"raw": "4",
"start": 209,
"type": "Literal",
"type": "Literal",
"value": 4
},
"operator": "<=",
"right": {
"end": 215,
"raw": "4",
"start": 214,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 209,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 238,
"raw": "\"lte but actually eq\"",
"start": 217,
"type": "Literal",
"type": "Literal",
"value": "lte but actually eq"
}
],
"callee": {
"end": 208,
"name": "assert",
"start": 202,
"type": "Identifier"
},
"end": 239,
"optional": false,
"start": 202,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 202,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 259,
"expression": {
"arguments": [
{
"end": 252,
"left": {
"end": 248,
"raw": "4",
"start": 247,
"type": "Literal",
"type": "Literal",
"value": 4
},
"operator": ">",
"right": {
"end": 252,
"raw": "3",
"start": 251,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 247,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 258,
"raw": "\"gt\"",
"start": 254,
"type": "Literal",
"type": "Literal",
"value": "gt"
}
],
"callee": {
"end": 246,
"name": "assert",
"start": 240,
"type": "Identifier"
},
"end": 259,
"optional": false,
"start": 240,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 240,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 297,
"expression": {
"arguments": [
{
"end": 273,
"left": {
"end": 268,
"raw": "4",
"start": 267,
"type": "Literal",
"type": "Literal",
"value": 4
},
"operator": ">=",
"right": {
"end": 273,
"raw": "3",
"start": 272,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 267,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 296,
"raw": "\"gte but actually gt\"",
"start": 275,
"type": "Literal",
"type": "Literal",
"value": "gte but actually gt"
}
],
"callee": {
"end": 266,
"name": "assert",
"start": 260,
"type": "Identifier"
},
"end": 297,
"optional": false,
"start": 260,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 260,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 335,
"expression": {
"arguments": [
{
"end": 311,
"left": {
"end": 306,
"raw": "3",
"start": 305,
"type": "Literal",
"type": "Literal",
"value": 3
},
"operator": ">=",
"right": {
"end": 311,
"raw": "3",
"start": 310,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 305,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 334,
"raw": "\"gte but actually eq\"",
"start": 313,
"type": "Literal",
"type": "Literal",
"value": "gte but actually eq"
}
],
"callee": {
"end": 304,
"name": "assert",
"start": 298,
"type": "Identifier"
},
"end": 335,
"optional": false,
"start": 298,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 298,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 375,
"expression": {
"arguments": [
{
"end": 354,
"left": {
"end": 347,
"raw": "0.0",
"start": 344,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
"operator": "==",
"right": {
"end": 354,
"raw": "0.0",
"start": 351,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
"start": 344,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 374,
"raw": "\"equality of zero\"",
"start": 356,
"type": "Literal",
"type": "Literal",
"value": "equality of zero"
}
],
"callee": {
"end": 343,
"name": "assert",
"start": 337,
"type": "Identifier"
},
"end": 375,
"optional": false,
"start": 337,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 337,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 428,
"expression": {
"arguments": [
{
"end": 394,
"left": {
"end": 386,
"raw": "0.0",
"start": 383,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
"operator": "==",
"right": {
"argument": {
"end": 394,
"raw": "0.0",
"start": 391,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
"end": 394,
"operator": "-",
"start": 390,
"type": "UnaryExpression",
"type": "UnaryExpression"
},
"start": 383,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"end": 427,
"raw": "\"equality of zero and neg zero\"",
"start": 396,
"type": "Literal",
"type": "Literal",
"value": "equality of zero and neg zero"
}
],
"callee": {
"end": 382,
"name": "assert",
"start": 376,
"type": "Identifier"
},
"end": 428,
"optional": false,
"start": 376,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 376,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 429,
"nonCodeMeta": {
"nonCodeNodes": {
"9": [
{
"end": 337,
"start": 335,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
}
},
"start": 0
}
}

View File

@ -0,0 +1,40 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing comparisons.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -0,0 +1,879 @@
---
source: kcl/src/simulation_tests.rs
description: Result of tokenizing comparisons.kcl
snapshot_kind: text
---
{
"Ok": [
{
"type": "word",
"start": 0,
"end": 6,
"value": "assert"
},
{
"type": "brace",
"start": 6,
"end": 7,
"value": "("
},
{
"type": "number",
"start": 7,
"end": 8,
"value": "3"
},
{
"type": "whitespace",
"start": 8,
"end": 9,
"value": " "
},
{
"type": "operator",
"start": 9,
"end": 11,
"value": "=="
},
{
"type": "whitespace",
"start": 11,
"end": 12,
"value": " "
},
{
"type": "number",
"start": 12,
"end": 13,
"value": "3"
},
{
"type": "comma",
"start": 13,
"end": 14,
"value": ","
},
{
"type": "whitespace",
"start": 14,
"end": 15,
"value": " "
},
{
"type": "string",
"start": 15,
"end": 25,
"value": "\"equality\""
},
{
"type": "brace",
"start": 25,
"end": 26,
"value": ")"
},
{
"type": "whitespace",
"start": 26,
"end": 27,
"value": "\n"
},
{
"type": "word",
"start": 27,
"end": 33,
"value": "assert"
},
{
"type": "brace",
"start": 33,
"end": 34,
"value": "("
},
{
"type": "number",
"start": 34,
"end": 37,
"value": "3.0"
},
{
"type": "whitespace",
"start": 37,
"end": 38,
"value": " "
},
{
"type": "operator",
"start": 38,
"end": 40,
"value": "=="
},
{
"type": "whitespace",
"start": 40,
"end": 41,
"value": " "
},
{
"type": "number",
"start": 41,
"end": 44,
"value": "3.0"
},
{
"type": "comma",
"start": 44,
"end": 45,
"value": ","
},
{
"type": "whitespace",
"start": 45,
"end": 46,
"value": " "
},
{
"type": "string",
"start": 46,
"end": 66,
"value": "\"equality of floats\""
},
{
"type": "brace",
"start": 66,
"end": 67,
"value": ")"
},
{
"type": "whitespace",
"start": 67,
"end": 68,
"value": "\n"
},
{
"type": "word",
"start": 68,
"end": 74,
"value": "assert"
},
{
"type": "brace",
"start": 74,
"end": 75,
"value": "("
},
{
"type": "number",
"start": 75,
"end": 76,
"value": "3"
},
{
"type": "whitespace",
"start": 76,
"end": 77,
"value": " "
},
{
"type": "operator",
"start": 77,
"end": 79,
"value": "!="
},
{
"type": "whitespace",
"start": 79,
"end": 80,
"value": " "
},
{
"type": "number",
"start": 80,
"end": 81,
"value": "4"
},
{
"type": "comma",
"start": 81,
"end": 82,
"value": ","
},
{
"type": "whitespace",
"start": 82,
"end": 83,
"value": " "
},
{
"type": "string",
"start": 83,
"end": 97,
"value": "\"non-equality\""
},
{
"type": "brace",
"start": 97,
"end": 98,
"value": ")"
},
{
"type": "whitespace",
"start": 98,
"end": 99,
"value": "\n"
},
{
"type": "word",
"start": 99,
"end": 105,
"value": "assert"
},
{
"type": "brace",
"start": 105,
"end": 106,
"value": "("
},
{
"type": "number",
"start": 106,
"end": 109,
"value": "3.0"
},
{
"type": "whitespace",
"start": 109,
"end": 110,
"value": " "
},
{
"type": "operator",
"start": 110,
"end": 112,
"value": "!="
},
{
"type": "whitespace",
"start": 112,
"end": 113,
"value": " "
},
{
"type": "number",
"start": 113,
"end": 116,
"value": "4.0"
},
{
"type": "comma",
"start": 116,
"end": 117,
"value": ","
},
{
"type": "whitespace",
"start": 117,
"end": 118,
"value": " "
},
{
"type": "string",
"start": 118,
"end": 142,
"value": "\"non-equality of floats\""
},
{
"type": "brace",
"start": 142,
"end": 143,
"value": ")"
},
{
"type": "whitespace",
"start": 143,
"end": 144,
"value": "\n"
},
{
"type": "word",
"start": 144,
"end": 150,
"value": "assert"
},
{
"type": "brace",
"start": 150,
"end": 151,
"value": "("
},
{
"type": "number",
"start": 151,
"end": 152,
"value": "3"
},
{
"type": "whitespace",
"start": 152,
"end": 153,
"value": " "
},
{
"type": "operator",
"start": 153,
"end": 154,
"value": "<"
},
{
"type": "whitespace",
"start": 154,
"end": 155,
"value": " "
},
{
"type": "number",
"start": 155,
"end": 156,
"value": "4"
},
{
"type": "comma",
"start": 156,
"end": 157,
"value": ","
},
{
"type": "whitespace",
"start": 157,
"end": 158,
"value": " "
},
{
"type": "string",
"start": 158,
"end": 162,
"value": "\"lt\""
},
{
"type": "brace",
"start": 162,
"end": 163,
"value": ")"
},
{
"type": "whitespace",
"start": 163,
"end": 164,
"value": "\n"
},
{
"type": "word",
"start": 164,
"end": 170,
"value": "assert"
},
{
"type": "brace",
"start": 170,
"end": 171,
"value": "("
},
{
"type": "number",
"start": 171,
"end": 172,
"value": "3"
},
{
"type": "whitespace",
"start": 172,
"end": 173,
"value": " "
},
{
"type": "operator",
"start": 173,
"end": 175,
"value": "<="
},
{
"type": "whitespace",
"start": 175,
"end": 176,
"value": " "
},
{
"type": "number",
"start": 176,
"end": 177,
"value": "4"
},
{
"type": "comma",
"start": 177,
"end": 178,
"value": ","
},
{
"type": "whitespace",
"start": 178,
"end": 179,
"value": " "
},
{
"type": "string",
"start": 179,
"end": 200,
"value": "\"lte but actually lt\""
},
{
"type": "brace",
"start": 200,
"end": 201,
"value": ")"
},
{
"type": "whitespace",
"start": 201,
"end": 202,
"value": "\n"
},
{
"type": "word",
"start": 202,
"end": 208,
"value": "assert"
},
{
"type": "brace",
"start": 208,
"end": 209,
"value": "("
},
{
"type": "number",
"start": 209,
"end": 210,
"value": "4"
},
{
"type": "whitespace",
"start": 210,
"end": 211,
"value": " "
},
{
"type": "operator",
"start": 211,
"end": 213,
"value": "<="
},
{
"type": "whitespace",
"start": 213,
"end": 214,
"value": " "
},
{
"type": "number",
"start": 214,
"end": 215,
"value": "4"
},
{
"type": "comma",
"start": 215,
"end": 216,
"value": ","
},
{
"type": "whitespace",
"start": 216,
"end": 217,
"value": " "
},
{
"type": "string",
"start": 217,
"end": 238,
"value": "\"lte but actually eq\""
},
{
"type": "brace",
"start": 238,
"end": 239,
"value": ")"
},
{
"type": "whitespace",
"start": 239,
"end": 240,
"value": "\n"
},
{
"type": "word",
"start": 240,
"end": 246,
"value": "assert"
},
{
"type": "brace",
"start": 246,
"end": 247,
"value": "("
},
{
"type": "number",
"start": 247,
"end": 248,
"value": "4"
},
{
"type": "whitespace",
"start": 248,
"end": 249,
"value": " "
},
{
"type": "operator",
"start": 249,
"end": 250,
"value": ">"
},
{
"type": "whitespace",
"start": 250,
"end": 251,
"value": " "
},
{
"type": "number",
"start": 251,
"end": 252,
"value": "3"
},
{
"type": "comma",
"start": 252,
"end": 253,
"value": ","
},
{
"type": "whitespace",
"start": 253,
"end": 254,
"value": " "
},
{
"type": "string",
"start": 254,
"end": 258,
"value": "\"gt\""
},
{
"type": "brace",
"start": 258,
"end": 259,
"value": ")"
},
{
"type": "whitespace",
"start": 259,
"end": 260,
"value": "\n"
},
{
"type": "word",
"start": 260,
"end": 266,
"value": "assert"
},
{
"type": "brace",
"start": 266,
"end": 267,
"value": "("
},
{
"type": "number",
"start": 267,
"end": 268,
"value": "4"
},
{
"type": "whitespace",
"start": 268,
"end": 269,
"value": " "
},
{
"type": "operator",
"start": 269,
"end": 271,
"value": ">="
},
{
"type": "whitespace",
"start": 271,
"end": 272,
"value": " "
},
{
"type": "number",
"start": 272,
"end": 273,
"value": "3"
},
{
"type": "comma",
"start": 273,
"end": 274,
"value": ","
},
{
"type": "whitespace",
"start": 274,
"end": 275,
"value": " "
},
{
"type": "string",
"start": 275,
"end": 296,
"value": "\"gte but actually gt\""
},
{
"type": "brace",
"start": 296,
"end": 297,
"value": ")"
},
{
"type": "whitespace",
"start": 297,
"end": 298,
"value": "\n"
},
{
"type": "word",
"start": 298,
"end": 304,
"value": "assert"
},
{
"type": "brace",
"start": 304,
"end": 305,
"value": "("
},
{
"type": "number",
"start": 305,
"end": 306,
"value": "3"
},
{
"type": "whitespace",
"start": 306,
"end": 307,
"value": " "
},
{
"type": "operator",
"start": 307,
"end": 309,
"value": ">="
},
{
"type": "whitespace",
"start": 309,
"end": 310,
"value": " "
},
{
"type": "number",
"start": 310,
"end": 311,
"value": "3"
},
{
"type": "comma",
"start": 311,
"end": 312,
"value": ","
},
{
"type": "whitespace",
"start": 312,
"end": 313,
"value": " "
},
{
"type": "string",
"start": 313,
"end": 334,
"value": "\"gte but actually eq\""
},
{
"type": "brace",
"start": 334,
"end": 335,
"value": ")"
},
{
"type": "whitespace",
"start": 335,
"end": 337,
"value": "\n\n"
},
{
"type": "word",
"start": 337,
"end": 343,
"value": "assert"
},
{
"type": "brace",
"start": 343,
"end": 344,
"value": "("
},
{
"type": "number",
"start": 344,
"end": 347,
"value": "0.0"
},
{
"type": "whitespace",
"start": 347,
"end": 348,
"value": " "
},
{
"type": "operator",
"start": 348,
"end": 350,
"value": "=="
},
{
"type": "whitespace",
"start": 350,
"end": 351,
"value": " "
},
{
"type": "number",
"start": 351,
"end": 354,
"value": "0.0"
},
{
"type": "comma",
"start": 354,
"end": 355,
"value": ","
},
{
"type": "whitespace",
"start": 355,
"end": 356,
"value": " "
},
{
"type": "string",
"start": 356,
"end": 374,
"value": "\"equality of zero\""
},
{
"type": "brace",
"start": 374,
"end": 375,
"value": ")"
},
{
"type": "whitespace",
"start": 375,
"end": 376,
"value": "\n"
},
{
"type": "word",
"start": 376,
"end": 382,
"value": "assert"
},
{
"type": "brace",
"start": 382,
"end": 383,
"value": "("
},
{
"type": "number",
"start": 383,
"end": 386,
"value": "0.0"
},
{
"type": "whitespace",
"start": 386,
"end": 387,
"value": " "
},
{
"type": "operator",
"start": 387,
"end": 389,
"value": "=="
},
{
"type": "whitespace",
"start": 389,
"end": 390,
"value": " "
},
{
"type": "operator",
"start": 390,
"end": 391,
"value": "-"
},
{
"type": "number",
"start": 391,
"end": 394,
"value": "0.0"
},
{
"type": "comma",
"start": 394,
"end": 395,
"value": ","
},
{
"type": "whitespace",
"start": 395,
"end": 396,
"value": " "
},
{
"type": "string",
"start": 396,
"end": 427,
"value": "\"equality of zero and neg zero\""
},
{
"type": "brace",
"start": 427,
"end": 428,
"value": ")"
},
{
"type": "whitespace",
"start": 428,
"end": 429,
"value": "\n"
}
]
}

View File

@ -664,8 +664,7 @@ snapshot_kind: text
}
}
]
},
"startNodes": []
}
},
"start": 30
},
@ -787,8 +786,7 @@ snapshot_kind: text
}
}
]
},
"startNodes": []
}
},
"start": 0
}

View File

@ -1,7 +0,0 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 98
description: Error from executing cube.kcl
snapshot_kind: text
---
No API token found in environment variables. Use KITTYCAD_API_TOKEN or ZOO_API_TOKEN

View File

@ -681,8 +681,7 @@ snapshot_kind: text
}
}
]
},
"startNodes": []
}
},
"start": 30
},

View File

@ -0,0 +1,233 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing double_map_fn.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 40,
"id": {
"end": 12,
"name": "increment",
"start": 3,
"type": "Identifier"
},
"init": {
"body": {
"body": [
{
"argument": {
"end": 38,
"left": {
"end": 34,
"name": "i",
"start": 33,
"type": "Identifier",
"type": "Identifier"
},
"operator": "+",
"right": {
"end": 38,
"raw": "1",
"start": 37,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 33,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
"end": 38,
"start": 26,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"end": 40,
"start": 22
},
"end": 40,
"params": [
{
"type": "Parameter",
"identifier": {
"end": 17,
"name": "i",
"start": 16,
"type": "Identifier"
},
"optional": false
}
],
"start": 15,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 3,
"type": "VariableDeclarator"
}
],
"end": 40,
"kind": "fn",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 53,
"id": {
"end": 44,
"name": "xs",
"start": 42,
"type": "Identifier"
},
"init": {
"end": 53,
"endElement": {
"end": 52,
"raw": "2",
"start": 51,
"type": "Literal",
"type": "Literal",
"value": 2
},
"endInclusive": true,
"start": 47,
"startElement": {
"end": 49,
"raw": "0",
"start": 48,
"type": "Literal",
"type": "Literal",
"value": 0
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
},
"start": 42,
"type": "VariableDeclarator"
}
],
"end": 53,
"kind": "const",
"start": 42,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 107,
"id": {
"end": 56,
"name": "ys",
"start": 54,
"type": "Identifier"
},
"init": {
"body": [
{
"end": 61,
"name": "xs",
"start": 59,
"type": "Identifier",
"type": "Identifier"
},
{
"arguments": [
{
"end": 72,
"start": 71,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
},
{
"end": 83,
"name": "increment",
"start": 74,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 70,
"name": "map",
"start": 67,
"type": "Identifier"
},
"end": 84,
"optional": false,
"start": 67,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 95,
"start": 94,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
},
{
"end": 106,
"name": "increment",
"start": 97,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 93,
"name": "map",
"start": 90,
"type": "Identifier"
},
"end": 107,
"optional": false,
"start": 90,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 107,
"start": 59,
"type": "PipeExpression",
"type": "PipeExpression"
},
"start": 54,
"type": "VariableDeclarator"
}
],
"end": 107,
"kind": "const",
"start": 54,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
}
],
"end": 108,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [
{
"end": 42,
"start": 40,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
}
},
"start": 0
}
}

View File

@ -0,0 +1,8 @@
fn increment = (i) => {
return i + 1
}
xs = [0..2]
ys = xs
|> map(%, increment)
|> map(%, increment)

View File

@ -0,0 +1,171 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing double_map_fn.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"increment": {
"type": "Function",
"expression": {
"body": {
"body": [
{
"argument": {
"end": 38,
"left": {
"end": 34,
"name": "i",
"start": 33,
"type": "Identifier",
"type": "Identifier"
},
"operator": "+",
"right": {
"end": 38,
"raw": "1",
"start": 37,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 33,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
"end": 38,
"start": 26,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"end": 40,
"start": 22
},
"end": 40,
"params": [
{
"type": "Parameter",
"identifier": {
"end": 17,
"name": "i",
"start": 16,
"type": "Identifier"
},
"optional": false
}
],
"start": 15,
"type": "FunctionExpression"
},
"memory": {
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
},
"__meta": [
{
"sourceRange": [
15,
40
]
}
]
},
"xs": {
"type": "UserVal",
"type": "UserVal",
"value": [
0,
1,
2
],
"__meta": [
{
"sourceRange": [
47,
53
]
}
]
},
"ys": {
"type": "UserVal",
"type": "UserVal",
"value": [
2.0,
3.0,
4.0
],
"__meta": [
{
"sourceRange": [
90,
107
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -0,0 +1,369 @@
---
source: kcl/src/simulation_tests.rs
description: Result of tokenizing double_map_fn.kcl
snapshot_kind: text
---
{
"Ok": [
{
"type": "keyword",
"start": 0,
"end": 2,
"value": "fn"
},
{
"type": "whitespace",
"start": 2,
"end": 3,
"value": " "
},
{
"type": "word",
"start": 3,
"end": 12,
"value": "increment"
},
{
"type": "whitespace",
"start": 12,
"end": 13,
"value": " "
},
{
"type": "operator",
"start": 13,
"end": 14,
"value": "="
},
{
"type": "whitespace",
"start": 14,
"end": 15,
"value": " "
},
{
"type": "brace",
"start": 15,
"end": 16,
"value": "("
},
{
"type": "word",
"start": 16,
"end": 17,
"value": "i"
},
{
"type": "brace",
"start": 17,
"end": 18,
"value": ")"
},
{
"type": "whitespace",
"start": 18,
"end": 19,
"value": " "
},
{
"type": "operator",
"start": 19,
"end": 21,
"value": "=>"
},
{
"type": "whitespace",
"start": 21,
"end": 22,
"value": " "
},
{
"type": "brace",
"start": 22,
"end": 23,
"value": "{"
},
{
"type": "whitespace",
"start": 23,
"end": 26,
"value": "\n "
},
{
"type": "keyword",
"start": 26,
"end": 32,
"value": "return"
},
{
"type": "whitespace",
"start": 32,
"end": 33,
"value": " "
},
{
"type": "word",
"start": 33,
"end": 34,
"value": "i"
},
{
"type": "whitespace",
"start": 34,
"end": 35,
"value": " "
},
{
"type": "operator",
"start": 35,
"end": 36,
"value": "+"
},
{
"type": "whitespace",
"start": 36,
"end": 37,
"value": " "
},
{
"type": "number",
"start": 37,
"end": 38,
"value": "1"
},
{
"type": "whitespace",
"start": 38,
"end": 39,
"value": "\n"
},
{
"type": "brace",
"start": 39,
"end": 40,
"value": "}"
},
{
"type": "whitespace",
"start": 40,
"end": 42,
"value": "\n\n"
},
{
"type": "word",
"start": 42,
"end": 44,
"value": "xs"
},
{
"type": "whitespace",
"start": 44,
"end": 45,
"value": " "
},
{
"type": "operator",
"start": 45,
"end": 46,
"value": "="
},
{
"type": "whitespace",
"start": 46,
"end": 47,
"value": " "
},
{
"type": "brace",
"start": 47,
"end": 48,
"value": "["
},
{
"type": "number",
"start": 48,
"end": 49,
"value": "0"
},
{
"type": "doublePeriod",
"start": 49,
"end": 51,
"value": ".."
},
{
"type": "number",
"start": 51,
"end": 52,
"value": "2"
},
{
"type": "brace",
"start": 52,
"end": 53,
"value": "]"
},
{
"type": "whitespace",
"start": 53,
"end": 54,
"value": "\n"
},
{
"type": "word",
"start": 54,
"end": 56,
"value": "ys"
},
{
"type": "whitespace",
"start": 56,
"end": 57,
"value": " "
},
{
"type": "operator",
"start": 57,
"end": 58,
"value": "="
},
{
"type": "whitespace",
"start": 58,
"end": 59,
"value": " "
},
{
"type": "word",
"start": 59,
"end": 61,
"value": "xs"
},
{
"type": "whitespace",
"start": 61,
"end": 64,
"value": "\n "
},
{
"type": "operator",
"start": 64,
"end": 66,
"value": "|>"
},
{
"type": "whitespace",
"start": 66,
"end": 67,
"value": " "
},
{
"type": "word",
"start": 67,
"end": 70,
"value": "map"
},
{
"type": "brace",
"start": 70,
"end": 71,
"value": "("
},
{
"type": "operator",
"start": 71,
"end": 72,
"value": "%"
},
{
"type": "comma",
"start": 72,
"end": 73,
"value": ","
},
{
"type": "whitespace",
"start": 73,
"end": 74,
"value": " "
},
{
"type": "word",
"start": 74,
"end": 83,
"value": "increment"
},
{
"type": "brace",
"start": 83,
"end": 84,
"value": ")"
},
{
"type": "whitespace",
"start": 84,
"end": 87,
"value": "\n "
},
{
"type": "operator",
"start": 87,
"end": 89,
"value": "|>"
},
{
"type": "whitespace",
"start": 89,
"end": 90,
"value": " "
},
{
"type": "word",
"start": 90,
"end": 93,
"value": "map"
},
{
"type": "brace",
"start": 93,
"end": 94,
"value": "("
},
{
"type": "operator",
"start": 94,
"end": 95,
"value": "%"
},
{
"type": "comma",
"start": 95,
"end": 96,
"value": ","
},
{
"type": "whitespace",
"start": 96,
"end": 97,
"value": " "
},
{
"type": "word",
"start": 97,
"end": 106,
"value": "increment"
},
{
"type": "brace",
"start": 106,
"end": 107,
"value": ")"
},
{
"type": "whitespace",
"start": 107,
"end": 108,
"value": "\n"
}
]
}

View File

@ -0,0 +1,262 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing helix_ccw.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 183,
"id": {
"end": 7,
"name": "part001",
"start": 0,
"type": "Identifier"
},
"init": {
"body": [
{
"arguments": [
{
"end": 28,
"raw": "'XY'",
"start": 24,
"type": "Literal",
"type": "Literal",
"value": "XY"
}
],
"callee": {
"end": 23,
"name": "startSketchOn",
"start": 10,
"type": "Identifier"
},
"end": 29,
"optional": false,
"start": 10,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 72,
"properties": [
{
"end": 58,
"key": {
"end": 50,
"name": "center",
"start": 44,
"type": "Identifier"
},
"start": 44,
"type": "ObjectProperty",
"value": {
"elements": [
{
"end": 54,
"raw": "5",
"start": 53,
"type": "Literal",
"type": "Literal",
"value": 5
},
{
"end": 57,
"raw": "5",
"start": 56,
"type": "Literal",
"type": "Literal",
"value": 5
}
],
"end": 58,
"start": 52,
"type": "ArrayExpression",
"type": "ArrayExpression"
}
},
{
"end": 70,
"key": {
"end": 66,
"name": "radius",
"start": 60,
"type": "Identifier"
},
"start": 60,
"type": "ObjectProperty",
"value": {
"end": 70,
"raw": "10",
"start": 68,
"type": "Literal",
"type": "Literal",
"value": 10
}
}
],
"start": 42,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
{
"end": 75,
"start": 74,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 41,
"name": "circle",
"start": 35,
"type": "Identifier"
},
"end": 76,
"optional": false,
"start": 35,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 92,
"raw": "10",
"start": 90,
"type": "Literal",
"type": "Literal",
"value": 10
},
{
"end": 95,
"start": 94,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 89,
"name": "extrude",
"start": 82,
"type": "Identifier"
},
"end": 96,
"optional": false,
"start": 82,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 179,
"properties": [
{
"end": 132,
"key": {
"end": 128,
"name": "revolutions",
"start": 117,
"type": "Identifier"
},
"start": 117,
"type": "ObjectProperty",
"value": {
"end": 132,
"raw": "16",
"start": 130,
"type": "Literal",
"type": "Literal",
"value": 16
}
},
{
"end": 154,
"key": {
"end": 151,
"name": "angleStart",
"start": 141,
"type": "Identifier"
},
"start": 141,
"type": "ObjectProperty",
"value": {
"end": 154,
"raw": "0",
"start": 153,
"type": "Literal",
"type": "Literal",
"value": 0
}
},
{
"end": 172,
"key": {
"end": 166,
"name": "ccw",
"start": 163,
"type": "Identifier"
},
"start": 163,
"type": "ObjectProperty",
"value": {
"end": 172,
"raw": "true",
"start": 168,
"type": "Literal",
"type": "Literal",
"value": true
}
}
],
"start": 108,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
{
"end": 182,
"start": 181,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 107,
"name": "helix",
"start": 102,
"type": "Identifier"
},
"end": 183,
"optional": false,
"start": 102,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 183,
"start": 10,
"type": "PipeExpression",
"type": "PipeExpression"
},
"start": 0,
"type": "VariableDeclarator"
}
],
"end": 183,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
}
],
"end": 184,
"start": 0
}
}

View File

@ -0,0 +1,8 @@
part001 = startSketchOn('XY')
|> circle({ center: [5, 5], radius: 10 }, %)
|> extrude(10, %)
|> helix({
revolutions: 16,
angleStart: 0,
ccw: true
}, %)

View File

@ -0,0 +1,151 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing helix_ccw.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"part001": {
"type": "Solid",
"type": "Solid",
"id": "[uuid]",
"value": [
{
"faceId": "[uuid]",
"id": "[uuid]",
"sourceRange": [
35,
76
],
"tag": null,
"type": "extrudeArc"
}
],
"sketch": {
"type": "Sketch",
"id": "[uuid]",
"paths": [
{
"__geoMeta": {
"id": "[uuid]",
"sourceRange": [
35,
76
]
},
"ccw": true,
"center": [
5.0,
5.0
],
"from": [
5.0,
5.0
],
"radius": 10.0,
"tag": null,
"to": [
5.0,
5.0
],
"type": "Circle"
}
],
"on": {
"type": "plane",
"id": "[uuid]",
"value": "XY",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"xAxis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"yAxis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"zAxis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"__meta": []
},
"start": {
"from": [
15.0,
5.0
],
"to": [
15.0,
5.0
],
"tag": null,
"__geoMeta": {
"id": "[uuid]",
"sourceRange": [
35,
76
]
}
},
"__meta": [
{
"sourceRange": [
35,
76
]
}
]
},
"height": 10.0,
"startCapId": "[uuid]",
"endCapId": "[uuid]",
"__meta": [
{
"sourceRange": [
35,
76
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@ -0,0 +1,465 @@
---
source: kcl/src/simulation_tests.rs
description: Result of tokenizing helix_ccw.kcl
snapshot_kind: text
---
{
"Ok": [
{
"type": "word",
"start": 0,
"end": 7,
"value": "part001"
},
{
"type": "whitespace",
"start": 7,
"end": 8,
"value": " "
},
{
"type": "operator",
"start": 8,
"end": 9,
"value": "="
},
{
"type": "whitespace",
"start": 9,
"end": 10,
"value": " "
},
{
"type": "word",
"start": 10,
"end": 23,
"value": "startSketchOn"
},
{
"type": "brace",
"start": 23,
"end": 24,
"value": "("
},
{
"type": "string",
"start": 24,
"end": 28,
"value": "'XY'"
},
{
"type": "brace",
"start": 28,
"end": 29,
"value": ")"
},
{
"type": "whitespace",
"start": 29,
"end": 32,
"value": "\n "
},
{
"type": "operator",
"start": 32,
"end": 34,
"value": "|>"
},
{
"type": "whitespace",
"start": 34,
"end": 35,
"value": " "
},
{
"type": "word",
"start": 35,
"end": 41,
"value": "circle"
},
{
"type": "brace",
"start": 41,
"end": 42,
"value": "("
},
{
"type": "brace",
"start": 42,
"end": 43,
"value": "{"
},
{
"type": "whitespace",
"start": 43,
"end": 44,
"value": " "
},
{
"type": "word",
"start": 44,
"end": 50,
"value": "center"
},
{
"type": "colon",
"start": 50,
"end": 51,
"value": ":"
},
{
"type": "whitespace",
"start": 51,
"end": 52,
"value": " "
},
{
"type": "brace",
"start": 52,
"end": 53,
"value": "["
},
{
"type": "number",
"start": 53,
"end": 54,
"value": "5"
},
{
"type": "comma",
"start": 54,
"end": 55,
"value": ","
},
{
"type": "whitespace",
"start": 55,
"end": 56,
"value": " "
},
{
"type": "number",
"start": 56,
"end": 57,
"value": "5"
},
{
"type": "brace",
"start": 57,
"end": 58,
"value": "]"
},
{
"type": "comma",
"start": 58,
"end": 59,
"value": ","
},
{
"type": "whitespace",
"start": 59,
"end": 60,
"value": " "
},
{
"type": "word",
"start": 60,
"end": 66,
"value": "radius"
},
{
"type": "colon",
"start": 66,
"end": 67,
"value": ":"
},
{
"type": "whitespace",
"start": 67,
"end": 68,
"value": " "
},
{
"type": "number",
"start": 68,
"end": 70,
"value": "10"
},
{
"type": "whitespace",
"start": 70,
"end": 71,
"value": " "
},
{
"type": "brace",
"start": 71,
"end": 72,
"value": "}"
},
{
"type": "comma",
"start": 72,
"end": 73,
"value": ","
},
{
"type": "whitespace",
"start": 73,
"end": 74,
"value": " "
},
{
"type": "operator",
"start": 74,
"end": 75,
"value": "%"
},
{
"type": "brace",
"start": 75,
"end": 76,
"value": ")"
},
{
"type": "whitespace",
"start": 76,
"end": 79,
"value": "\n "
},
{
"type": "operator",
"start": 79,
"end": 81,
"value": "|>"
},
{
"type": "whitespace",
"start": 81,
"end": 82,
"value": " "
},
{
"type": "word",
"start": 82,
"end": 89,
"value": "extrude"
},
{
"type": "brace",
"start": 89,
"end": 90,
"value": "("
},
{
"type": "number",
"start": 90,
"end": 92,
"value": "10"
},
{
"type": "comma",
"start": 92,
"end": 93,
"value": ","
},
{
"type": "whitespace",
"start": 93,
"end": 94,
"value": " "
},
{
"type": "operator",
"start": 94,
"end": 95,
"value": "%"
},
{
"type": "brace",
"start": 95,
"end": 96,
"value": ")"
},
{
"type": "whitespace",
"start": 96,
"end": 99,
"value": "\n "
},
{
"type": "operator",
"start": 99,
"end": 101,
"value": "|>"
},
{
"type": "whitespace",
"start": 101,
"end": 102,
"value": " "
},
{
"type": "word",
"start": 102,
"end": 107,
"value": "helix"
},
{
"type": "brace",
"start": 107,
"end": 108,
"value": "("
},
{
"type": "brace",
"start": 108,
"end": 109,
"value": "{"
},
{
"type": "whitespace",
"start": 109,
"end": 117,
"value": "\n "
},
{
"type": "word",
"start": 117,
"end": 128,
"value": "revolutions"
},
{
"type": "colon",
"start": 128,
"end": 129,
"value": ":"
},
{
"type": "whitespace",
"start": 129,
"end": 130,
"value": " "
},
{
"type": "number",
"start": 130,
"end": 132,
"value": "16"
},
{
"type": "comma",
"start": 132,
"end": 133,
"value": ","
},
{
"type": "whitespace",
"start": 133,
"end": 141,
"value": "\n "
},
{
"type": "word",
"start": 141,
"end": 151,
"value": "angleStart"
},
{
"type": "colon",
"start": 151,
"end": 152,
"value": ":"
},
{
"type": "whitespace",
"start": 152,
"end": 153,
"value": " "
},
{
"type": "number",
"start": 153,
"end": 154,
"value": "0"
},
{
"type": "comma",
"start": 154,
"end": 155,
"value": ","
},
{
"type": "whitespace",
"start": 155,
"end": 163,
"value": "\n "
},
{
"type": "word",
"start": 163,
"end": 166,
"value": "ccw"
},
{
"type": "colon",
"start": 166,
"end": 167,
"value": ":"
},
{
"type": "whitespace",
"start": 167,
"end": 168,
"value": " "
},
{
"type": "keyword",
"start": 168,
"end": 172,
"value": "true"
},
{
"type": "whitespace",
"start": 172,
"end": 178,
"value": "\n "
},
{
"type": "brace",
"start": 178,
"end": 179,
"value": "}"
},
{
"type": "comma",
"start": 179,
"end": 180,
"value": ","
},
{
"type": "whitespace",
"start": 180,
"end": 181,
"value": " "
},
{
"type": "operator",
"start": 181,
"end": 182,
"value": "%"
},
{
"type": "brace",
"start": 182,
"end": 183,
"value": ")"
},
{
"type": "whitespace",
"start": 183,
"end": 184,
"value": "\n"
}
]
}

View File

@ -0,0 +1,540 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing if_else.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 101,
"id": {
"end": 49,
"name": "a",
"start": 48,
"type": "Identifier"
},
"init": {
"cond": {
"end": 59,
"raw": "true",
"start": 55,
"type": "Literal",
"type": "Literal",
"value": true
},
"else_ifs": [
{
"cond": {
"end": 80,
"raw": "true",
"start": 76,
"type": "Literal",
"type": "Literal",
"value": true
},
"end": 88,
"start": 68,
"then_val": {
"body": [
{
"end": 86,
"expression": {
"end": 86,
"raw": "4",
"start": 85,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 85,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 87,
"start": 81
},
"type": "ElseIf"
}
],
"end": 101,
"final_else": {
"body": [
{
"end": 99,
"expression": {
"end": 99,
"raw": "5",
"start": 98,
"type": "Literal",
"type": "Literal",
"value": 5
},
"start": 98,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 100,
"start": 98
},
"start": 52,
"then_val": {
"body": [
{
"end": 65,
"expression": {
"end": 65,
"raw": "3",
"start": 64,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 64,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 66,
"start": 64
},
"type": "IfExpression",
"type": "IfExpression"
},
"start": 48,
"type": "VariableDeclarator"
}
],
"end": 101,
"kind": "const",
"start": 48,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 159,
"expression": {
"arguments": [
{
"end": 115,
"name": "a",
"start": 114,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 118,
"raw": "3",
"start": 117,
"type": "Literal",
"type": "Literal",
"value": 3
},
{
"end": 125,
"raw": "0.001",
"start": 120,
"type": "Literal",
"type": "Literal",
"value": 0.001
},
{
"end": 158,
"raw": "\"the 'if' branch gets returned\"",
"start": 127,
"type": "Literal",
"type": "Literal",
"value": "the 'if' branch gets returned"
}
],
"callee": {
"end": 113,
"name": "assertEqual",
"start": 102,
"type": "Identifier"
},
"end": 159,
"optional": false,
"start": 102,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 102,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 215,
"id": {
"end": 162,
"name": "b",
"start": 161,
"type": "Identifier"
},
"init": {
"cond": {
"end": 173,
"raw": "false",
"start": 168,
"type": "Literal",
"type": "Literal",
"value": false
},
"else_ifs": [
{
"cond": {
"end": 194,
"raw": "true",
"start": 190,
"type": "Literal",
"type": "Literal",
"value": true
},
"end": 202,
"start": 182,
"then_val": {
"body": [
{
"end": 200,
"expression": {
"end": 200,
"raw": "4",
"start": 199,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 199,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 201,
"start": 195
},
"type": "ElseIf"
}
],
"end": 215,
"final_else": {
"body": [
{
"end": 213,
"expression": {
"end": 213,
"raw": "5",
"start": 212,
"type": "Literal",
"type": "Literal",
"value": 5
},
"start": 212,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 214,
"start": 212
},
"start": 165,
"then_val": {
"body": [
{
"end": 179,
"expression": {
"end": 179,
"raw": "3",
"start": 178,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 178,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 180,
"start": 178
},
"type": "IfExpression",
"type": "IfExpression"
},
"start": 161,
"type": "VariableDeclarator"
}
],
"end": 215,
"kind": "const",
"start": 161,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 278,
"expression": {
"arguments": [
{
"end": 229,
"name": "b",
"start": 228,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 232,
"raw": "4",
"start": 231,
"type": "Literal",
"type": "Literal",
"value": 4
},
{
"end": 239,
"raw": "0.001",
"start": 234,
"type": "Literal",
"type": "Literal",
"value": 0.001
},
{
"end": 277,
"raw": "\"the 'else if' branch gets returned\"",
"start": 241,
"type": "Literal",
"type": "Literal",
"value": "the 'else if' branch gets returned"
}
],
"callee": {
"end": 227,
"name": "assertEqual",
"start": 216,
"type": "Identifier"
},
"end": 278,
"optional": false,
"start": 216,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 216,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 335,
"id": {
"end": 281,
"name": "c",
"start": 280,
"type": "Identifier"
},
"init": {
"cond": {
"end": 292,
"raw": "false",
"start": 287,
"type": "Literal",
"type": "Literal",
"value": false
},
"else_ifs": [
{
"cond": {
"end": 314,
"raw": "false",
"start": 309,
"type": "Literal",
"type": "Literal",
"value": false
},
"end": 322,
"start": 301,
"then_val": {
"body": [
{
"end": 320,
"expression": {
"end": 320,
"raw": "4",
"start": 319,
"type": "Literal",
"type": "Literal",
"value": 4
},
"start": 319,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 321,
"start": 315
},
"type": "ElseIf"
}
],
"end": 335,
"final_else": {
"body": [
{
"end": 333,
"expression": {
"end": 333,
"raw": "5",
"start": 332,
"type": "Literal",
"type": "Literal",
"value": 5
},
"start": 332,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 334,
"start": 332
},
"start": 284,
"then_val": {
"body": [
{
"end": 298,
"expression": {
"end": 298,
"raw": "3",
"start": 297,
"type": "Literal",
"type": "Literal",
"value": 3
},
"start": 297,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 299,
"start": 297
},
"type": "IfExpression",
"type": "IfExpression"
},
"start": 280,
"type": "VariableDeclarator"
}
],
"end": 335,
"kind": "const",
"start": 280,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 395,
"expression": {
"arguments": [
{
"end": 349,
"name": "c",
"start": 348,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 352,
"raw": "5",
"start": 351,
"type": "Literal",
"type": "Literal",
"value": 5
},
{
"end": 359,
"raw": "0.001",
"start": 354,
"type": "Literal",
"type": "Literal",
"value": 0.001
},
{
"end": 394,
"raw": "\"the 'else' branch gets returned\"",
"start": 361,
"type": "Literal",
"type": "Literal",
"value": "the 'else' branch gets returned"
}
],
"callee": {
"end": 347,
"name": "assertEqual",
"start": 336,
"type": "Identifier"
},
"end": 395,
"optional": false,
"start": 336,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 336,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 396,
"nonCodeMeta": {
"nonCodeNodes": {
"1": [
{
"end": 161,
"start": 159,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"3": [
{
"end": 280,
"start": 278,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": [
{
"end": 45,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "This tests evaluating if-else expressions.",
"style": "line"
}
},
{
"end": 48,
"start": 45,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"start": 0
}
}

View File

@ -1,6 +1,7 @@
// This tests evaluating if-else expressions.
let a = if true {
a = if true {
3
} else if true {
4
@ -9,7 +10,7 @@ let a = if true {
}
assertEqual(a, 3, 0.001, "the 'if' branch gets returned")
let b = if false {
b = if false {
3
} else if true {
4
@ -18,7 +19,7 @@ let b = if false {
}
assertEqual(b, 4, 0.001, "the 'else if' branch gets returned")
let c = if false {
c = if false {
3
} else if false {
4

View File

@ -0,0 +1,79 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing if_else.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"a": {
"type": "UserVal",
"type": "UserVal",
"value": 3,
"__meta": [
{
"sourceRange": [
64,
65
]
}
]
},
"b": {
"type": "UserVal",
"type": "UserVal",
"value": 4,
"__meta": [
{
"sourceRange": [
199,
200
]
}
]
},
"c": {
"type": "UserVal",
"type": "UserVal",
"value": 5,
"__meta": [
{
"sourceRange": [
332,
333
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -0,0 +1,885 @@
---
source: kcl/src/simulation_tests.rs
description: Result of tokenizing if_else.kcl
snapshot_kind: text
---
{
"Ok": [
{
"type": "lineComment",
"start": 0,
"end": 45,
"value": "// This tests evaluating if-else expressions."
},
{
"type": "whitespace",
"start": 45,
"end": 48,
"value": "\n\n\n"
},
{
"type": "word",
"start": 48,
"end": 49,
"value": "a"
},
{
"type": "whitespace",
"start": 49,
"end": 50,
"value": " "
},
{
"type": "operator",
"start": 50,
"end": 51,
"value": "="
},
{
"type": "whitespace",
"start": 51,
"end": 52,
"value": " "
},
{
"type": "keyword",
"start": 52,
"end": 54,
"value": "if"
},
{
"type": "whitespace",
"start": 54,
"end": 55,
"value": " "
},
{
"type": "keyword",
"start": 55,
"end": 59,
"value": "true"
},
{
"type": "whitespace",
"start": 59,
"end": 60,
"value": " "
},
{
"type": "brace",
"start": 60,
"end": 61,
"value": "{"
},
{
"type": "whitespace",
"start": 61,
"end": 64,
"value": "\n "
},
{
"type": "number",
"start": 64,
"end": 65,
"value": "3"
},
{
"type": "whitespace",
"start": 65,
"end": 66,
"value": "\n"
},
{
"type": "brace",
"start": 66,
"end": 67,
"value": "}"
},
{
"type": "whitespace",
"start": 67,
"end": 68,
"value": " "
},
{
"type": "keyword",
"start": 68,
"end": 72,
"value": "else"
},
{
"type": "whitespace",
"start": 72,
"end": 73,
"value": " "
},
{
"type": "keyword",
"start": 73,
"end": 75,
"value": "if"
},
{
"type": "whitespace",
"start": 75,
"end": 76,
"value": " "
},
{
"type": "keyword",
"start": 76,
"end": 80,
"value": "true"
},
{
"type": "whitespace",
"start": 80,
"end": 81,
"value": " "
},
{
"type": "brace",
"start": 81,
"end": 82,
"value": "{"
},
{
"type": "whitespace",
"start": 82,
"end": 85,
"value": "\n "
},
{
"type": "number",
"start": 85,
"end": 86,
"value": "4"
},
{
"type": "whitespace",
"start": 86,
"end": 87,
"value": "\n"
},
{
"type": "brace",
"start": 87,
"end": 88,
"value": "}"
},
{
"type": "whitespace",
"start": 88,
"end": 89,
"value": " "
},
{
"type": "keyword",
"start": 89,
"end": 93,
"value": "else"
},
{
"type": "whitespace",
"start": 93,
"end": 94,
"value": " "
},
{
"type": "brace",
"start": 94,
"end": 95,
"value": "{"
},
{
"type": "whitespace",
"start": 95,
"end": 98,
"value": "\n "
},
{
"type": "number",
"start": 98,
"end": 99,
"value": "5"
},
{
"type": "whitespace",
"start": 99,
"end": 100,
"value": "\n"
},
{
"type": "brace",
"start": 100,
"end": 101,
"value": "}"
},
{
"type": "whitespace",
"start": 101,
"end": 102,
"value": "\n"
},
{
"type": "word",
"start": 102,
"end": 113,
"value": "assertEqual"
},
{
"type": "brace",
"start": 113,
"end": 114,
"value": "("
},
{
"type": "word",
"start": 114,
"end": 115,
"value": "a"
},
{
"type": "comma",
"start": 115,
"end": 116,
"value": ","
},
{
"type": "whitespace",
"start": 116,
"end": 117,
"value": " "
},
{
"type": "number",
"start": 117,
"end": 118,
"value": "3"
},
{
"type": "comma",
"start": 118,
"end": 119,
"value": ","
},
{
"type": "whitespace",
"start": 119,
"end": 120,
"value": " "
},
{
"type": "number",
"start": 120,
"end": 125,
"value": "0.001"
},
{
"type": "comma",
"start": 125,
"end": 126,
"value": ","
},
{
"type": "whitespace",
"start": 126,
"end": 127,
"value": " "
},
{
"type": "string",
"start": 127,
"end": 158,
"value": "\"the 'if' branch gets returned\""
},
{
"type": "brace",
"start": 158,
"end": 159,
"value": ")"
},
{
"type": "whitespace",
"start": 159,
"end": 161,
"value": "\n\n"
},
{
"type": "word",
"start": 161,
"end": 162,
"value": "b"
},
{
"type": "whitespace",
"start": 162,
"end": 163,
"value": " "
},
{
"type": "operator",
"start": 163,
"end": 164,
"value": "="
},
{
"type": "whitespace",
"start": 164,
"end": 165,
"value": " "
},
{
"type": "keyword",
"start": 165,
"end": 167,
"value": "if"
},
{
"type": "whitespace",
"start": 167,
"end": 168,
"value": " "
},
{
"type": "keyword",
"start": 168,
"end": 173,
"value": "false"
},
{
"type": "whitespace",
"start": 173,
"end": 174,
"value": " "
},
{
"type": "brace",
"start": 174,
"end": 175,
"value": "{"
},
{
"type": "whitespace",
"start": 175,
"end": 178,
"value": "\n "
},
{
"type": "number",
"start": 178,
"end": 179,
"value": "3"
},
{
"type": "whitespace",
"start": 179,
"end": 180,
"value": "\n"
},
{
"type": "brace",
"start": 180,
"end": 181,
"value": "}"
},
{
"type": "whitespace",
"start": 181,
"end": 182,
"value": " "
},
{
"type": "keyword",
"start": 182,
"end": 186,
"value": "else"
},
{
"type": "whitespace",
"start": 186,
"end": 187,
"value": " "
},
{
"type": "keyword",
"start": 187,
"end": 189,
"value": "if"
},
{
"type": "whitespace",
"start": 189,
"end": 190,
"value": " "
},
{
"type": "keyword",
"start": 190,
"end": 194,
"value": "true"
},
{
"type": "whitespace",
"start": 194,
"end": 195,
"value": " "
},
{
"type": "brace",
"start": 195,
"end": 196,
"value": "{"
},
{
"type": "whitespace",
"start": 196,
"end": 199,
"value": "\n "
},
{
"type": "number",
"start": 199,
"end": 200,
"value": "4"
},
{
"type": "whitespace",
"start": 200,
"end": 201,
"value": "\n"
},
{
"type": "brace",
"start": 201,
"end": 202,
"value": "}"
},
{
"type": "whitespace",
"start": 202,
"end": 203,
"value": " "
},
{
"type": "keyword",
"start": 203,
"end": 207,
"value": "else"
},
{
"type": "whitespace",
"start": 207,
"end": 208,
"value": " "
},
{
"type": "brace",
"start": 208,
"end": 209,
"value": "{"
},
{
"type": "whitespace",
"start": 209,
"end": 212,
"value": "\n "
},
{
"type": "number",
"start": 212,
"end": 213,
"value": "5"
},
{
"type": "whitespace",
"start": 213,
"end": 214,
"value": "\n"
},
{
"type": "brace",
"start": 214,
"end": 215,
"value": "}"
},
{
"type": "whitespace",
"start": 215,
"end": 216,
"value": "\n"
},
{
"type": "word",
"start": 216,
"end": 227,
"value": "assertEqual"
},
{
"type": "brace",
"start": 227,
"end": 228,
"value": "("
},
{
"type": "word",
"start": 228,
"end": 229,
"value": "b"
},
{
"type": "comma",
"start": 229,
"end": 230,
"value": ","
},
{
"type": "whitespace",
"start": 230,
"end": 231,
"value": " "
},
{
"type": "number",
"start": 231,
"end": 232,
"value": "4"
},
{
"type": "comma",
"start": 232,
"end": 233,
"value": ","
},
{
"type": "whitespace",
"start": 233,
"end": 234,
"value": " "
},
{
"type": "number",
"start": 234,
"end": 239,
"value": "0.001"
},
{
"type": "comma",
"start": 239,
"end": 240,
"value": ","
},
{
"type": "whitespace",
"start": 240,
"end": 241,
"value": " "
},
{
"type": "string",
"start": 241,
"end": 277,
"value": "\"the 'else if' branch gets returned\""
},
{
"type": "brace",
"start": 277,
"end": 278,
"value": ")"
},
{
"type": "whitespace",
"start": 278,
"end": 280,
"value": "\n\n"
},
{
"type": "word",
"start": 280,
"end": 281,
"value": "c"
},
{
"type": "whitespace",
"start": 281,
"end": 282,
"value": " "
},
{
"type": "operator",
"start": 282,
"end": 283,
"value": "="
},
{
"type": "whitespace",
"start": 283,
"end": 284,
"value": " "
},
{
"type": "keyword",
"start": 284,
"end": 286,
"value": "if"
},
{
"type": "whitespace",
"start": 286,
"end": 287,
"value": " "
},
{
"type": "keyword",
"start": 287,
"end": 292,
"value": "false"
},
{
"type": "whitespace",
"start": 292,
"end": 293,
"value": " "
},
{
"type": "brace",
"start": 293,
"end": 294,
"value": "{"
},
{
"type": "whitespace",
"start": 294,
"end": 297,
"value": "\n "
},
{
"type": "number",
"start": 297,
"end": 298,
"value": "3"
},
{
"type": "whitespace",
"start": 298,
"end": 299,
"value": "\n"
},
{
"type": "brace",
"start": 299,
"end": 300,
"value": "}"
},
{
"type": "whitespace",
"start": 300,
"end": 301,
"value": " "
},
{
"type": "keyword",
"start": 301,
"end": 305,
"value": "else"
},
{
"type": "whitespace",
"start": 305,
"end": 306,
"value": " "
},
{
"type": "keyword",
"start": 306,
"end": 308,
"value": "if"
},
{
"type": "whitespace",
"start": 308,
"end": 309,
"value": " "
},
{
"type": "keyword",
"start": 309,
"end": 314,
"value": "false"
},
{
"type": "whitespace",
"start": 314,
"end": 315,
"value": " "
},
{
"type": "brace",
"start": 315,
"end": 316,
"value": "{"
},
{
"type": "whitespace",
"start": 316,
"end": 319,
"value": "\n "
},
{
"type": "number",
"start": 319,
"end": 320,
"value": "4"
},
{
"type": "whitespace",
"start": 320,
"end": 321,
"value": "\n"
},
{
"type": "brace",
"start": 321,
"end": 322,
"value": "}"
},
{
"type": "whitespace",
"start": 322,
"end": 323,
"value": " "
},
{
"type": "keyword",
"start": 323,
"end": 327,
"value": "else"
},
{
"type": "whitespace",
"start": 327,
"end": 328,
"value": " "
},
{
"type": "brace",
"start": 328,
"end": 329,
"value": "{"
},
{
"type": "whitespace",
"start": 329,
"end": 332,
"value": "\n "
},
{
"type": "number",
"start": 332,
"end": 333,
"value": "5"
},
{
"type": "whitespace",
"start": 333,
"end": 334,
"value": "\n"
},
{
"type": "brace",
"start": 334,
"end": 335,
"value": "}"
},
{
"type": "whitespace",
"start": 335,
"end": 336,
"value": "\n"
},
{
"type": "word",
"start": 336,
"end": 347,
"value": "assertEqual"
},
{
"type": "brace",
"start": 347,
"end": 348,
"value": "("
},
{
"type": "word",
"start": 348,
"end": 349,
"value": "c"
},
{
"type": "comma",
"start": 349,
"end": 350,
"value": ","
},
{
"type": "whitespace",
"start": 350,
"end": 351,
"value": " "
},
{
"type": "number",
"start": 351,
"end": 352,
"value": "5"
},
{
"type": "comma",
"start": 352,
"end": 353,
"value": ","
},
{
"type": "whitespace",
"start": 353,
"end": 354,
"value": " "
},
{
"type": "number",
"start": 354,
"end": 359,
"value": "0.001"
},
{
"type": "comma",
"start": 359,
"end": 360,
"value": ","
},
{
"type": "whitespace",
"start": 360,
"end": 361,
"value": " "
},
{
"type": "string",
"start": 361,
"end": 394,
"value": "\"the 'else' branch gets returned\""
},
{
"type": "brace",
"start": 394,
"end": 395,
"value": ")"
},
{
"type": "whitespace",
"start": 395,
"end": 396,
"value": "\n"
}
]
}

View File

@ -0,0 +1,466 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing index_of_array.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 55,
"id": {
"end": 40,
"name": "array",
"start": 35,
"type": "Identifier"
},
"init": {
"elements": [
{
"end": 46,
"raw": "90",
"start": 44,
"type": "Literal",
"type": "Literal",
"value": 90
},
{
"end": 50,
"raw": "91",
"start": 48,
"type": "Literal",
"type": "Literal",
"value": 91
},
{
"end": 54,
"raw": "92",
"start": 52,
"type": "Literal",
"type": "Literal",
"value": 92
}
],
"end": 55,
"start": 43,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 35,
"type": "VariableDeclarator"
}
],
"end": 55,
"kind": "const",
"start": 35,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 101,
"id": {
"end": 90,
"name": "result0",
"start": 83,
"type": "Identifier"
},
"init": {
"computed": false,
"end": 101,
"object": {
"end": 98,
"name": "array",
"start": 93,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 100,
"raw": "1",
"start": 99,
"type": "Literal",
"type": "Literal",
"value": 1
},
"start": 93,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 83,
"type": "VariableDeclarator"
}
],
"end": 101,
"kind": "const",
"start": 83,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 161,
"expression": {
"arguments": [
{
"end": 129,
"name": "result0",
"start": 122,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 133,
"raw": "91",
"start": 131,
"type": "Literal",
"type": "Literal",
"value": 91
},
{
"end": 160,
"raw": "\"Literal property lookup\"",
"start": 135,
"type": "Literal",
"type": "Literal",
"value": "Literal property lookup"
}
],
"callee": {
"end": 121,
"name": "assertLessThanOrEq",
"start": 103,
"type": "Identifier"
},
"end": 161,
"optional": false,
"start": 103,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 103,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 223,
"expression": {
"arguments": [
{
"end": 191,
"name": "result0",
"start": 184,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 195,
"raw": "91",
"start": 193,
"type": "Literal",
"type": "Literal",
"value": 91
},
{
"end": 222,
"raw": "\"Literal property lookup\"",
"start": 197,
"type": "Literal",
"type": "Literal",
"value": "Literal property lookup"
}
],
"callee": {
"end": 183,
"name": "assertGreaterThanOrEq",
"start": 162,
"type": "Identifier"
},
"end": 223,
"optional": false,
"start": 162,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 162,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 266,
"id": {
"end": 253,
"name": "i",
"start": 252,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 265,
"left": {
"end": 261,
"raw": "1",
"start": 260,
"type": "Literal",
"type": "Literal",
"value": 1
},
"operator": "+",
"right": {
"end": 265,
"raw": "0",
"start": 264,
"type": "Literal",
"type": "Literal",
"value": 0
},
"start": 260,
"type": "BinaryExpression",
"type": "BinaryExpression"
}
],
"callee": {
"end": 259,
"name": "int",
"start": 256,
"type": "Identifier"
},
"end": 266,
"optional": false,
"start": 256,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 252,
"type": "VariableDeclarator"
}
],
"end": 266,
"kind": "const",
"start": 252,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 285,
"id": {
"end": 274,
"name": "result1",
"start": 267,
"type": "Identifier"
},
"init": {
"computed": true,
"end": 285,
"object": {
"end": 282,
"name": "array",
"start": 277,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 284,
"name": "i",
"start": 283,
"type": "Identifier",
"type": "Identifier"
},
"start": 277,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 267,
"type": "VariableDeclarator"
}
],
"end": 285,
"kind": "const",
"start": 267,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 346,
"expression": {
"arguments": [
{
"end": 313,
"name": "result1",
"start": 306,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 317,
"raw": "91",
"start": 315,
"type": "Literal",
"type": "Literal",
"value": 91
},
{
"end": 345,
"raw": "\"Computed property lookup\"",
"start": 319,
"type": "Literal",
"type": "Literal",
"value": "Computed property lookup"
}
],
"callee": {
"end": 305,
"name": "assertLessThanOrEq",
"start": 287,
"type": "Identifier"
},
"end": 346,
"optional": false,
"start": 287,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 287,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 409,
"expression": {
"arguments": [
{
"end": 376,
"name": "result1",
"start": 369,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 380,
"raw": "91",
"start": 378,
"type": "Literal",
"type": "Literal",
"value": 91
},
{
"end": 408,
"raw": "\"Computed property lookup\"",
"start": 382,
"type": "Literal",
"type": "Literal",
"value": "Computed property lookup"
}
],
"callee": {
"end": 368,
"name": "assertGreaterThanOrEq",
"start": 347,
"type": "Identifier"
},
"end": 409,
"optional": false,
"start": 347,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 347,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 410,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [
{
"end": 80,
"start": 55,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Test: literal index.",
"style": "line"
}
},
{
"end": 83,
"start": 80,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"1": [
{
"end": 103,
"start": 101,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"3": [
{
"end": 249,
"start": 223,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Test: computed index.",
"style": "line"
}
},
{
"end": 252,
"start": 249,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"5": [
{
"end": 287,
"start": 285,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": [
{
"end": 32,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "This tests indexing an array.",
"style": "line"
}
},
{
"end": 35,
"start": 32,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"start": 0
}
}

View File

@ -1,18 +1,21 @@
// This tests indexing an array.
const array = [90, 91, 92]
array = [90, 91, 92]
// Test: literal index.
const result0 = array[1]
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]
i = int(1 + 0)
result1 = array[i]
assertLessThanOrEq(result1, 91, "Computed property lookup")
assertGreaterThanOrEq(result1, 91, "Computed property lookup")

View File

@ -0,0 +1,96 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing index_of_array.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"array": {
"type": "UserVal",
"type": "UserVal",
"value": [
90,
91,
92
],
"__meta": [
{
"sourceRange": [
43,
55
]
}
]
},
"i": {
"type": "UserVal",
"type": "UserVal",
"value": 1,
"__meta": [
{
"sourceRange": [
256,
266
]
}
]
},
"result0": {
"type": "UserVal",
"type": "UserVal",
"value": 91,
"__meta": [
{
"sourceRange": [
93,
101
]
}
]
},
"result1": {
"type": "UserVal",
"type": "UserVal",
"value": 91,
"__meta": [
{
"sourceRange": [
277,
285
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -0,0 +1,579 @@
---
source: kcl/src/simulation_tests.rs
description: Result of tokenizing index_of_array.kcl
snapshot_kind: text
---
{
"Ok": [
{
"type": "lineComment",
"start": 0,
"end": 32,
"value": "// This tests indexing an array."
},
{
"type": "whitespace",
"start": 32,
"end": 35,
"value": "\n\n\n"
},
{
"type": "word",
"start": 35,
"end": 40,
"value": "array"
},
{
"type": "whitespace",
"start": 40,
"end": 41,
"value": " "
},
{
"type": "operator",
"start": 41,
"end": 42,
"value": "="
},
{
"type": "whitespace",
"start": 42,
"end": 43,
"value": " "
},
{
"type": "brace",
"start": 43,
"end": 44,
"value": "["
},
{
"type": "number",
"start": 44,
"end": 46,
"value": "90"
},
{
"type": "comma",
"start": 46,
"end": 47,
"value": ","
},
{
"type": "whitespace",
"start": 47,
"end": 48,
"value": " "
},
{
"type": "number",
"start": 48,
"end": 50,
"value": "91"
},
{
"type": "comma",
"start": 50,
"end": 51,
"value": ","
},
{
"type": "whitespace",
"start": 51,
"end": 52,
"value": " "
},
{
"type": "number",
"start": 52,
"end": 54,
"value": "92"
},
{
"type": "brace",
"start": 54,
"end": 55,
"value": "]"
},
{
"type": "whitespace",
"start": 55,
"end": 57,
"value": "\n\n"
},
{
"type": "lineComment",
"start": 57,
"end": 80,
"value": "// Test: literal index."
},
{
"type": "whitespace",
"start": 80,
"end": 83,
"value": "\n\n\n"
},
{
"type": "word",
"start": 83,
"end": 90,
"value": "result0"
},
{
"type": "whitespace",
"start": 90,
"end": 91,
"value": " "
},
{
"type": "operator",
"start": 91,
"end": 92,
"value": "="
},
{
"type": "whitespace",
"start": 92,
"end": 93,
"value": " "
},
{
"type": "word",
"start": 93,
"end": 98,
"value": "array"
},
{
"type": "brace",
"start": 98,
"end": 99,
"value": "["
},
{
"type": "number",
"start": 99,
"end": 100,
"value": "1"
},
{
"type": "brace",
"start": 100,
"end": 101,
"value": "]"
},
{
"type": "whitespace",
"start": 101,
"end": 103,
"value": "\n\n"
},
{
"type": "word",
"start": 103,
"end": 121,
"value": "assertLessThanOrEq"
},
{
"type": "brace",
"start": 121,
"end": 122,
"value": "("
},
{
"type": "word",
"start": 122,
"end": 129,
"value": "result0"
},
{
"type": "comma",
"start": 129,
"end": 130,
"value": ","
},
{
"type": "whitespace",
"start": 130,
"end": 131,
"value": " "
},
{
"type": "number",
"start": 131,
"end": 133,
"value": "91"
},
{
"type": "comma",
"start": 133,
"end": 134,
"value": ","
},
{
"type": "whitespace",
"start": 134,
"end": 135,
"value": " "
},
{
"type": "string",
"start": 135,
"end": 160,
"value": "\"Literal property lookup\""
},
{
"type": "brace",
"start": 160,
"end": 161,
"value": ")"
},
{
"type": "whitespace",
"start": 161,
"end": 162,
"value": "\n"
},
{
"type": "word",
"start": 162,
"end": 183,
"value": "assertGreaterThanOrEq"
},
{
"type": "brace",
"start": 183,
"end": 184,
"value": "("
},
{
"type": "word",
"start": 184,
"end": 191,
"value": "result0"
},
{
"type": "comma",
"start": 191,
"end": 192,
"value": ","
},
{
"type": "whitespace",
"start": 192,
"end": 193,
"value": " "
},
{
"type": "number",
"start": 193,
"end": 195,
"value": "91"
},
{
"type": "comma",
"start": 195,
"end": 196,
"value": ","
},
{
"type": "whitespace",
"start": 196,
"end": 197,
"value": " "
},
{
"type": "string",
"start": 197,
"end": 222,
"value": "\"Literal property lookup\""
},
{
"type": "brace",
"start": 222,
"end": 223,
"value": ")"
},
{
"type": "whitespace",
"start": 223,
"end": 225,
"value": "\n\n"
},
{
"type": "lineComment",
"start": 225,
"end": 249,
"value": "// Test: computed index."
},
{
"type": "whitespace",
"start": 249,
"end": 252,
"value": "\n\n\n"
},
{
"type": "word",
"start": 252,
"end": 253,
"value": "i"
},
{
"type": "whitespace",
"start": 253,
"end": 254,
"value": " "
},
{
"type": "operator",
"start": 254,
"end": 255,
"value": "="
},
{
"type": "whitespace",
"start": 255,
"end": 256,
"value": " "
},
{
"type": "word",
"start": 256,
"end": 259,
"value": "int"
},
{
"type": "brace",
"start": 259,
"end": 260,
"value": "("
},
{
"type": "number",
"start": 260,
"end": 261,
"value": "1"
},
{
"type": "whitespace",
"start": 261,
"end": 262,
"value": " "
},
{
"type": "operator",
"start": 262,
"end": 263,
"value": "+"
},
{
"type": "whitespace",
"start": 263,
"end": 264,
"value": " "
},
{
"type": "number",
"start": 264,
"end": 265,
"value": "0"
},
{
"type": "brace",
"start": 265,
"end": 266,
"value": ")"
},
{
"type": "whitespace",
"start": 266,
"end": 267,
"value": "\n"
},
{
"type": "word",
"start": 267,
"end": 274,
"value": "result1"
},
{
"type": "whitespace",
"start": 274,
"end": 275,
"value": " "
},
{
"type": "operator",
"start": 275,
"end": 276,
"value": "="
},
{
"type": "whitespace",
"start": 276,
"end": 277,
"value": " "
},
{
"type": "word",
"start": 277,
"end": 282,
"value": "array"
},
{
"type": "brace",
"start": 282,
"end": 283,
"value": "["
},
{
"type": "word",
"start": 283,
"end": 284,
"value": "i"
},
{
"type": "brace",
"start": 284,
"end": 285,
"value": "]"
},
{
"type": "whitespace",
"start": 285,
"end": 287,
"value": "\n\n"
},
{
"type": "word",
"start": 287,
"end": 305,
"value": "assertLessThanOrEq"
},
{
"type": "brace",
"start": 305,
"end": 306,
"value": "("
},
{
"type": "word",
"start": 306,
"end": 313,
"value": "result1"
},
{
"type": "comma",
"start": 313,
"end": 314,
"value": ","
},
{
"type": "whitespace",
"start": 314,
"end": 315,
"value": " "
},
{
"type": "number",
"start": 315,
"end": 317,
"value": "91"
},
{
"type": "comma",
"start": 317,
"end": 318,
"value": ","
},
{
"type": "whitespace",
"start": 318,
"end": 319,
"value": " "
},
{
"type": "string",
"start": 319,
"end": 345,
"value": "\"Computed property lookup\""
},
{
"type": "brace",
"start": 345,
"end": 346,
"value": ")"
},
{
"type": "whitespace",
"start": 346,
"end": 347,
"value": "\n"
},
{
"type": "word",
"start": 347,
"end": 368,
"value": "assertGreaterThanOrEq"
},
{
"type": "brace",
"start": 368,
"end": 369,
"value": "("
},
{
"type": "word",
"start": 369,
"end": 376,
"value": "result1"
},
{
"type": "comma",
"start": 376,
"end": 377,
"value": ","
},
{
"type": "whitespace",
"start": 377,
"end": 378,
"value": " "
},
{
"type": "number",
"start": 378,
"end": 380,
"value": "91"
},
{
"type": "comma",
"start": 380,
"end": 381,
"value": ","
},
{
"type": "whitespace",
"start": 381,
"end": 382,
"value": " "
},
{
"type": "string",
"start": 382,
"end": 408,
"value": "\"Computed property lookup\""
},
{
"type": "brace",
"start": 408,
"end": 409,
"value": ")"
},
{
"type": "whitespace",
"start": 409,
"end": 410,
"value": "\n"
}
]
}

View File

@ -0,0 +1,863 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing property_of_object.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 74,
"id": {
"end": 53,
"name": "obj",
"start": 50,
"type": "Identifier"
},
"init": {
"end": 74,
"properties": [
{
"end": 64,
"key": {
"end": 61,
"name": "foo",
"start": 58,
"type": "Identifier"
},
"start": 58,
"type": "ObjectProperty",
"value": {
"end": 64,
"raw": "1",
"start": 63,
"type": "Literal",
"type": "Literal",
"value": 1
}
},
{
"end": 72,
"key": {
"end": 69,
"name": "bar",
"start": 66,
"type": "Identifier"
},
"start": 66,
"type": "ObjectProperty",
"value": {
"end": 72,
"raw": "0",
"start": 71,
"type": "Literal",
"type": "Literal",
"value": 0
}
}
],
"start": 56,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
"start": 50,
"type": "VariableDeclarator"
}
],
"end": 74,
"kind": "const",
"start": 50,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 132,
"id": {
"end": 119,
"name": "one_a",
"start": 114,
"type": "Identifier"
},
"init": {
"computed": false,
"end": 132,
"object": {
"end": 125,
"name": "obj",
"start": 122,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 131,
"raw": "\"foo\"",
"start": 126,
"type": "Literal",
"type": "Literal",
"value": "foo"
},
"start": 122,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 114,
"type": "VariableDeclarator"
}
],
"end": 132,
"kind": "const",
"start": 114,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 189,
"expression": {
"arguments": [
{
"end": 158,
"name": "one_a",
"start": 153,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 161,
"raw": "1",
"start": 160,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 188,
"raw": "\"Literal property lookup\"",
"start": 163,
"type": "Literal",
"type": "Literal",
"value": "Literal property lookup"
}
],
"callee": {
"end": 152,
"name": "assertLessThanOrEq",
"start": 134,
"type": "Identifier"
},
"end": 189,
"optional": false,
"start": 134,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 134,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 248,
"expression": {
"arguments": [
{
"end": 217,
"name": "one_a",
"start": 212,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 220,
"raw": "1",
"start": 219,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 247,
"raw": "\"Literal property lookup\"",
"start": 222,
"type": "Literal",
"type": "Literal",
"value": "Literal property lookup"
}
],
"callee": {
"end": 211,
"name": "assertGreaterThanOrEq",
"start": 190,
"type": "Identifier"
},
"end": 248,
"optional": false,
"start": 190,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 190,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 347,
"id": {
"end": 339,
"name": "p",
"start": 338,
"type": "Identifier"
},
"init": {
"end": 347,
"raw": "\"foo\"",
"start": 342,
"type": "Literal",
"type": "Literal",
"value": "foo"
},
"start": 338,
"type": "VariableDeclarator"
}
],
"end": 347,
"kind": "const",
"start": 338,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 362,
"id": {
"end": 353,
"name": "one_b",
"start": 348,
"type": "Identifier"
},
"init": {
"computed": true,
"end": 362,
"object": {
"end": 359,
"name": "obj",
"start": 356,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 361,
"name": "p",
"start": 360,
"type": "Identifier",
"type": "Identifier"
},
"start": 356,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 348,
"type": "VariableDeclarator"
}
],
"end": 362,
"kind": "const",
"start": 348,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 420,
"expression": {
"arguments": [
{
"end": 388,
"name": "one_b",
"start": 383,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 391,
"raw": "1",
"start": 390,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 419,
"raw": "\"Computed property lookup\"",
"start": 393,
"type": "Literal",
"type": "Literal",
"value": "Computed property lookup"
}
],
"callee": {
"end": 382,
"name": "assertLessThanOrEq",
"start": 364,
"type": "Identifier"
},
"end": 420,
"optional": false,
"start": 364,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 364,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 480,
"expression": {
"arguments": [
{
"end": 448,
"name": "one_b",
"start": 443,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 451,
"raw": "1",
"start": 450,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 479,
"raw": "\"Computed property lookup\"",
"start": 453,
"type": "Literal",
"type": "Literal",
"value": "Computed property lookup"
}
],
"callee": {
"end": 442,
"name": "assertGreaterThanOrEq",
"start": 421,
"type": "Identifier"
},
"end": 480,
"optional": false,
"start": 421,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 421,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 543,
"id": {
"end": 526,
"name": "obj2",
"start": 522,
"type": "Identifier"
},
"init": {
"end": 543,
"properties": [
{
"end": 541,
"key": {
"end": 536,
"name": "inner",
"start": 531,
"type": "Identifier"
},
"start": 531,
"type": "ObjectProperty",
"value": {
"end": 541,
"name": "obj",
"start": 538,
"type": "Identifier",
"type": "Identifier"
}
}
],
"start": 529,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
"start": 522,
"type": "VariableDeclarator"
}
],
"end": 543,
"kind": "const",
"start": 522,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 570,
"id": {
"end": 550,
"name": "one_c",
"start": 545,
"type": "Identifier"
},
"init": {
"computed": false,
"end": 570,
"object": {
"computed": false,
"end": 563,
"object": {
"end": 557,
"name": "obj2",
"start": 553,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 563,
"name": "inner",
"start": 558,
"type": "Identifier",
"type": "Identifier"
},
"start": 553,
"type": "MemberExpression",
"type": "MemberExpression"
},
"property": {
"end": 569,
"raw": "\"foo\"",
"start": 564,
"type": "Literal",
"type": "Literal",
"value": "foo"
},
"start": 553,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 545,
"type": "VariableDeclarator"
}
],
"end": 570,
"kind": "const",
"start": 545,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 627,
"expression": {
"arguments": [
{
"end": 596,
"name": "one_c",
"start": 591,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 599,
"raw": "1",
"start": 598,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 626,
"raw": "\"Literal property lookup\"",
"start": 601,
"type": "Literal",
"type": "Literal",
"value": "Literal property lookup"
}
],
"callee": {
"end": 590,
"name": "assertLessThanOrEq",
"start": 572,
"type": "Identifier"
},
"end": 627,
"optional": false,
"start": 572,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 572,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 686,
"expression": {
"arguments": [
{
"end": 655,
"name": "one_c",
"start": 650,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 658,
"raw": "1",
"start": 657,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 685,
"raw": "\"Literal property lookup\"",
"start": 660,
"type": "Literal",
"type": "Literal",
"value": "Literal property lookup"
}
],
"callee": {
"end": 649,
"name": "assertGreaterThanOrEq",
"start": 628,
"type": "Identifier"
},
"end": 686,
"optional": false,
"start": 628,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 628,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 770,
"id": {
"end": 754,
"name": "one_d",
"start": 749,
"type": "Identifier"
},
"init": {
"computed": true,
"end": 770,
"object": {
"computed": false,
"end": 767,
"object": {
"end": 761,
"name": "obj2",
"start": 757,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 767,
"name": "inner",
"start": 762,
"type": "Identifier",
"type": "Identifier"
},
"start": 757,
"type": "MemberExpression",
"type": "MemberExpression"
},
"property": {
"end": 769,
"name": "p",
"start": 768,
"type": "Identifier",
"type": "Identifier"
},
"start": 757,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 749,
"type": "VariableDeclarator"
}
],
"end": 770,
"kind": "const",
"start": 749,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 828,
"expression": {
"arguments": [
{
"end": 796,
"name": "one_d",
"start": 791,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 799,
"raw": "1",
"start": 798,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 827,
"raw": "\"Computed property lookup\"",
"start": 801,
"type": "Literal",
"type": "Literal",
"value": "Computed property lookup"
}
],
"callee": {
"end": 790,
"name": "assertLessThanOrEq",
"start": 772,
"type": "Identifier"
},
"end": 828,
"optional": false,
"start": 772,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 772,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"end": 888,
"expression": {
"arguments": [
{
"end": 856,
"name": "one_d",
"start": 851,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 859,
"raw": "1",
"start": 858,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 887,
"raw": "\"Computed property lookup\"",
"start": 861,
"type": "Literal",
"type": "Literal",
"value": "Computed property lookup"
}
],
"callee": {
"end": 850,
"name": "assertGreaterThanOrEq",
"start": 829,
"type": "Identifier"
},
"end": 888,
"optional": false,
"start": 829,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 829,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 889,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [
{
"end": 111,
"start": 74,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Test: the property is a literal.",
"style": "line"
}
},
{
"end": 114,
"start": 111,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"1": [
{
"end": 134,
"start": 132,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"3": [
{
"end": 286,
"start": 248,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Test: the property is a variable,",
"style": "line"
}
},
{
"end": 335,
"start": 287,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "which must be evaluated before looking it up.",
"style": "line"
}
},
{
"end": 338,
"start": 335,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"5": [
{
"end": 364,
"start": 362,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"7": [
{
"end": 519,
"start": 480,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Test: multiple literal properties.",
"style": "line"
}
},
{
"end": 522,
"start": 519,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"8": [
{
"end": 545,
"start": 543,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"9": [
{
"end": 572,
"start": 570,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"11": [
{
"end": 746,
"start": 686,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Test: multiple properties, mix of literal and computed.",
"style": "line"
}
},
{
"end": 749,
"start": 746,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"12": [
{
"end": 772,
"start": 770,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": [
{
"end": 47,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "This tests evaluating properties of objects.",
"style": "line"
}
},
{
"end": 50,
"start": 47,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"start": 0
}
}

View File

@ -1,40 +1,40 @@
// This tests evaluating properties of objects.
const obj = {
foo: 1,
bar: 0,
}
obj = { foo: 1, bar: 0 }
// Test: the property is a literal.
const one_a = obj["foo"]
assertLessThanOrEq(one_a, 1, "Literal property lookup")
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")
p = "foo"
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"]
obj2 = { inner: obj }
assertLessThanOrEq(one_c, 1, "Literal property lookup")
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")
one_d = obj2.inner[p]
assertLessThanOrEq(one_d, 1, "Computed property lookup")
assertGreaterThanOrEq(one_d, 1, "Computed property lookup")

View File

@ -0,0 +1,139 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing property_of_object.kcl
snapshot_kind: text
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 180,
"__meta": []
},
"QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 90,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "UserVal",
"type": "UserVal",
"value": 270,
"__meta": []
},
"ZERO": {
"type": "UserVal",
"type": "UserVal",
"value": 0,
"__meta": []
},
"obj": {
"type": "UserVal",
"type": "UserVal",
"value": {
"bar": 0,
"foo": 1
},
"__meta": [
{
"sourceRange": [
56,
74
]
}
]
},
"obj2": {
"type": "UserVal",
"type": "UserVal",
"value": {
"inner": {
"bar": 0,
"foo": 1
}
},
"__meta": [
{
"sourceRange": [
529,
543
]
}
]
},
"one_a": {
"type": "UserVal",
"type": "UserVal",
"value": 1,
"__meta": [
{
"sourceRange": [
122,
132
]
}
]
},
"one_b": {
"type": "UserVal",
"type": "UserVal",
"value": 1,
"__meta": [
{
"sourceRange": [
356,
362
]
}
]
},
"one_c": {
"type": "UserVal",
"type": "UserVal",
"value": 1,
"__meta": [
{
"sourceRange": [
553,
570
]
}
]
},
"one_d": {
"type": "UserVal",
"type": "UserVal",
"value": 1,
"__meta": [
{
"sourceRange": [
757,
770
]
}
]
},
"p": {
"type": "UserVal",
"type": "UserVal",
"value": "foo",
"__meta": [
{
"sourceRange": [
342,
347
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,6 @@ mod TEST_NAME_HERE {
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME).await
super::execute(TEST_NAME, RENDER_TO_PNG).await
}
}

View File

@ -0,0 +1,844 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing sketch_in_object.kcl
snapshot_kind: text
---
{
"Ok": {
"body": [
{
"declarations": [
{
"end": 157,
"id": {
"end": 7,
"name": "test",
"start": 3,
"type": "Identifier"
},
"init": {
"body": {
"body": [
{
"argument": {
"body": [
{
"arguments": [
{
"end": 45,
"raw": "'XY'",
"start": 41,
"type": "Literal",
"type": "Literal",
"value": "XY"
}
],
"callee": {
"end": 40,
"name": "startSketchOn",
"start": 27,
"type": "Identifier"
},
"end": 46,
"optional": false,
"start": 27,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 69,
"raw": "0",
"start": 68,
"type": "Literal",
"type": "Literal",
"value": 0
},
{
"end": 72,
"raw": "0",
"start": 71,
"type": "Literal",
"type": "Literal",
"value": 0
}
],
"end": 73,
"start": 67,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 76,
"start": 75,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 66,
"name": "startProfileAt",
"start": 52,
"type": "Identifier"
},
"end": 77,
"optional": false,
"start": 52,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 90,
"raw": "0",
"start": 89,
"type": "Literal",
"type": "Literal",
"value": 0
},
{
"end": 93,
"raw": "1",
"start": 92,
"type": "Literal",
"type": "Literal",
"value": 1
}
],
"end": 94,
"start": 88,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 97,
"start": 96,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 87,
"name": "line",
"start": 83,
"type": "Identifier"
},
"end": 98,
"optional": false,
"start": 83,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 111,
"raw": "1",
"start": 110,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 114,
"raw": "0",
"start": 113,
"type": "Literal",
"type": "Literal",
"value": 0
}
],
"end": 115,
"start": 109,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 118,
"start": 117,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 108,
"name": "line",
"start": 104,
"type": "Identifier"
},
"end": 119,
"optional": false,
"start": 104,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 132,
"raw": "0",
"start": 131,
"type": "Literal",
"type": "Literal",
"value": 0
},
{
"argument": {
"end": 136,
"raw": "1",
"start": 135,
"type": "Literal",
"type": "Literal",
"value": 1
},
"end": 136,
"operator": "-",
"start": 134,
"type": "UnaryExpression",
"type": "UnaryExpression"
}
],
"end": 137,
"start": 130,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 140,
"start": 139,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 129,
"name": "line",
"start": 125,
"type": "Identifier"
},
"end": 141,
"optional": false,
"start": 125,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 154,
"start": 153,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 152,
"name": "close",
"start": 147,
"type": "Identifier"
},
"end": 155,
"optional": false,
"start": 147,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 155,
"start": 27,
"type": "PipeExpression",
"type": "PipeExpression"
},
"end": 155,
"start": 20,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"end": 157,
"start": 16
},
"end": 157,
"params": [],
"start": 10,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 3,
"type": "VariableDeclarator"
}
],
"end": 157,
"kind": "fn",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 369,
"id": {
"end": 167,
"name": "test2",
"start": 162,
"type": "Identifier"
},
"init": {
"body": {
"body": [
{
"argument": {
"end": 367,
"properties": [
{
"end": 365,
"key": {
"end": 197,
"name": "thing1",
"start": 191,
"type": "Identifier"
},
"start": 191,
"type": "ObjectProperty",
"value": {
"end": 365,
"properties": [
{
"end": 361,
"key": {
"end": 211,
"name": "thing2",
"start": 205,
"type": "Identifier"
},
"start": 205,
"type": "ObjectProperty",
"value": {
"body": [
{
"arguments": [
{
"end": 231,
"raw": "'XY'",
"start": 227,
"type": "Literal",
"type": "Literal",
"value": "XY"
}
],
"callee": {
"end": 226,
"name": "startSketchOn",
"start": 213,
"type": "Identifier"
},
"end": 232,
"optional": false,
"start": 213,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 259,
"raw": "0",
"start": 258,
"type": "Literal",
"type": "Literal",
"value": 0
},
{
"end": 262,
"raw": "0",
"start": 261,
"type": "Literal",
"type": "Literal",
"value": 0
}
],
"end": 263,
"start": 257,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 266,
"start": 265,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 256,
"name": "startProfileAt",
"start": 242,
"type": "Identifier"
},
"end": 267,
"optional": false,
"start": 242,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 284,
"raw": "0",
"start": 283,
"type": "Literal",
"type": "Literal",
"value": 0
},
{
"end": 287,
"raw": "1",
"start": 286,
"type": "Literal",
"type": "Literal",
"value": 1
}
],
"end": 288,
"start": 282,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 291,
"start": 290,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 281,
"name": "line",
"start": 277,
"type": "Identifier"
},
"end": 292,
"optional": false,
"start": 277,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 309,
"raw": "1",
"start": 308,
"type": "Literal",
"type": "Literal",
"value": 1
},
{
"end": 312,
"raw": "0",
"start": 311,
"type": "Literal",
"type": "Literal",
"value": 0
}
],
"end": 313,
"start": 307,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 316,
"start": 315,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 306,
"name": "line",
"start": 302,
"type": "Identifier"
},
"end": 317,
"optional": false,
"start": 302,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"elements": [
{
"end": 334,
"raw": "0",
"start": 333,
"type": "Literal",
"type": "Literal",
"value": 0
},
{
"argument": {
"end": 338,
"raw": "1",
"start": 337,
"type": "Literal",
"type": "Literal",
"value": 1
},
"end": 338,
"operator": "-",
"start": 336,
"type": "UnaryExpression",
"type": "UnaryExpression"
}
],
"end": 339,
"start": 332,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 342,
"start": 341,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 331,
"name": "line",
"start": 327,
"type": "Identifier"
},
"end": 343,
"optional": false,
"start": 327,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 360,
"start": 359,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 358,
"name": "close",
"start": 353,
"type": "Identifier"
},
"end": 361,
"optional": false,
"start": 353,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 361,
"start": 213,
"type": "PipeExpression",
"type": "PipeExpression"
}
}
],
"start": 199,
"type": "ObjectExpression",
"type": "ObjectExpression"
}
}
],
"start": 187,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
"end": 367,
"start": 180,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"end": 369,
"start": 176
},
"end": 369,
"params": [],
"start": 170,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 162,
"type": "VariableDeclarator"
}
],
"end": 369,
"kind": "fn",
"start": 159,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declarations": [
{
"end": 381,
"id": {
"end": 372,
"name": "x",
"start": 371,
"type": "Identifier"
},
"init": {
"arguments": [],
"callee": {
"end": 379,
"name": "test",
"start": 375,
"type": "Identifier"
},
"end": 381,
"optional": false,
"start": 375,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 371,
"type": "VariableDeclarator"
}
],
"end": 381,
"kind": "const",
"start": 371,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 404,
"expression": {
"body": [
{
"end": 383,
"name": "x",
"start": 382,
"type": "Identifier",
"type": "Identifier"
},
{
"arguments": [
{
"argument": {
"end": 400,
"raw": "10",
"start": 398,
"type": "Literal",
"type": "Literal",
"value": 10
},
"end": 400,
"operator": "-",
"start": 397,
"type": "UnaryExpression",
"type": "UnaryExpression"
},
{
"end": 403,
"start": 402,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 396,
"name": "extrude",
"start": 389,
"type": "Identifier"
},
"end": 404,
"optional": false,
"start": 389,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 404,
"start": 382,
"type": "PipeExpression",
"type": "PipeExpression"
},
"start": 382,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declarations": [
{
"end": 418,
"id": {
"end": 408,
"name": "x2",
"start": 406,
"type": "Identifier"
},
"init": {
"arguments": [],
"callee": {
"end": 416,
"name": "test2",
"start": 411,
"type": "Identifier"
},
"end": 418,
"optional": false,
"start": 411,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 406,
"type": "VariableDeclarator"
}
],
"end": 418,
"kind": "const",
"start": 406,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 455,
"expression": {
"body": [
{
"computed": false,
"end": 435,
"object": {
"computed": false,
"end": 428,
"object": {
"end": 421,
"name": "x2",
"start": 419,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"end": 428,
"name": "thing1",
"start": 422,
"type": "Identifier",
"type": "Identifier"
},
"start": 419,
"type": "MemberExpression",
"type": "MemberExpression"
},
"property": {
"end": 435,
"name": "thing2",
"start": 429,
"type": "Identifier",
"type": "Identifier"
},
"start": 419,
"type": "MemberExpression",
"type": "MemberExpression"
},
{
"arguments": [
{
"end": 451,
"raw": "10",
"start": 449,
"type": "Literal",
"type": "Literal",
"value": 10
},
{
"end": 454,
"start": 453,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 448,
"name": "extrude",
"start": 441,
"type": "Identifier"
},
"end": 455,
"optional": false,
"start": 441,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 455,
"start": 419,
"type": "PipeExpression",
"type": "PipeExpression"
},
"start": 419,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 456,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [
{
"end": 159,
"start": 157,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"1": [
{
"end": 371,
"start": 369,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
],
"3": [
{
"end": 406,
"start": 404,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
}
},
"start": 0
}
}

View File

@ -9,21 +9,21 @@ fn test = () => {
fn test2 = () => {
return {
thing1: {
thing2: startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0, 1], %)
|> line([1, 0], %)
|> line([0, -1], %)
|> close(%)
}
thing1: {
thing2: startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0, 1], %)
|> line([1, 0], %)
|> line([0, -1], %)
|> close(%)
}
}
}
const x = test()
x = test()
x
|> extrude(-10, %)
const x2 = test2()
x2 = test2()
x2.thing1.thing2
|> extrude(10, %)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +0,0 @@
const part001 = startSketchOn('XY')
|> circle({ center: [5, 5], radius: 10 }, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0, ccw: true}, %)

View File

@ -1,107 +0,0 @@
fn f = (i) => {
return i * 2
}
let x = f(0)
+ f(1)
+ f(2)
+ f(3)
+ f(4)
+ f(5)
+ f(6)
+ f(7)
+ f(8)
+ f(9)
+ f(10)
+ f(11)
+ f(12)
+ f(13)
+ f(14)
+ f(15)
+ f(16)
+ f(17)
+ f(18)
+ f(19)
+ f(20)
+ f(21)
+ f(22)
+ f(23)
+ f(24)
+ f(25)
+ f(26)
+ f(27)
+ f(28)
+ f(29)
+ f(30)
+ f(31)
+ f(32)
+ f(33)
+ f(34)
+ f(35)
+ f(36)
+ f(37)
+ f(38)
+ f(39)
+ f(40)
+ f(41)
+ f(42)
+ f(43)
+ f(44)
+ f(45)
+ f(46)
+ f(47)
+ f(48)
+ f(49)
+ f(50)
+ f(51)
+ f(52)
+ f(53)
+ f(54)
+ f(55)
+ f(56)
+ f(57)
+ f(58)
+ f(59)
+ f(60)
+ f(61)
+ f(62)
+ f(63)
+ f(64)
+ f(65)
+ f(66)
+ f(67)
+ f(68)
+ f(69)
+ f(70)
+ f(71)
+ f(72)
+ f(73)
+ f(74)
+ f(75)
+ f(76)
+ f(77)
+ f(78)
+ f(79)
+ f(80)
+ f(81)
+ f(82)
+ f(83)
+ f(84)
+ f(85)
+ f(86)
+ f(87)
+ f(88)
+ f(89)
+ f(90)
+ f(91)
+ f(92)
+ f(93)
+ f(94)
+ f(95)
+ f(96)
+ f(97)
+ f(98)
+ f(99)
+ f(100)
assertEqual(x, 10100, 0.1, "Big sum")

View File

@ -1,6 +0,0 @@
fn increment = (i) => { return i + 1 }
xs = [0..2]
ys = xs
|> map(%, increment)
|> map(%, increment)

View File

@ -153,14 +153,6 @@ async fn kcl_test_helix_defaults_negative_extrude() {
assert_out("helix_defaults_negative_extrude", &result);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_helix_ccw() {
let code = kcl_input!("helix_ccw");
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("helix_ccw", &result);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_helix_with_length() {
let code = kcl_input!("helix_with_length");

View File

@ -5,16 +5,6 @@ use kcl_lib::{
parser,
};
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]
@ -37,27 +27,6 @@ macro_rules! gen_test_parse_fail {
};
}
async fn run(code: &str) {
let (ctx, program, id_generator) = setup(code).await;
let res = ctx
.run(
&program,
None,
id_generator,
Some("tests/executor/inputs/no_visuals/".to_owned()),
)
.await;
match res {
Ok(state) => {
println!("{:#?}", state.memory);
}
Err(e) => {
panic!("{e}");
}
}
}
async fn setup(program: &str) -> (ExecutorContext, Node<Program>, IdGenerator) {
let tokens = kcl_lib::token::lexer(program).unwrap();
let parser = kcl_lib::parser::Parser::new(tokens);
@ -97,11 +66,6 @@ async fn run_parse_fail(code: &str) -> KclError {
e
}
gen_test!(property_of_object);
gen_test!(index_of_array);
gen_test!(comparisons);
gen_test!(array_range_expr);
gen_test!(array_range_negative_expr);
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"
@ -138,14 +102,11 @@ gen_test_fail!(
pipe_substitution_inside_function_called_from_pipeline,
"semantic: cannot use % outside a pipe expression"
);
gen_test!(sketch_in_object);
gen_test!(if_else);
// gen_test_fail!(
// if_else_no_expr,
// "syntax: blocks inside an if/else expression must end in an expression"
// );
gen_test_fail!(comparisons_multiple, "syntax: Invalid number: true");
gen_test!(import_simple);
gen_test_fail!(
import_cycle1,
"import cycle: circular import of modules is not allowed: tests/executor/inputs/no_visuals/import_cycle2.kcl -> tests/executor/inputs/no_visuals/import_cycle3.kcl -> tests/executor/inputs/no_visuals/import_cycle1.kcl -> tests/executor/inputs/no_visuals/import_cycle2.kcl"
@ -171,9 +132,6 @@ gen_test_parse_fail!(
// import_in_function,
// "syntax: Can import only import at the top level"
// );
gen_test!(add_lots);
gen_test!(double_map);
gen_test!(array_elem_push);
gen_test_fail!(
array_elem_push_fail,
"undefined value: The array doesn't have any item at index 3"