Skip to content

Commit 5780fb9

Browse files
gHashTaggHashTag
andauthored
compiler tests: positive-control set for declaration parser (16->21). Closes #1130 (#1133)
Co-authored-by: gHashTag <admin@t27.ai>
1 parent 61cfe6d commit 5780fb9

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

bootstrap/src/compiler.rs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20020,6 +20020,105 @@ mod tests_compiler_rejects {
2002020020
r
2002120021
);
2002220022
}
20023+
20024+
// -----------------------------------------------------------------------
20025+
// Variant T: positive control set, the mirror of variants K/M/Q. Those
20026+
// pin what the parser REJECTS or recovers from; this pins what it ACCEPTS
20027+
// and lowers, so the negative gate cannot silently start over-rejecting
20028+
// valid input (the same role `accepts_valid_cast_as_control` plays for the
20029+
// cast tests, lifted to the module/declaration level). Every assertion was
20030+
// confirmed empirically against the current lowering before being written.
20031+
// -----------------------------------------------------------------------
20032+
20033+
// (T) Multiple `const` declarations in one module all lower to parameters.
20034+
#[test]
20035+
fn accepts_multiple_consts() {
20036+
let v = emit(r#"module TMultiConst { pub const A : u32 = 7 pub const B : u32 = 9 }"#);
20037+
assert!(
20038+
v.contains("A = 7") && v.contains("B = 9"),
20039+
"both consts must lower to parameters, got:\n{}",
20040+
v
20041+
);
20042+
assert!(
20043+
!v.contains("// TODO: implement"),
20044+
"a valid module must not be dropped, got:\n{}",
20045+
v
20046+
);
20047+
}
20048+
20049+
// (T) A `fn` WITH a body lowers its operand (contrast with variant Q's
20050+
// `rejects_fn_declaration_without_body`, where the body-less form is dropped).
20051+
#[test]
20052+
fn accepts_fn_with_body() {
20053+
let v = emit(r#"module TFnBody { pub fn id(x: u8) -> u8 { return x } }"#);
20054+
assert!(
20055+
v.contains("id = x"),
20056+
"a function with a body must lower its operand, got:\n{}",
20057+
v
20058+
);
20059+
assert!(
20060+
!v.contains("// TODO: implement"),
20061+
"a valid function body must not be dropped, got:\n{}",
20062+
v
20063+
);
20064+
}
20065+
20066+
// (T) A module mixing a `const` and a `fn` lowers both -- declaration kinds
20067+
// do not interfere with each other on the happy path.
20068+
#[test]
20069+
fn accepts_mixed_const_and_fn() {
20070+
let v = emit(r#"module TMixed { pub const W : u32 = 4 pub fn id(x: u8) -> u8 { return x } }"#);
20071+
assert!(
20072+
v.contains("W = 4") && v.contains("id = x"),
20073+
"both the const and the fn must lower, got:\n{}",
20074+
v
20075+
);
20076+
}
20077+
20078+
// (T) A `struct` declaration is accepted without error and without dropping
20079+
// the module (it is metadata, not a Verilog assign, so we assert acceptance
20080+
// and a clean -- non-TODO -- emit rather than a specific lowered token).
20081+
#[test]
20082+
fn accepts_struct_declaration() {
20083+
let v = emit(r#"module TStruct { pub struct Pt { x: u8, y: u8 } }"#);
20084+
assert!(
20085+
v.contains("module TStruct ("),
20086+
"a module with a struct decl must still emit, got:\n{}",
20087+
v
20088+
);
20089+
assert!(
20090+
!v.contains("// TODO: implement"),
20091+
"a valid struct decl must not drop the module, got:\n{}",
20092+
v
20093+
);
20094+
}
20095+
20096+
// (T) CHARACTERIZATION of the multi-module surface. Variant Q pinned that two
20097+
// top-level modules compile WITHOUT error; this records the *lowering* side of
20098+
// that fact: only the FIRST module is emitted to Verilog (exactly one `module`
20099+
// keyword, the second module's body does not appear). This is current
20100+
// behavior, not an endorsement -- if multi-module emission is added later this
20101+
// test must be updated deliberately.
20102+
#[test]
20103+
fn lowers_only_first_of_two_modules_characterization() {
20104+
let v = emit(r#"module TFirst { pub const A : u32 = 1 } module TSecond { pub const B : u32 = 2 }"#);
20105+
assert!(
20106+
v.contains("module TFirst ("),
20107+
"the first module must be emitted, got:\n{}",
20108+
v
20109+
);
20110+
assert_eq!(
20111+
v.matches("module ").count(),
20112+
1,
20113+
"only the first module is currently lowered (one `module` keyword), got:\n{}",
20114+
v
20115+
);
20116+
assert!(
20117+
!v.contains("TSecond"),
20118+
"the second module is not currently lowered, got:\n{}",
20119+
v
20120+
);
20121+
}
2002320122
}
2002420123

2002520124
#[cfg(test)]

docs/NOW.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Last updated: 2026-06-14
44

5+
## loop9-t-decl-positive-tests -- positive-control tests for the declaration parser (Closes #1130)
6+
7+
- **WHERE**: bootstrap/src/compiler.rs, mod tests_compiler_rejects (test-only additions).
8+
- **WHAT**: added 5 positive-control tests pinning what the declaration parser ACCEPTS and lowers (accepts_multiple_consts, accepts_fn_with_body, accepts_mixed_const_and_fn, accepts_struct_declaration, lowers_only_first_of_two_modules_characterization); count 16 -> 21.
9+
- **Why** the mirror of #1123: #1123 pinned rejections/recovery; this pins acceptance/lowering so a regression that silently stopped lowering a valid construct is caught. Each test was written by empirically observing current behavior first; the two-module test is a named characterization, not an endorsement. L6 gf16 SSOT untouched; catalog stays 83; no gen/ edits; ASCII-only added lines; no quality claim added. Closes #1130.
10+
- **Anchor**: phi^2 + phi^-2 = 3
11+
512
## loop9-s-hir-deadcode-slice -- per-enum allow(dead_code) for HIR/FPGA grammar enums (Closes #1129)
613

714
- **WHERE**: bootstrap/src/compiler.rs (HIR/FPGA grammar enums), scripts/warnings-baseline.sh.

0 commit comments

Comments
 (0)