mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
refactor tests - remove eval_modules
This commit is contained in:
@@ -414,7 +414,6 @@ export const eval_modules = (
|
|||||||
on_deferred_call,
|
on_deferred_call,
|
||||||
calltree_changed_token,
|
calltree_changed_token,
|
||||||
io_trace,
|
io_trace,
|
||||||
location
|
|
||||||
) => {
|
) => {
|
||||||
// TODO gensym __cxt, __trace, __trace_call, __calltree_node_by_loc,
|
// TODO gensym __cxt, __trace, __trace_call, __calltree_node_by_loc,
|
||||||
// __do_await, __Multiversion, __create_array, __create_object
|
// __do_await, __Multiversion, __create_array, __create_object
|
||||||
|
|||||||
34
test/test.js
34
test/test.js
@@ -1,6 +1,6 @@
|
|||||||
import {find_leaf, ancestry, find_node} from '../src/ast_utils.js'
|
import {find_leaf, ancestry, find_node} from '../src/ast_utils.js'
|
||||||
import {print_debug_node} from '../src/parse_js.js'
|
import {print_debug_node} from '../src/parse_js.js'
|
||||||
import {eval_frame, eval_modules} from '../src/eval.js'
|
import {eval_frame} from '../src/eval.js'
|
||||||
import {COMMANDS, with_version_number_of_log} from '../src/cmd.js'
|
import {COMMANDS, with_version_number_of_log} from '../src/cmd.js'
|
||||||
import {header} from '../src/value_explorer_utils.js'
|
import {header} from '../src/value_explorer_utils.js'
|
||||||
import {
|
import {
|
||||||
@@ -833,15 +833,11 @@ export const tests = [
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
test('eval_frame modules', () => {
|
test('eval_frame modules', () => {
|
||||||
const parsed = parse_modules(
|
const i = test_initial_state({
|
||||||
'b',
|
'' : 'import {a} from "a"; export const b = a*2;',
|
||||||
{
|
'a' : 'export const a = 1;',
|
||||||
'a' : 'export const a = 1;',
|
})
|
||||||
'b' : 'import {a} from "a"; export const b = a*2;',
|
const frame = active_frame(i)
|
||||||
}
|
|
||||||
)
|
|
||||||
const {calltree, modules} = eval_modules(parsed);
|
|
||||||
const frame = eval_frame(calltree, modules)
|
|
||||||
assert_equal(frame.children[1].result, {ok: true})
|
assert_equal(frame.children[1].result, {ok: true})
|
||||||
assert_equal(
|
assert_equal(
|
||||||
find_node(frame, n => n.string == 'b').result.value,
|
find_node(frame, n => n.string == 'b').result.value,
|
||||||
@@ -1022,19 +1018,17 @@ export const tests = [
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
test('modules', () => {
|
test('modules', () => {
|
||||||
const parsed = parse_modules(
|
const i = test_initial_state(
|
||||||
'd',
|
|
||||||
{
|
{
|
||||||
'a' : 'export const a = 1;',
|
'a' : 'export const a = 1;',
|
||||||
'b' : 'import {a} from "a"; export const b = a*2;',
|
'b' : 'import {a} from "a"; export const b = a*2;',
|
||||||
'c1' : 'import {b} from "b"; import {a} from "a"; export const c1 = b*2;',
|
'c1' : 'import {b} from "b"; import {a} from "a"; export const c1 = b*2;',
|
||||||
'c2' : 'import {b} from "b"; import {a} from "a"; export const c2 = b*2;',
|
'c2' : 'import {b} from "b"; import {a} from "a"; export const c2 = b*2;',
|
||||||
'd' : 'import {c1} from "c1"; import {c2} from "c2"; export const d = c1 + c2;',
|
'' : 'import {c1} from "c1"; import {c2} from "c2"; export const result = c1 + c2;',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
assert_equal(parsed.sorted, ['a', 'b', 'c1', 'c2', 'd'])
|
assert_equal(i.parse_result.sorted, ['a', 'b', 'c1', 'c2', ''])
|
||||||
const modules = eval_modules(parsed).modules;
|
assert_equal(i.modules[''].result, 8)
|
||||||
assert_equal(modules.d.d, 8)
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
test('module loaded just once', () => {
|
test('module loaded just once', () => {
|
||||||
@@ -1042,10 +1036,9 @@ export const tests = [
|
|||||||
root -> intermediate1 -> leaf
|
root -> intermediate1 -> leaf
|
||||||
root -> intermediate2 -> leaf
|
root -> intermediate2 -> leaf
|
||||||
*/
|
*/
|
||||||
const parsed = parse_modules(
|
const i = test_initial_state(
|
||||||
'root',
|
|
||||||
{
|
{
|
||||||
'root' : `
|
'' : `
|
||||||
import {l1} from "intermediate1";
|
import {l1} from "intermediate1";
|
||||||
import {l2} from "intermediate2";
|
import {l2} from "intermediate2";
|
||||||
export const is_eq = l1 == l2;
|
export const is_eq = l1 == l2;
|
||||||
@@ -1055,10 +1048,9 @@ export const tests = [
|
|||||||
'leaf' : 'export const leaf = {}',
|
'leaf' : 'export const leaf = {}',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
const mods = eval_modules(parsed).modules
|
|
||||||
// Check that the same symbol improted through different paths gives the
|
// Check that the same symbol improted through different paths gives the
|
||||||
// same result
|
// same result
|
||||||
assert_equal(mods.root.is_eq, true)
|
assert_equal(i.modules[''].is_eq, true)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
test('modules empty import', () => {
|
test('modules empty import', () => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {find_error_origin_node} from '../src/ast_utils.js'
|
import {find_error_origin_node} from '../src/ast_utils.js'
|
||||||
import {parse, print_debug_node, load_modules} from '../src/parse_js.js'
|
import {parse, print_debug_node, load_modules} from '../src/parse_js.js'
|
||||||
import {eval_modules} from '../src/eval.js'
|
|
||||||
import {active_frame, pp_calltree, version_number_symbol} from '../src/calltree.js'
|
import {active_frame, pp_calltree, version_number_symbol} from '../src/calltree.js'
|
||||||
import {COMMANDS} from '../src/cmd.js'
|
import {COMMANDS} from '../src/cmd.js'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user