mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-14 05:14:28 -08:00
make cursor position controlled property of state
This commit is contained in:
109
test/test.js
109
test/test.js
@@ -2,8 +2,13 @@ import {find_leaf, ancestry, find_node} from '../src/ast_utils.js'
|
||||
import {parse, print_debug_node} from '../src/parse_js.js'
|
||||
import {eval_tree, eval_frame, eval_modules} from '../src/eval.js'
|
||||
import {COMMANDS} from '../src/cmd.js'
|
||||
import {root_calltree_node, active_frame, pp_calltree, get_deferred_calls}
|
||||
from '../src/calltree.js'
|
||||
import {
|
||||
root_calltree_node,
|
||||
active_frame,
|
||||
pp_calltree,
|
||||
get_deferred_calls,
|
||||
current_caret_position,
|
||||
} from '../src/calltree.js'
|
||||
import {color_file} from '../src/color.js'
|
||||
import {
|
||||
test,
|
||||
@@ -863,7 +868,6 @@ export const tests = [
|
||||
console.log(foo_var)
|
||||
`
|
||||
const s1 = test_initial_state(code)
|
||||
assert_equal(s1.loading_external_imports_state.index, 0)
|
||||
assert_equal(s1.loading_external_imports_state.external_imports, ['foo.js'])
|
||||
|
||||
const state = COMMANDS.external_imports_loaded(s1, s1, {
|
||||
@@ -897,7 +901,6 @@ export const tests = [
|
||||
// embed_value_explorer suspended until external imports resolved
|
||||
assert_equal(effects.length, 1)
|
||||
assert_equal(effects[0].type, 'save_to_localstorage')
|
||||
assert_equal(state.loading_external_imports_state.index, index)
|
||||
assert_equal(
|
||||
state.loading_external_imports_state.external_imports,
|
||||
['foo.js'],
|
||||
@@ -1106,18 +1109,11 @@ export const tests = [
|
||||
|
||||
const x_result_1 = COMMANDS.goto_definition(s, entry.indexOf('x*x'))
|
||||
assert_equal(x_result_1.state.current_module, '')
|
||||
assert_equal(
|
||||
x_result_1.effects,
|
||||
{type: 'set_caret_position', args: [entry.indexOf('x')]}
|
||||
)
|
||||
assert_equal(current_caret_position(x_result_1.state), entry.indexOf('x'))
|
||||
|
||||
const x_result_2 = COMMANDS.goto_definition(s, entry.indexOf('x'))
|
||||
assert_equal(x_result_2.state.current_module, 'a')
|
||||
assert_equal(
|
||||
x_result_2.effects,
|
||||
{type: 'set_caret_position', args: [a.indexOf('x = 2')]}
|
||||
)
|
||||
|
||||
assert_equal(current_caret_position(x_result_2.state), a.indexOf('x = 2'))
|
||||
}),
|
||||
|
||||
test('assignment', () => {
|
||||
@@ -1183,11 +1179,8 @@ export const tests = [
|
||||
const {state, effects} = COMMANDS.step_into(initial, code.indexOf('x()'))
|
||||
const call_code = state.current_calltree_node.code
|
||||
assert_equal(call_code.index, code.indexOf('() =>'))
|
||||
assert_equal(effects[0], {
|
||||
type: 'set_caret_position',
|
||||
args: [code.indexOf('() =>')],
|
||||
})
|
||||
assert_equal(effects[1].type, 'embed_value_explorer')
|
||||
assert_equal(current_caret_position(state), code.indexOf('() =>'))
|
||||
assert_equal(effects.type, 'embed_value_explorer')
|
||||
}),
|
||||
|
||||
test('step_into deepest', () => {
|
||||
@@ -1587,28 +1580,26 @@ const y = x()`
|
||||
const index = 0 // Where call starts
|
||||
const call = root_calltree_node(s).children[0]
|
||||
const {state, effects} = COMMANDS.calltree.click(s, call.id)
|
||||
assert_equal(current_caret_position(state), index)
|
||||
assert_equal(
|
||||
effects,
|
||||
[
|
||||
{ type: 'set_caret_position', args: [ index ] },
|
||||
{
|
||||
"type": "embed_value_explorer",
|
||||
"args": [
|
||||
{
|
||||
index,
|
||||
result: {
|
||||
"ok": true,
|
||||
"value": {
|
||||
"*arguments*": [
|
||||
[]
|
||||
],
|
||||
"*return*": {}
|
||||
}
|
||||
{
|
||||
"type": "embed_value_explorer",
|
||||
"args": [
|
||||
{
|
||||
index,
|
||||
result: {
|
||||
"ok": true,
|
||||
"value": {
|
||||
"*arguments*": [
|
||||
[]
|
||||
],
|
||||
"*return*": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}),
|
||||
|
||||
@@ -1624,10 +1615,7 @@ const y = x()`
|
||||
const assert_loc = (s, substring, is_assert_node_by_loc) => {
|
||||
const {state, effects} = COMMANDS.calltree.arrow_right(s)
|
||||
const index = code.indexOf(substring)
|
||||
assert_equal(
|
||||
effects[0],
|
||||
{type: 'set_caret_position', args: [index]}
|
||||
)
|
||||
assert_equal(current_caret_position(state), index)
|
||||
if(is_assert_node_by_loc) {
|
||||
assert_equal(
|
||||
state.calltree_node_by_loc[''][index] == null,
|
||||
@@ -1903,10 +1891,8 @@ const y = x()`
|
||||
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
|
||||
assert_equal(s3.selection_state.result.value, 1)
|
||||
assert_equal(s3.selection_state.node.index, code.indexOf('x()'))
|
||||
assert_equal(
|
||||
effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('x()'), true]}
|
||||
)
|
||||
assert_equal(current_caret_position(s3), code.indexOf('x()'))
|
||||
assert_equal(effects, {type: 'set_focus'})
|
||||
}),
|
||||
|
||||
test('select_return_value expanded', () => {
|
||||
@@ -1921,10 +1907,8 @@ const y = x()`
|
||||
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
|
||||
assert_equal(s3.selection_state.result.value, 1)
|
||||
assert_equal(s3.selection_state.node.index, code.indexOf('1'))
|
||||
assert_equal(
|
||||
effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('1'), true]}
|
||||
)
|
||||
assert_equal(current_caret_position(s3), code.indexOf('1'))
|
||||
assert_equal(effects, {type: 'set_focus'})
|
||||
}),
|
||||
|
||||
test('select_return_value fn curly braces', () => {
|
||||
@@ -1939,10 +1923,8 @@ const y = x()`
|
||||
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
|
||||
assert_equal(s3.selection_state.result.value, 1)
|
||||
assert_equal(s3.selection_state.node.index, code.indexOf('1'))
|
||||
assert_equal(
|
||||
effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('1'), true]}
|
||||
)
|
||||
assert_equal(current_caret_position(s3), code.indexOf('1'))
|
||||
assert_equal(effects, {type: 'set_focus'})
|
||||
}),
|
||||
|
||||
test('select_return_value fn curly braces no return', () => {
|
||||
@@ -1956,10 +1938,8 @@ const y = x()`
|
||||
const s2 = COMMANDS.calltree.arrow_right(s2_0).state
|
||||
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
|
||||
assert_equal(s3.selection_state, null)
|
||||
assert_equal(
|
||||
effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('{'), true]}
|
||||
)
|
||||
assert_equal(current_caret_position(s3), code.indexOf('{'))
|
||||
assert_equal(effects, {type: 'set_focus'})
|
||||
}),
|
||||
|
||||
test('select_return_value native', () => {
|
||||
@@ -1983,10 +1963,8 @@ const y = x()`
|
||||
const s2 = COMMANDS.calltree.arrow_right(s1).state
|
||||
const s3 = COMMANDS.calltree.select_arguments(s2)
|
||||
assert_equal(s3.state.selection_state.result, {ok: true, value: [1]})
|
||||
assert_equal(
|
||||
s3.effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('(1)'), true]}
|
||||
)
|
||||
assert_equal(current_caret_position(s3.state), code.indexOf('(1)'))
|
||||
assert_equal(s3.effects, {type: 'set_focus'})
|
||||
}),
|
||||
|
||||
test('select_arguments expanded', () => {
|
||||
@@ -2001,10 +1979,8 @@ const y = x()`
|
||||
const s2 = COMMANDS.calltree.arrow_right(s2_0).state
|
||||
const s3 = COMMANDS.calltree.select_arguments(s2)
|
||||
assert_equal(s3.state.selection_state.result, {ok: true, value: {a: 1}})
|
||||
assert_equal(
|
||||
s3.effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('(a)'), true]}
|
||||
)
|
||||
assert_equal(current_caret_position(s3.state), code.indexOf('(a)'))
|
||||
assert_equal(s3.effects, {type: 'set_focus'})
|
||||
}),
|
||||
|
||||
test('move_cursor arguments', () => {
|
||||
@@ -2370,10 +2346,7 @@ const y = x()`
|
||||
const {state, effects} = COMMANDS.calltree.navigate_logs_position(i, 0)
|
||||
assert_equal(state.logs.log_position, 0)
|
||||
assert_equal(state.selection_state.result.value, [10])
|
||||
assert_equal(
|
||||
effects,
|
||||
{type: 'set_caret_position', args: [code.indexOf('(x)'), false]}
|
||||
)
|
||||
assert_equal(current_caret_position(state), code.indexOf('(x)'))
|
||||
}),
|
||||
|
||||
test('deferred calls', () => {
|
||||
|
||||
Reference in New Issue
Block a user