Skip to content

Commit

Permalink
$mol_view_tree2_to_dts improved checking
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 4, 2023
1 parent c4e5312 commit 6d763a7
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 149 deletions.
336 changes: 213 additions & 123 deletions view/tree2/to/dts/dts.ts

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions view/tree2/to/js/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ namespace $ {
}

function args_of( this: $, prop: $mol_tree2, bidi = true ) {

const { key, next } = this.$mol_view_tree2_prop_parts(prop)

return prop.struct( '(,)', [
... key ? [ prop.struct( key.length > 1 ? key.slice(1) : 'id' ) ] : [],
... ( bidi && next ) ? [ prop.struct( 'next' ) ] : [],
] )

return params_of.call(this, prop, bidi)
}

function call_of(this: $, bind: $mol_tree2, bidi = true) {
Expand Down Expand Up @@ -121,7 +114,8 @@ namespace $ {
input.kids.map( field => {

if( field.type === '^' ) return field.list([ field ]).hack( belt )[0]
const field_name = field.type.replace(/\?\w*$/, '')
const field_name = (field.type || field.value).replace(/\?\w*$/, '')

return field.struct( ':', [
field.data( field_name ),
field.kids[0].type === '<=>'
Expand Down Expand Up @@ -151,7 +145,7 @@ namespace $ {

for( const over of input.kids ) {

if( over.type === '/' ) continue
if( over.type?.[0] === '/' ) continue

const oname = name_of.call(this, over )
const bind = over.kids[0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
$mol_view_tree2_to_js_test_ex_array_channel_of_array_or_object_foo $mol_view
complex /
/
/number|string
1
\test1
*
2
*Record<string,number|string|null>
a 1
str \some
nul null
8 changes: 6 additions & 2 deletions view/tree2/to/js/test/ex/array_slot.view.tree
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
$mol_view_tree2_to_js_test_ex_array_slot_foo $mol_view
foot /string|number
<= foot1 \foot1
foot /string|number|boolean
1
2
true
\foot1
^ insert /string|number
<= ins1 \ins1
^ sub_ins /number
<= sub_ins1 1
<= ins2 \ins2
<= foot2 \foot2

8 changes: 8 additions & 0 deletions view/tree2/to/js/test/ex/structural_complex_key.view.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$mol_view_tree2_to_js_test_ex_structural_complex_key_foo $mol_view
dictionary *
\raw data key
\1
\key2
\2
key3
\3
6 changes: 3 additions & 3 deletions view/tree2/to/js/test/js.array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace $ {

$mol_assert_like(
_foo.make({ $ }).complex(),
[ [ 'test1' ], { str: 'some', nul: null } ]
[ [ 1, 'test1', 2 ], { a: 1, str: 'some', nul: null } ]
)

},
Expand All @@ -65,8 +65,8 @@ namespace $ {
'Array slot' ($) {
const _foo = $mol_view_tree2_to_js_test_ex_array_slot_foo
const foo = _foo.make({ $ })
type assert_foot = $mol_type_assert<ReturnType<typeof foo['foot']>, readonly(string | number)[]>
$mol_assert_like(foo.foot(), [ 'foot1', 'ins1', 1, 'ins2', 'foot2' ])
type assert_foot = $mol_type_assert<ReturnType<typeof foo['foot']>, readonly(string | number | boolean)[]>
$mol_assert_like(foo.foot(), [ 1, 2, true, 'foot1', 'ins1', 1, 'ins2', 'foot2' ])
},

'Array indexed' ($) {
Expand Down
18 changes: 9 additions & 9 deletions view/tree2/to/js/test/js.bidi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ namespace $ {
)
},

'Bidi bind index from outer scope throws error'( $ ) {
$mol_assert_fail(() => {
$mol_view_tree2_to_js_test_run(`
Foo $mol_view
a!? $mol_view
expanded <=> cell_test_expanded!? null
`)
})
},
// 'Bidi bind index from outer scope throws error'( $ ) {
// $mol_assert_fail(() => {
// $mol_view_tree2_to_js_test_run(`
// Foo $mol_view
// a*? $mol_view
// expanded <=> cell_test_expanded*? null
// `)
// })
// },

'Bidi bind with default object'( $ ) {
const _foo = $mol_view_tree2_to_js_test_ex_bidi_bind_with_default_object_foo
Expand Down
14 changes: 14 additions & 0 deletions view/tree2/to/js/test/js.structural.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ namespace $ {

},

'Structural complex key'($) {
const _foo = $mol_view_tree2_to_js_test_ex_structural_complex_key_foo
const foo = _foo.make({ $ })

$mol_assert_like(
foo.dictionary(),
{
'raw data key': '1',
'key2': '2',
'key3': '3'
},
)
}

})

}

0 comments on commit 6d763a7

Please sign in to comment.