Repository navigation
Description
Summary
Add tests for c_import auto-method generation. The implementation already detects method and constructor patterns; the missing work is committed coverage for the §16.2a rules and opt-out interactions.
Spec
§16.2a says c_import detects C function names like structname_method(self, ...) and generates method syntax that is zero-cost sugar over the C function call (docs/with-specification.md:8205). Detection converts struct names to snake_case, treats first-parameter *S/*mut S/*const S/S functions as method candidates, treats *S/*mut S returns without self as constructor candidates, strips the prefix for the method name, supports type-call constructor sugar for .new, and provides no_methods opt-out (docs/with-specification.md:8225, docs/with-specification.md:8281).
Current state
ci_detect_member_functions scans imported functions and emits wrappers when the first parameter or return type matches a known struct (src/CImport.w:1220). It precomputes snake-case prefixes with ci_compute_snake_prefix (src/CImport.w:1308), strips prefixes with ci_strip_snake_prefix / ci_strip_struct_prefix (src/CImport.w:1356), emits member wrappers (src/CImport.w:1396), and emits constructor wrappers (src/CImport.w:1435). The requirement campaign found this implemented but not directly covered.
Implementation plan
- Add a C header fixture with
typedef struct GHashTable GHashTable;,g_hash_table_new,g_hash_table_insert,g_hash_table_lookup, and a second type to test ambiguity/prefix selection. - Write a With test that imports the header and checks that
.new,.insert,.lookup, and type-call constructor sugar type-check and lower to the generated wrappers. - Include first-parameter variations:
*mut S,*const S, and by-valueSif the importer supports by-value structs. - Add negative/opt-out coverage for
no_methods: trueandno_methods: "Type"from c_import: no_methods opt-out option (§16.2a) #416, proving flat C functions remain available. - Add a collision/ambiguity fixture if practical: longest prefix wins; equal length neither claims the function.
Test plan
Add test/behavior/behav_c_import_auto_methods.h and .w for positive method/constructor coverage. Add compile/check tests for no_methods disabling generated methods. Add an import surface snapshot or with check fixture if runtime linking to C functions is not needed.
Acceptance criteria
- Auto-generated member methods are covered for first-param type matching.
- Constructor wrapper and type-call sugar are covered.
- Prefix stripping and snake-case conversion are covered.
no_methodsopt-out behavior is covered without removing flat functions.with build && with build :fixpoint && with build :testpass.
Dependencies
Related to #416 for no_methods opt-out.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.2.2.1, 16.2.2.10, 16.2.2.2, 16.2.2.5, 16.2.2.6, 16.2.2.7, 16.2.2.8.
Activity
ehartford commentedon Jul 3, 2026
Closing — c_import factory-as-constructor sugar (Counter.make) pinned by behav_c_import_auto_constructor (3628d82); method sugar + no_methods opt-out already covered (behav_c_import_auto_method_baseline, behav_c_import_no_methods_flat, err_c_import_no_methods_*). §16.
test: coverage-sweep batch 5 (#485 #486 #487 #500 #505 #510)