add a test for coercing a nested array (#6326)

* add a test for coercing a nested array

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add console log

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add console log

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add test for what we get back on no_outputs error

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* remove my log

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* move test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Paul Tagliamonte <paul@zoo.dev>
This commit is contained in:
Jess Frazelle
2025-04-24 12:37:44 -07:00
committed by GitHub
parent 0e945b6457
commit 6e0f1e71b2
2 changed files with 82 additions and 1 deletions

View File

@ -2119,4 +2119,73 @@ d = cos(30)
assert_value_and_type("c", &result, 1.0, NumericType::count()); assert_value_and_type("c", &result, 1.0, NumericType::count());
assert_value_and_type("d", &result, 0.0, NumericType::count()); assert_value_and_type("d", &result, 0.0, NumericType::count());
} }
#[tokio::test(flavor = "multi_thread")]
async fn coerce_nested_array() {
let mut exec_state = ExecState::new(&crate::ExecutorContext::new_mock().await);
let mixed1 = KclValue::MixedArray {
value: vec![
KclValue::Number {
value: 0.0,
ty: NumericType::count(),
meta: Vec::new(),
},
KclValue::Number {
value: 1.0,
ty: NumericType::count(),
meta: Vec::new(),
},
KclValue::HomArray {
value: vec![
KclValue::Number {
value: 2.0,
ty: NumericType::count(),
meta: Vec::new(),
},
KclValue::Number {
value: 3.0,
ty: NumericType::count(),
meta: Vec::new(),
},
],
ty: RuntimeType::Primitive(PrimitiveType::Number(NumericType::count())),
},
],
meta: Vec::new(),
};
// Principal types
let tym1 = RuntimeType::Array(
Box::new(RuntimeType::Primitive(PrimitiveType::Number(NumericType::count()))),
ArrayLen::NonEmpty,
);
let result = KclValue::HomArray {
value: vec![
KclValue::Number {
value: 0.0,
ty: NumericType::count(),
meta: Vec::new(),
},
KclValue::Number {
value: 1.0,
ty: NumericType::count(),
meta: Vec::new(),
},
KclValue::Number {
value: 2.0,
ty: NumericType::count(),
meta: Vec::new(),
},
KclValue::Number {
value: 3.0,
ty: NumericType::count(),
meta: Vec::new(),
},
],
ty: RuntimeType::Primitive(PrimitiveType::Number(NumericType::count())),
};
assert_coerce_results(&mixed1, &tym1, &result, &mut exec_state);
}
} }

View File

@ -2,7 +2,7 @@ import type { Node } from '@rust/kcl-lib/bindings/Node'
import type { Program } from '@rust/kcl-lib/bindings/Program' import type { Program } from '@rust/kcl-lib/bindings/Program'
import type { ParseResult } from '@src/lang/wasm' import type { ParseResult } from '@src/lang/wasm'
import { formatNumber, parse } from '@src/lang/wasm' import { formatNumber, parse, errFromErrWithOutputs } from '@src/lang/wasm'
import { initPromise } from '@src/lang/wasmUtils' import { initPromise } from '@src/lang/wasmUtils'
import { enginelessExecutor } from '@src/lib/testHelpers' import { enginelessExecutor } from '@src/lib/testHelpers'
import { err } from '@src/lib/trap' import { err } from '@src/lib/trap'
@ -32,3 +32,15 @@ it('formats numbers with units', () => {
expect(formatNumber(0.5, 'Mm')).toEqual('0.5mm') expect(formatNumber(0.5, 'Mm')).toEqual('0.5mm')
expect(formatNumber(-0.5, 'Mm')).toEqual('-0.5mm') expect(formatNumber(-0.5, 'Mm')).toEqual('-0.5mm')
}) })
describe('test errFromErrWithOutputs', () => {
it('converts KclErrorWithOutputs to KclError', () => {
const blob =
'{"error":{"kind":"internal","sourceRanges":[],"msg":"Cache busted"},"operations":[],"artifactCommands":[],"artifactGraph":{"map":{}},"filenames":{},"sourceFiles":{},"defaultPlanes":null}'
const error = errFromErrWithOutputs(blob)
const errorStr = JSON.stringify(error)
expect(errorStr).toEqual(
'{"kind":"internal","sourceRange":[0,0,0],"msg":"Cache busted","operations":[],"artifactCommands":[],"artifactGraph":{},"filenames":{},"defaultPlanes":null}'
)
})
})