Skip to content

Commit

Permalink
$mol_view_tree2_to_js_test review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Dec 16, 2023
1 parent 1988818 commit 2089bf9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion view/tree2/to/js/test/ex/array_number.view.tree
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$mol_view_tree2_to_js_test_ex_array_number_foo $mol_object
bar /
- NaN
-NaN
-Infinity
+Infinity
0
2 changes: 1 addition & 1 deletion view/tree2/to/js/test/js.array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace $ {
$mol_assert_like(
foo.bar(),
[
// Number.NaN,
Number.NaN,
Number.NEGATIVE_INFINITY,
Number.POSITIVE_INFINITY,
0,
Expand Down
18 changes: 3 additions & 15 deletions view/tree2/to/js/test/run.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
namespace $ {

const str2js_dts = (function (this: $, data: string, url: string) {
const str2js = (function (this: $, data: string, url: string) {
const tree = this.$mol_tree2_from_string(data, url)
const js_tree = this.$mol_view_tree2_to_js(tree)
const js_text = this.$mol_tree2_js_to_text(js_tree)
const js_str = this.$mol_tree2_text_to_string_mapped_js(js_text)
return js_str
}).bind($ as typeof $$)

function $mol_view_tree2_to_js_test_id(stack_index = 1, no_prefix = false) {
const name = new Error('').stack
?.split('\n').at(stack_index + 1)?.match(/ at (.*) \(/)
?.[1].toLowerCase().replace(/[ .]/g, '_') ?? ''

if (no_prefix) return name

return '$mol_view_tree2_to_js_test_ex_' + name
}

export function $mol_view_tree2_to_js_test_run( tree: string ): any {
class $mol_view_mock extends $mol_object {}
const $ = { $mol_object: $mol_view_mock }
;( $mol_view_mock as any )[$mol_ambient_ref] = $

const name = $mol_view_tree2_to_js_test_id(2, true)

const src_uri = `${name}.view.tree`
const js = str2js_dts( tree, src_uri )
const src_uri = `.view.tree`
const js = str2js( tree, src_uri )

eval( js )
return $
Expand Down

0 comments on commit 2089bf9

Please sign in to comment.