Files
modeling-app/src/lang/std/std.test.ts

29 lines
939 B
TypeScript
Raw Normal View History

2023-03-15 08:15:01 +11:00
import { abstractSyntaxTree } from '../abstractSyntaxTree'
import { executor } from '../../lib/testHelpers'
2023-03-15 08:15:01 +11:00
import { lexer } from '../tokeniser'
import { initPromise } from '../rust'
beforeAll(() => initPromise)
describe('testing angledLineThatIntersects', () => {
it('angledLineThatIntersects should intersect with another line', async () => {
2023-03-15 08:15:01 +11:00
const code = (offset: string) => `const part001 = startSketchAt([0, 0])
|> lineTo({to:[2, 2], tag: "yo"}, %)
|> lineTo([3, 1], %)
|> angledLineThatIntersects({
angle: 180,
intersectTag: 'yo',
offset: ${offset},
tag: "yo2"
}, %)
const intersect = segEndX('yo2', part001)
show(part001)`
const { root } = await executor(abstractSyntaxTree(lexer(code('-1'))))
2023-03-15 08:15:01 +11:00
expect(root.intersect.value).toBe(1 + Math.sqrt(2))
const { root: noOffset } = await executor(
abstractSyntaxTree(lexer(code('0')))
)
2023-03-15 08:15:01 +11:00
expect(noOffset.intersect.value).toBeCloseTo(1)
})
})