2 Commits

Author SHA1 Message Date
Laszlo Nagy dea535751c move methods to types and introduce ResolvedTable
Option A: move free functions to methods on their natural types
- FlagMatch::name_len() (was codegen::flag_name_len)
- EnvEntry::validate() (was codegen::validate_env_entry)
- EnvMappingYaml::to_rust() (was codegen::env_mapping_to_rust)

codegen.rs now contains only the two string-to-string converters
(pattern_to_rust, result_to_rust) that operate on raw YAML strings.

Option B: introduce ResolvedTable struct that encapsulates inheritance
resolution and code generation for a single compiler table.
- ResolvedTable::new() merges flags, ignore_when, slash_prefix, env
- ResolvedTable::generate() produces the complete output file
- generate() in lib.rs becomes a thin loop over TABLES
- Snapshot tests reduce from 20-line helper to one-liner

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 09:31:02 +00:00
Laszlo Nagy b54ce0a953 add snapshot, schema validation, and property-based tests
Phase 2 of the bear-codegen extraction:

- Add insta snapshot tests for all 14 generated files (12 flag tables +
  recognition.rs + env_keys.rs). Any change in YAML or codegen logic
  is caught as a snapshot diff.

- Add YAML schema validation tests: extends references, result strings,
  pattern codegen, env entry validation, circular extends detection,
  and structural invariants (typed tables have recognition entries,
  all tables have flags).

- Add proptest property-based tests for pattern_to_rust and flag_name_len:
  suffix-to-variant mapping, count-dependent behavior, and bounds.

- Refactor validate_env_entry to return Result<(), String> instead of
  panicking, so tests get structured error messages. Build path still
  unwraps (panics on invalid YAML).

- Refactor generate_recognition_patterns and generate_env_keys to return
  strings instead of writing files, enabling direct snapshot testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 09:14:23 +00:00