@buaa_smat/hometrans 26.0.0 → 26.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -82
- package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +2 -2
- package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +2 -2
- package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +2 -2
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +1 -1
- package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
- package/skills/a2h-batch-ui-align/references/step3-capture.md +3 -3
- package/skills/a2h-batch-ui-align/references/step4-prepare.md +1 -1
- package/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +11 -6
- package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +59 -21
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -3
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +1 -1
- package/skills/a2h-utg-explorer/SKILL.md +1 -1
- package/skills/a2h-utg-explorer/references/architecture.md +2 -2
- package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +36 -11
- package/skills/a2h-utg-explorer/scripts/device_health.mjs +91 -6
- package/skills/a2h-utg-explorer/scripts/final_utg.mjs +20 -2
- package/skills/a2h-utg-explorer/scripts/hint_check.mjs +64 -8
- package/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
- package/skills/a2h-utg-explorer/scripts/recover.mjs +7 -1
- package/skills/a2h-utg-explorer/scripts/recover_b.mjs +8 -1
- package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +89 -7
- package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +173 -4
- package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +82 -14
- package/skills/a2h-utg-static/SKILL.md +1 -1
- package/skills/a2h-utg-static/references/view-interactions.md +1 -1
- package/skills/a2h-utg-static/scripts/assemble.mjs +6 -3
- package/skills/a2h-utg-static/scripts/compose_body_text.mjs +23 -5
- package/skills/a2h-utg-static/scripts/compose_overlay.mjs +29 -3
- package/skills/a2h-utg-static/scripts/compose_titles.mjs +10 -1
- package/skills/a2h-utg-static/scripts/label_resolve.mjs +51 -2
- package/skills/a2h-utg-static/scripts/static_prior.mjs +2 -1
- package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
- package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
- package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
- package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
- package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
- package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +135 -0
- package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
- package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
- package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
- package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
- package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
- package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
- package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
- package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
- package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
- package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
- package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
- package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
- package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
- package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
- package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
- package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
- package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
- package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
- package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
- package/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
- package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
- package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
- package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
- package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
- package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +155 -0
- package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
- package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
- package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
- package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
- package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
- package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
- package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
- package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
- package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +328 -0
- package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
- package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
- package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
- package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +83 -0
- package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
- package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
- package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
- package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
- package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
- package/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
- package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
- package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
- package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
- package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
- package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
- package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
- package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
- package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
- package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
- package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
- package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
- package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
- package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
- package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
- package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
- package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
- package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
- package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
- package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
- package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
- package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
- package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
- package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
- package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
- package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
- package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
- package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
- package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
- package/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
- package/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
- package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
- package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
- package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
- package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
- package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
- package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// viewpage_nav: code-built View pages swapped into a host Activity by a dispatch table
|
|
2
|
+
// (single-Activity app with no Fragment, Compose or layout XML). Also locks the
|
|
3
|
+
// implicit-receiver listener form in view_interactions, which hid every tab of such an app.
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import * as os from 'node:os';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import * as vp from '../viewpage_nav.mjs';
|
|
10
|
+
import * as vi from '../view_interactions.mjs';
|
|
11
|
+
|
|
12
|
+
const HOST = `package sample.app
|
|
13
|
+
|
|
14
|
+
class MainActivity : Activity() {
|
|
15
|
+
private enum class Destination(val label: String, val icon: Int) {
|
|
16
|
+
HOME("首页", R.drawable.ic_home),
|
|
17
|
+
LIBRARY("资料库", R.drawable.ic_lib),
|
|
18
|
+
QUERY("查询", R.drawable.ic_query),
|
|
19
|
+
SETTINGS("设置", R.drawable.ic_settings),
|
|
20
|
+
}
|
|
21
|
+
private var selectedDestination = Destination.HOME
|
|
22
|
+
private lateinit var content: FrameLayout
|
|
23
|
+
|
|
24
|
+
private fun tab(destination: Destination): TextView =
|
|
25
|
+
TextView(this).apply {
|
|
26
|
+
text = destination.label
|
|
27
|
+
setOnClickListener {
|
|
28
|
+
if (destination == selectedDestination) return@setOnClickListener
|
|
29
|
+
navigate(destination)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private fun navigate(destination: Destination) {
|
|
34
|
+
selectedDestination = destination
|
|
35
|
+
val page = when (destination) {
|
|
36
|
+
Destination.HOME -> HomePage(this, repo).build()
|
|
37
|
+
Destination.LIBRARY -> ListPage(activity = this, modes = libraryModes).build()
|
|
38
|
+
Destination.QUERY -> ListPage(activity = this, modes = queryModes).build()
|
|
39
|
+
Destination.SETTINGS -> SettingsPage(this, store, onDone = { x -> x }).build()
|
|
40
|
+
}
|
|
41
|
+
content.removeAllViews()
|
|
42
|
+
content.addView(page)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fun refreshCurrentPage() { navigate(selectedDestination) }
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const PAGES = `package sample.app
|
|
49
|
+
|
|
50
|
+
class HomePage(private val activity: MainActivity, private val repo: Repo) {
|
|
51
|
+
fun build(): ScrollView = ScrollView(activity).apply {
|
|
52
|
+
addView(Button(activity).apply { setOnClickListener { activity.showDetails() } })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
internal class ListPage(private val activity: MainActivity, private val modes: List<Mode>) {
|
|
56
|
+
fun build(): View { return LinearLayout(activity) }
|
|
57
|
+
}
|
|
58
|
+
class SettingsPage internal constructor(private val activity: MainActivity, private val store: Store, private val onDone: (Int) -> Int) {
|
|
59
|
+
fun build(): ScrollView = ScrollView(activity)
|
|
60
|
+
}
|
|
61
|
+
class Repo(private val activity: MainActivity) { fun load(): List<String> = emptyList() }
|
|
62
|
+
`;
|
|
63
|
+
const MANIFEST_NODE = { id: 'activity:MainActivity', kind: 'activity', name: 'MainActivity',
|
|
64
|
+
fqn: 'sample.app.MainActivity', declared_at: 'app/src/main/AndroidManifest.xml', is_launcher: true };
|
|
65
|
+
|
|
66
|
+
function fixture() {
|
|
67
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'vp-'));
|
|
68
|
+
const src = path.join(root, 'app', 'src', 'main', 'java', 'sample', 'app');
|
|
69
|
+
fs.mkdirSync(src, { recursive: true });
|
|
70
|
+
fs.writeFileSync(path.join(src, 'MainActivity.kt'), HOST);
|
|
71
|
+
fs.writeFileSync(path.join(src, 'Pages.kt'), PAGES);
|
|
72
|
+
const ws = path.join(root, 'ws');
|
|
73
|
+
fs.mkdirSync(ws);
|
|
74
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), JSON.stringify(MANIFEST_NODE) + '\n');
|
|
75
|
+
return { root, ws };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
test('one view-page per arm; a class shared by two arms is split per arm', () => {
|
|
79
|
+
const { root, ws } = fixture();
|
|
80
|
+
const [nodes] = vp.build(root, ws);
|
|
81
|
+
assert.deepEqual(nodes.map((n) => n.id), [
|
|
82
|
+
'view-page:HomePage', 'view-page:ListPage#library', 'view-page:ListPage#query', 'view-page:SettingsPage']);
|
|
83
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
84
|
+
assert.equal(byId.get('view-page:ListPage#query').label, '查询', 'label from the enum constant literal');
|
|
85
|
+
assert.equal(byId.get('view-page:HomePage').shell_host, 'activity:MainActivity');
|
|
86
|
+
assert.deepEqual(byId.get('view-page:SettingsPage').expected,
|
|
87
|
+
{ component: 'sample.app.MainActivity', hint_any: ['设置'] }, 'tab caption is a hint, never a title');
|
|
88
|
+
assert.ok(!byId.has('view-page:Repo'), 'a constructed non-View class is not a page');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('tab loop: every page reaches every other; host enters the initial page by default', () => {
|
|
92
|
+
const { root, ws } = fixture();
|
|
93
|
+
const [, edges] = vp.build(root, ws);
|
|
94
|
+
const pageTaps = edges.filter((e) => e.source.startsWith('view-page:'));
|
|
95
|
+
assert.equal(pageTaps.length, 4 * 3, 'persistent chrome: N pages x (N-1) targets');
|
|
96
|
+
assert.ok(pageTaps.every((e) => e.trigger === 'onClick@app/src/main/java/sample/app/MainActivity.kt:16'));
|
|
97
|
+
const fromHost = edges.filter((e) => e.source === 'activity:MainActivity');
|
|
98
|
+
const initial = fromHost.filter((e) => e.args.action === 'default');
|
|
99
|
+
assert.deepEqual(initial.map((e) => e.target), ['view-page:HomePage'],
|
|
100
|
+
'initial page proved by `var selectedDestination = Destination.HOME`');
|
|
101
|
+
assert.ok(!initial[0].trigger.startsWith('lifecycle@'), 'not a non-gesture detour for click_paths');
|
|
102
|
+
assert.equal(fromHost.length, 4, 'host also taps into the 3 non-initial pages');
|
|
103
|
+
assert.ok(!edges.some((e) => e.trigger.includes(':47')), 'refreshCurrentPage (not a listener) emits nothing');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('no page node in the workspace: nothing to anchor, no output', () => {
|
|
107
|
+
const { root, ws } = fixture();
|
|
108
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), '');
|
|
109
|
+
const [nodes, edges] = vp.build(root, ws);
|
|
110
|
+
assert.equal(nodes.length + edges.length, 0);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('view_interactions LISTENER: implicit receiver counts, declarations and dotted forms', () => {
|
|
114
|
+
const hit = (s) => { vi.LISTENER.lastIndex = 0; return vi.LISTENER.exec(s) !== null; };
|
|
115
|
+
assert.ok(hit('btn.setOnClickListener {'));
|
|
116
|
+
assert.ok(hit('btn . setOnClickListener(v -> x())'));
|
|
117
|
+
assert.ok(hit('TextView(this).apply {\n setOnClickListener {'), 'implicit receiver inside apply {}');
|
|
118
|
+
assert.ok(hit('init { setOnClickListener { toggle() } }'), 'a View subclass registering on itself');
|
|
119
|
+
assert.ok(!hit('override fun setOnClickListener(l: OnClickListener?) {'), 'a declaration is not a registration');
|
|
120
|
+
assert.ok(!hit('mySetOnClickListener {'), 'identifier suffix');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('view_interactions inventories implicit-receiver listeners and hosts them on view-page nodes', () => {
|
|
124
|
+
const { root, ws } = fixture();
|
|
125
|
+
const [nodes, edges] = vp.build(root, ws);
|
|
126
|
+
fs.appendFileSync(path.join(ws, 'nodes.jsonl'), nodes.map((n) => JSON.stringify(n) + '\n').join(''));
|
|
127
|
+
fs.writeFileSync(path.join(ws, 'edges.jsonl'), edges.map((e) => JSON.stringify(e) + '\n').join(''));
|
|
128
|
+
const wl = vi.collect(root, ws, false);
|
|
129
|
+
const all = [...wl.items, ...wl.prescreened];
|
|
130
|
+
const at = (f, ln) => all.find((i) => i.trigger_at === `app/src/main/java/sample/app/${f}:${ln}`);
|
|
131
|
+
assert.ok(at('MainActivity.kt', 16), 'tab listener inside TextView(this).apply {} is inventoried');
|
|
132
|
+
const home = at('Pages.kt', 5);
|
|
133
|
+
assert.ok(home, 'page-internal listener is inventoried');
|
|
134
|
+
assert.ok(home.host_candidates.includes('view-page:HomePage'), JSON.stringify(home.host_candidates));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// ---- review fixes (PR !49) ------------------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
function fixtureWith(files) {
|
|
140
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'vp2-'));
|
|
141
|
+
const src = path.join(root, 'app', 'src', 'main', 'java', 'sample', 'app');
|
|
142
|
+
fs.mkdirSync(src, { recursive: true });
|
|
143
|
+
for (const [n, t] of Object.entries(files)) { fs.writeFileSync(path.join(src, n), t); }
|
|
144
|
+
const ws = path.join(root, 'ws');
|
|
145
|
+
fs.mkdirSync(ws);
|
|
146
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), JSON.stringify(MANIFEST_NODE) + '\n');
|
|
147
|
+
return { root, ws };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
test('a bare imported constant restricts to its page; a constant button does not fan out', () => {
|
|
151
|
+
const host = HOST.replace(' fun refreshCurrentPage()',
|
|
152
|
+
' fun wire(settingsBtn: Button) { settingsBtn.setOnClickListener { navigate(SETTINGS) } }\n fun refreshCurrentPage()');
|
|
153
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': host, 'Pages.kt': PAGES });
|
|
154
|
+
const [, edges] = vp.build(root, ws);
|
|
155
|
+
const btnLine = host.split('\n').findIndex((l) => l.includes('settingsBtn.setOnClickListener')) + 1;
|
|
156
|
+
const viaBtn = edges.filter((e) => e.trigger.endsWith(`MainActivity.kt:${btnLine}`));
|
|
157
|
+
assert.ok(viaBtn.length > 0);
|
|
158
|
+
assert.ok(viaBtn.every((e) => e.target === 'view-page:SettingsPage'), JSON.stringify(viaBtn.map((e) => e.target)));
|
|
159
|
+
const fromHost = viaBtn.filter((e) => e.source === 'activity:MainActivity');
|
|
160
|
+
assert.deepEqual(fromHost.map((e) => e.target), ['view-page:SettingsPage'], 'the button reaches only Settings');
|
|
161
|
+
assert.ok(fromHost.every((e) => e.args.label === '设置'), 'its own target label, not a sibling tab label');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const JAVA_HOST = `package sample.app;
|
|
165
|
+
public class MainActivity extends Activity {
|
|
166
|
+
enum Destination { HOME("首页"), SETTINGS("设置"); Destination(String l) {} }
|
|
167
|
+
private Destination selected = Destination.HOME;
|
|
168
|
+
void wire(View homeBtn, View setBtn) {
|
|
169
|
+
homeBtn.setOnClickListener(v -> navigate(Destination.HOME));
|
|
170
|
+
setBtn.setOnClickListener(v -> navigate(Destination.SETTINGS));
|
|
171
|
+
}
|
|
172
|
+
private void navigate(Destination d) {
|
|
173
|
+
View page;
|
|
174
|
+
switch (d) {
|
|
175
|
+
case HOME: page = new HomePage(this).build(); break;
|
|
176
|
+
case SETTINGS: page = new SettingsPage(this).build(); break;
|
|
177
|
+
}
|
|
178
|
+
content.removeAllViews();
|
|
179
|
+
content.addView(page);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
const JAVA_PAGES = `package sample.app;
|
|
184
|
+
class HomePage { HomePage(MainActivity a) {} ScrollView build() { return null; } }
|
|
185
|
+
class SettingsPage { SettingsPage(MainActivity a) {} ScrollView build() { return null; } }
|
|
186
|
+
`;
|
|
187
|
+
|
|
188
|
+
test('Java switch with case CONST: qualified call arguments still restrict', () => {
|
|
189
|
+
const { root, ws } = fixtureWith({ 'MainActivity.java': JAVA_HOST, 'Pages.java': JAVA_PAGES });
|
|
190
|
+
const [nodes, edges] = vp.build(root, ws);
|
|
191
|
+
assert.deepEqual(nodes.map((n) => n.id), ['view-page:HomePage', 'view-page:SettingsPage']);
|
|
192
|
+
const at7 = edges.filter((e) => e.trigger.endsWith('MainActivity.java:7'));
|
|
193
|
+
assert.ok(at7.length && at7.every((e) => e.target === 'view-page:SettingsPage'), JSON.stringify(edges));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const AD_HOST = `package sample.app
|
|
197
|
+
class MainActivity : Activity() {
|
|
198
|
+
private fun show(kind: Kind) {
|
|
199
|
+
val adapter = when (kind) {
|
|
200
|
+
Kind.GRID -> GridAdapter(this)
|
|
201
|
+
Kind.LIST -> ListAdapter(this)
|
|
202
|
+
}
|
|
203
|
+
list.adapter = adapter
|
|
204
|
+
content.addView(list)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
`;
|
|
208
|
+
const ADAPTERS = `package sample.app
|
|
209
|
+
class GridAdapter(a: MainActivity) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { }
|
|
210
|
+
class ListAdapter(a: MainActivity) : RecyclerView.Adapter<Holder>() { }
|
|
211
|
+
class Holder(v: View) : RecyclerView.ViewHolder(v)
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
const CARD_HOST = `package sample.app
|
|
215
|
+
class MainActivity : Activity() {
|
|
216
|
+
private lateinit var list: LinearLayout
|
|
217
|
+
private fun render(items: List<Item>) {
|
|
218
|
+
list.removeAllViews()
|
|
219
|
+
for (item in items) {
|
|
220
|
+
val row = when (item.type) {
|
|
221
|
+
Type.HEADER -> HeaderCard(this).build(item)
|
|
222
|
+
Type.PRODUCT -> ProductCard(this).build(item)
|
|
223
|
+
Type.FOOTER -> FooterCard(this).build(item)
|
|
224
|
+
}
|
|
225
|
+
list.addView(row)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
private fun renderLambda(items: List<Item>) {
|
|
229
|
+
items.forEach { item ->
|
|
230
|
+
list.addView(when (item.type) {
|
|
231
|
+
Type.HEADER -> HeaderCard(this).build(item)
|
|
232
|
+
Type.FOOTER -> FooterCard(this).build(item)
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
const CARDS = `package sample.app
|
|
239
|
+
class HeaderCard(val a: MainActivity) { fun build(i: Item): View = View(a) }
|
|
240
|
+
class ProductCard(val a: MainActivity) { fun build(i: Item): View = View(a) }
|
|
241
|
+
class FooterCard(val a: MainActivity) { fun build(i: Item): View = View(a) }
|
|
242
|
+
`;
|
|
243
|
+
|
|
244
|
+
test('typed cards built per item in a loop are rows, not pages', () => {
|
|
245
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': CARD_HOST, 'Cards.kt': CARDS });
|
|
246
|
+
const [nodes, edges] = vp.build(root, ws);
|
|
247
|
+
assert.deepEqual(nodes.map((n) => n.id), []);
|
|
248
|
+
assert.equal(edges.length, 0);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('a table no gesture or initial page reaches is dropped, not emitted', () => {
|
|
252
|
+
const host = CARD_HOST.replace(/for \(item in items\) \{\n/, '{\n').replace(/items\.forEach \{ item ->\n/, '{\n');
|
|
253
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': host, 'Cards.kt': CARDS });
|
|
254
|
+
const [nodes, , stats] = vp.build(root, ws);
|
|
255
|
+
assert.deepEqual(nodes.map((n) => n.id), [], 'mounted but unreachable');
|
|
256
|
+
assert.ok(stats.dropped_tables.length >= 1, JSON.stringify(stats));
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('a helper View an arm builds before the page is not the page', () => {
|
|
260
|
+
const host = HOST.replace('Destination.HOME -> HomePage(this, repo).build()',
|
|
261
|
+
'Destination.HOME -> {\n LoadingView(this)\n HomePage(this, repo).build()\n }');
|
|
262
|
+
const pages = PAGES + 'class LoadingView(ctx: Context) : View(ctx)\n';
|
|
263
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': host, 'Pages.kt': pages });
|
|
264
|
+
const [nodes] = vp.build(root, ws);
|
|
265
|
+
assert.ok(nodes.some((n) => n.id === 'view-page:HomePage'), JSON.stringify(nodes.map((n) => n.id)));
|
|
266
|
+
assert.ok(!nodes.some((n) => n.id === 'view-page:LoadingView'));
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('adapter / view-holder dispatch tables are not view pages', () => {
|
|
270
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': AD_HOST, 'Adapters.kt': ADAPTERS });
|
|
271
|
+
const [nodes] = vp.build(root, ws);
|
|
272
|
+
assert.deepEqual(nodes.map((n) => n.id), []);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// No layout XML: a code-built page's on-device identity is the ids its class assigns, plus the
|
|
276
|
+
// id the host stamps on the mounted view from the table constant (the only one telling apart
|
|
277
|
+
// two arms of one class). Without them every capture of the page resolved `unmapped`.
|
|
278
|
+
test('layout_ids: ids the page class assigns plus the per-destination mount id', () => {
|
|
279
|
+
const host = HOST
|
|
280
|
+
.replace('private enum class Destination(val label: String, val icon: Int) {',
|
|
281
|
+
'private enum class Destination(val label: String, val icon: Int, val pageViewID: Int = 0) {')
|
|
282
|
+
.replace('HOME("首页", R.drawable.ic_home),', 'HOME("首页", R.drawable.ic_home, R.id.page_home),')
|
|
283
|
+
.replace('LIBRARY("资料库", R.drawable.ic_lib),', 'LIBRARY("资料库", R.drawable.ic_lib, pageViewID = R.id.page_library),')
|
|
284
|
+
.replace('QUERY("查询", R.drawable.ic_query),', 'QUERY("查询", R.drawable.ic_query, R.id.page_query),')
|
|
285
|
+
.replace('content.removeAllViews()', 'page.id = destination.pageViewID\n content.removeAllViews()');
|
|
286
|
+
const pages = PAGES
|
|
287
|
+
.replace('fun build(): ScrollView = ScrollView(activity).apply {',
|
|
288
|
+
'fun build(): ScrollView = ScrollView(activity).apply {\n id = R.id.home_scroll\n if (id == R.id.not_assigned) return@apply')
|
|
289
|
+
.replace('fun build(): View { return LinearLayout(activity) }',
|
|
290
|
+
'fun build(): View { return LinearLayout(activity).also { it.setId(R.id.list_root); findViewById<View>(R.id.read_only) } }');
|
|
291
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': host, 'Pages.kt': pages });
|
|
292
|
+
const [nodes] = vp.build(root, ws);
|
|
293
|
+
const ids = Object.fromEntries(nodes.map((n) => [n.id, n.layout_ids]));
|
|
294
|
+
assert.deepEqual(ids['view-page:HomePage'], ['home_scroll', 'page_home']);
|
|
295
|
+
assert.deepEqual(ids['view-page:ListPage#library'], ['list_root', 'page_library']);
|
|
296
|
+
assert.deepEqual(ids['view-page:ListPage#query'], ['list_root', 'page_query']);
|
|
297
|
+
assert.equal(ids['view-page:SettingsPage'], undefined, 'no assigned id, no mount id: field omitted');
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Reads that look like assignments are not the page's ids: a local `val/var id =` later passed to
|
|
301
|
+
// findViewById, a named argument `foo(id = R.id.x)`, the framework's `android.R.id.*`, and the ids
|
|
302
|
+
// a nested ViewHolder / Adapter class assigns to its rows. A package-qualified R still counts.
|
|
303
|
+
test('assignedIds: skips locals, named args, android.R and nested classes; keeps qualified R', () => {
|
|
304
|
+
const body = `{
|
|
305
|
+
fun build(): View = LinearLayout(activity).apply {
|
|
306
|
+
id = com.sample.app.R.id.page_root
|
|
307
|
+
val id = R.id.local_read
|
|
308
|
+
var other = 0; var id2 = 0
|
|
309
|
+
var id = R.id.local_var
|
|
310
|
+
bind(id = R.id.named_arg)
|
|
311
|
+
bind(x, id = R.id.named_arg2)
|
|
312
|
+
setId(android.R.id.content)
|
|
313
|
+
findViewById<View>(id)
|
|
314
|
+
it.setId(R.id.kept_set)
|
|
315
|
+
val k = Foo::class.java
|
|
316
|
+
tail.id = R.id.after_class_literal
|
|
317
|
+
}
|
|
318
|
+
inner class RowHolder(v: View) : RecyclerView.ViewHolder(v) {
|
|
319
|
+
init { v.id = R.id.row_item }
|
|
320
|
+
}
|
|
321
|
+
object Cfg { fun mk(v: View) { v.id = R.id.cfg_item } }
|
|
322
|
+
fun later(v: View) { v.id = R.id.after_nested }
|
|
323
|
+
}`;
|
|
324
|
+
assert.deepEqual(vp.assignedIds({ body }), ['after_class_literal', 'after_nested', 'kept_set', 'page_root']);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// `tab.id = R.id.nav_tab` in the dispatch function is not a per-destination stamp. Read as
|
|
328
|
+
// `R`.`id`, its prop `id` matched the enum's `val id: Int` and gave every page its nav-item id.
|
|
329
|
+
test('mountIds: a resource-id stamp (R.id.*) is not a per-destination mount id', () => {
|
|
330
|
+
const host = HOST
|
|
331
|
+
.replace('private enum class Destination(val label: String, val icon: Int) {',
|
|
332
|
+
'private enum class Destination(val label: String, val icon: Int, val id: Int = 0) {')
|
|
333
|
+
.replace('HOME("首页", R.drawable.ic_home),', 'HOME("首页", R.drawable.ic_home, R.id.nav_home),')
|
|
334
|
+
.replace('content.removeAllViews()', 'tabStrip.id = R.id.nav_tab\n content.removeAllViews()');
|
|
335
|
+
const { root, ws } = fixtureWith({ 'MainActivity.kt': host, 'Pages.kt': PAGES });
|
|
336
|
+
const [nodes] = vp.build(root, ws);
|
|
337
|
+
const home = nodes.find((n) => n.id === 'view-page:HomePage');
|
|
338
|
+
assert.ok(home);
|
|
339
|
+
assert.equal(home.layout_ids, undefined, 'no stamp from the table constant: no mount id');
|
|
340
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// vm_nav: navigation through a TOP-LEVEL helper (`fun navigate(route: NavKey)` forwarding to an
|
|
2
|
+
// app-wide navigator) and through route wrappers (`object XNavigator { fun toY() { navigate(Y) } }`),
|
|
3
|
+
// called from a ViewModel or straight from a page's callback lambda.
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import { routeWrappers, uiCallbackFor, vmNavEdges, vmNavHelpers } from '../vm_nav.mjs';
|
|
7
|
+
|
|
8
|
+
const FILES = new Map([
|
|
9
|
+
['/p/nav/NavigationService.kt', `package p.nav
|
|
10
|
+
object NavigationService {
|
|
11
|
+
fun navigate(route: NavKey) { requireNavigator().navigateTo(route = route) }
|
|
12
|
+
fun navigateAndCloseCurrent(route: NavKey, currentRoute: NavKey) {
|
|
13
|
+
val navOptions = NavigationOptions(popUpToRoute = currentRoute, inclusive = true)
|
|
14
|
+
requireNavigator().navigateTo(route = route, navOptions = navOptions)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
fun navigate(route: NavKey) {
|
|
18
|
+
NavigationService.navigate(route = route)
|
|
19
|
+
}
|
|
20
|
+
fun navigateAndCloseCurrent(route: NavKey, currentRoute: NavKey) {
|
|
21
|
+
NavigationService.navigateAndCloseCurrent(route = route, currentRoute = currentRoute)
|
|
22
|
+
}`],
|
|
23
|
+
['/p/nav/AuthNavigator.kt', `package p.nav
|
|
24
|
+
object AuthNavigator {
|
|
25
|
+
fun toLogin() {
|
|
26
|
+
navigate(AuthRoutes.Login)
|
|
27
|
+
}
|
|
28
|
+
fun toMainAndClose(currentRoute: NavKey) {
|
|
29
|
+
navigateAndCloseCurrent(route = MainRoutes.Main, currentRoute = currentRoute)
|
|
30
|
+
}
|
|
31
|
+
}`],
|
|
32
|
+
['/p/goods/GoodsViewModel.kt', `package p.goods
|
|
33
|
+
class GoodsViewModel @Inject constructor() : BaseViewModel() {
|
|
34
|
+
fun buyNow() {
|
|
35
|
+
if (!loggedIn) {
|
|
36
|
+
navigate(AuthRoutes.Login)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
navigate(
|
|
40
|
+
OrderRoutes.Confirm,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
fun leave() { AuthNavigator.toMainAndClose(currentRoute = GoodsRoutes.Detail) }
|
|
44
|
+
}`],
|
|
45
|
+
['/p/goods/GoodsScreen.kt', `package p.goods
|
|
46
|
+
@Composable
|
|
47
|
+
fun GoodsRoute(viewModel: GoodsViewModel = hiltViewModel()) {
|
|
48
|
+
GoodsScreen(
|
|
49
|
+
onBuyNow = viewModel::buyNow,
|
|
50
|
+
onLoginClick = { AuthNavigator.toLogin() },
|
|
51
|
+
)
|
|
52
|
+
}`],
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
const ROUTES = new Map([
|
|
56
|
+
['Login', 'compose-route:Login'], ['Confirm', 'compose-route:Confirm'],
|
|
57
|
+
['Main', 'compose-route:Main'], ['Detail', 'compose-route:Detail'],
|
|
58
|
+
]);
|
|
59
|
+
const pageOf = (f) => (f.endsWith('GoodsScreen.kt') ? 'compose-route:Detail' : null);
|
|
60
|
+
const rel = (f) => f.slice(3);
|
|
61
|
+
|
|
62
|
+
test('a top-level helper the ViewModel calls by bare name is a navigation helper', () => {
|
|
63
|
+
const h = vmNavHelpers(FILES);
|
|
64
|
+
assert.ok(h.has('navigate'), 'top-level `fun navigate(route)` is a helper');
|
|
65
|
+
assert.ok(h.has('navigateAndCloseCurrent'));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('ViewModel calls through the top-level helper become edges from the owning page', () => {
|
|
69
|
+
const { edges } = vmNavEdges(FILES, ROUTES, pageOf, rel);
|
|
70
|
+
const vm = edges.filter((e) => e.args.via === 'viewmodel');
|
|
71
|
+
const pairs = vm.map((e) => `${e.source}->${e.target}`).sort();
|
|
72
|
+
assert.deepEqual(pairs, ['compose-route:Detail->compose-route:Confirm', 'compose-route:Detail->compose-route:Login',
|
|
73
|
+
'compose-route:Detail->compose-route:Main']);
|
|
74
|
+
const confirm = vm.find((e) => e.target === 'compose-route:Confirm');
|
|
75
|
+
assert.equal(confirm.trigger, 'onClick@goods/GoodsViewModel.kt:8', 'multi-line call anchored at the call line');
|
|
76
|
+
assert.equal(confirm.args.ui_callback, 'onBuyNow', 'the page callback wired to viewModel::buyNow is named');
|
|
77
|
+
const main = vm.find((e) => e.target === 'compose-route:Main');
|
|
78
|
+
assert.equal(main.args.helper, 'AuthNavigator.toMainAndClose', 'a route wrapper called from the VM resolves');
|
|
79
|
+
assert.equal(main.args.closes_source, true, 'a close-current wrapper (forwarded popUpTo inclusive) closes its source');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('a route wrapper called from a page lambda is credited to that page', () => {
|
|
83
|
+
const { edges, wrapper } = vmNavEdges(FILES, ROUTES, pageOf, rel);
|
|
84
|
+
const page = edges.filter((e) => e.args.via === 'route-wrapper');
|
|
85
|
+
assert.equal(page.length, 1);
|
|
86
|
+
assert.equal(page[0].source, 'compose-route:Detail');
|
|
87
|
+
assert.equal(page[0].target, 'compose-route:Login');
|
|
88
|
+
assert.equal(page[0].args.ui_callback, 'onLoginClick');
|
|
89
|
+
assert.equal(wrapper.edges, 1);
|
|
90
|
+
assert.deepEqual(wrapper.unowned, [], "the wrapper's own body is a definition, not an unowned call");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('wrappers are keyed by owner; a bare name is kept only when unique at top level', () => {
|
|
94
|
+
const w = routeWrappers(FILES, vmNavHelpers(FILES), ROUTES);
|
|
95
|
+
assert.ok(w.byQual.has('AuthNavigator.toLogin'));
|
|
96
|
+
assert.ok(!w.byBare.has('toLogin'), 'an object member is not callable by its bare name');
|
|
97
|
+
assert.equal(uiCallbackFor('a(onX = { vm.go() }, onY = { vm.go() })', 'go'), null, 'two callbacks: ambiguous');
|
|
98
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Port of test_widget_class_scope.py: view_widgets resolves a page's layout in CLASS scope and refuses otherwise.
|
|
2
|
+
import { test, after } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import * as V from '../view_widgets.mjs';
|
|
8
|
+
|
|
9
|
+
const HOST_JAVA = `
|
|
10
|
+
package com.example.ui;
|
|
11
|
+
|
|
12
|
+
public class HostFragment extends Fragment {
|
|
13
|
+
@Override
|
|
14
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup c, Bundle b) {
|
|
15
|
+
return inflater.inflate(R.layout.outer_page, c, false);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private void showRename() {
|
|
19
|
+
new RenameDialog().show(getChildFragmentManager(), "rename");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static class InnerDialog extends DialogFragment {
|
|
23
|
+
@Override
|
|
24
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup c, Bundle b) {
|
|
25
|
+
return inflater.inflate(R.layout.inner_dialog, c, false);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
const OBJ_KT = `
|
|
31
|
+
package com.example.ui
|
|
32
|
+
|
|
33
|
+
object SettingsSheet {
|
|
34
|
+
fun render(inflater: LayoutInflater): View =
|
|
35
|
+
inflater.inflate(R.layout.settings_sheet, null, false)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class Unrelated {
|
|
39
|
+
fun other(inflater: LayoutInflater): View =
|
|
40
|
+
inflater.inflate(R.layout.unrelated_page, null, false)
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'wcs-'));
|
|
45
|
+
after(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
|
46
|
+
const write = (rel, text) => {
|
|
47
|
+
const p = path.join(tmp, ...rel.split('/'));
|
|
48
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
49
|
+
fs.writeFileSync(p, text, 'utf8');
|
|
50
|
+
};
|
|
51
|
+
write('app/src/main/java/com/example/ui/HostFragment.java', HOST_JAVA);
|
|
52
|
+
write('app/src/main/java/com/example/ui/SettingsSheet.kt', OBJ_KT);
|
|
53
|
+
const HOST_AT = 'app/src/main/java/com/example/ui/HostFragment.java:5';
|
|
54
|
+
const OBJ_AT = 'app/src/main/java/com/example/ui/SettingsSheet.kt:3';
|
|
55
|
+
const names = (node) => V.nodeLayoutNames(node, tmp, new Map());
|
|
56
|
+
|
|
57
|
+
test('host keeps its own layout, not the nested dialog\'s', () => {
|
|
58
|
+
const host = names({ id: 'fragment:HostFragment', kind: 'fragment', declared_at: HOST_AT });
|
|
59
|
+
assert.ok(host.includes('outer_page'));
|
|
60
|
+
assert.ok(!host.includes('inner_dialog'), String(host));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('nested class keeps its own layout', () => {
|
|
64
|
+
const inner = names({ id: 'dialog:InnerDialog', kind: 'dialog', declared_at: HOST_AT });
|
|
65
|
+
assert.ok(inner.includes('inner_dialog'));
|
|
66
|
+
assert.ok(!inner.includes('outer_page'), String(inner));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('hosted subnodes are refused', () => {
|
|
70
|
+
for (const [ident, kind] of [['menu:nav_context@HostFragment', 'menu'], ['mode:select@HostFragment', 'menu'],
|
|
71
|
+
['overlay:Confirm@HostFragment:42', 'dialog']]) {
|
|
72
|
+
assert.deepEqual(names({ id: ident, kind, declared_at: HOST_AT }), [], ident);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('a class the file does not declare claims no layout', () => {
|
|
77
|
+
assert.deepEqual(names({ id: 'overlay:RenameDialog', kind: 'dialog', declared_at: HOST_AT }), []);
|
|
78
|
+
assert.deepEqual(names({ id: 'fragment:RenameDialogClose', kind: 'fragment', declared_at: HOST_AT }), []);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('Kotlin object is a declarator', () => {
|
|
82
|
+
const obj = names({ id: 'dialog:SettingsSheet', kind: 'dialog', declared_at: OBJ_AT });
|
|
83
|
+
assert.ok(obj.includes('settings_sheet'));
|
|
84
|
+
assert.ok(!obj.includes('unrelated_page'), String(obj));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('refusals are tracked as id sets', () => {
|
|
88
|
+
// depends on the calls above (node:test runs tests in file order)
|
|
89
|
+
assert.ok(V.SCOPE_STATS.hosted instanceof Set && V.SCOPE_STATS.call_site instanceof Set);
|
|
90
|
+
assert.ok(V.SCOPE_STATS.hosted.has('menu:nav_context@HostFragment'));
|
|
91
|
+
assert.ok(V.SCOPE_STATS.call_site.has('overlay:RenameDialog'));
|
|
92
|
+
});
|