on master help sign in
Update tests for unified @let directive

Migrate all test cases from old @fn, @define, @mixin syntax to new @let directive. Update warning message assertions to match new diagnostic names (unused attribute bundle). Regenerate snapshot HTML files with updated CSS.

commitbf43689c15ddf113003ccdaa26e658a5792526a3 authoriko <mail@iko.soy> dateSun 26 Apr 2026, 18:10 (5 months ago) parentbe4fcdc
1 file changed+39−31
tests/snapshots.rs+39−31
tests/snapshots.rs+39−31
@@ -257,7 +257,7 @@ fn error_unclosed_bracket() {
257257
258258#[test]
259259fn error_recursive_function() {
260− let input = "@fn loop\n @loop\n@loop";
260+ let input = "@let loop\n @loop\n@loop";
261261 let diags = parse_diagnostics(input);
262262 assert!(
263263 diags
@@ -348,13 +348,13 @@ fn else_if_chain() {
348348
349349#[test]
350350fn fn_default_used() {
351− let output = compile("@fn test $x=hello\n @text $x\n@test");
351+ let output = compile("@let test $x=hello\n @text $x\n@test");
352352 assert!(output.contains("hello"));
353353}
354354
355355#[test]
356356fn fn_default_overridden() {
357− let output = compile("@fn test $x=hello\n @text $x\n@test [x world]");
357+ let output = compile("@let test $x=hello\n @text $x\n@test [x world]");
358358 assert!(output.contains("world"));
359359 assert!(!output.contains("hello"));
360360}
@@ -446,7 +446,7 @@ fn no_warning_used_variable() {
446446
447447#[test]
448448fn warning_unused_function() {
449− let diags = parse_diagnostics("@fn card\n @el [padding 10]\n@el");
449+ let diags = parse_diagnostics("@let card\n @el [padding 10]\n@el");
450450 assert!(
451451 diags
452452 .iter()
@@ -458,7 +458,7 @@ fn warning_unused_function() {
458458
459459#[test]
460460fn no_warning_used_function() {
461− let diags = parse_diagnostics("@fn card\n @el [padding 10]\n@card");
461+ let diags = parse_diagnostics("@let card\n @el [padding 10]\n@card");
462462 assert!(
463463 !diags.iter().any(|d| d.message.contains("unused function")),
464464 "should not warn about used function, got: {:?}",
@@ -468,19 +468,23 @@ fn no_warning_used_function() {
468468
469469#[test]
470470fn warning_unused_define() {
471− let diags = parse_diagnostics("@define card-style [padding 10]\n@el");
471+ let diags = parse_diagnostics("@let card-style [padding 10]\n@el");
472472 assert!(
473− diags.iter().any(|d| d.message.contains("unused define")),
474− "expected unused define warning, got: {:?}",
473+ diags
474+ .iter()
475+ .any(|d| d.message.contains("unused attribute bundle")),
476+ "expected unused attribute bundle warning, got: {:?}",
475477 diags
476478 );
477479}
478480
479481#[test]
480482fn no_warning_used_define() {
481− let diags = parse_diagnostics("@define card-style [padding 10]\n@el [$card-style]");
483+ let diags = parse_diagnostics("@let card-style [padding 10]\n@el [$card-style]");
482484 assert!(
483− !diags.iter().any(|d| d.message.contains("unused define")),
485+ !diags
486+ .iter()
487+ .any(|d| d.message.contains("unused attribute bundle")),
484488 "should not warn about used define, got: {:?}",
485489 diags
486490 );
@@ -559,7 +563,7 @@ fn each_range_with_index() {
559563#[test]
560564fn named_slot_basic() {
561565 let output = compile(
562− "@fn card\n @el\n @slot header\n @children\n@card\n @slot header\n @text Title\n @text Body",
566+ "@let card\n @el\n @slot header\n @children\n@card\n @slot header\n @text Title\n @text Body",
563567 );
564568 assert!(output.contains("Title"));
565569 assert!(output.contains("Body"));
@@ -568,7 +572,7 @@ fn named_slot_basic() {
568572#[test]
569573fn named_slot_default_content() {
570574 let output = compile(
571− "@fn card\n @el\n @slot header\n @text Default\n @children\n@card\n @text Body",
575+ "@let card\n @el\n @slot header\n @text Default\n @children\n@card\n @text Body",
572576 );
573577 assert!(output.contains("Default"));
574578 assert!(output.contains("Body"));
@@ -3094,7 +3098,7 @@ fn test_theme_directive() {
30943098#[test]
30953099fn test_deprecated_fn() {
30963100 let result = htmlang::parser::parse(
3097− "@deprecated Use @new-card instead\n@fn old-card $title\n @text $title\n\n@old-card [title Hello]",
3101+ "@deprecated Use @new-card instead\n@let old-card $title\n @text $title\n\n@old-card [title Hello]",
30983102 );
30993103 let warnings: Vec<_> = result
31003104 .diagnostics
@@ -3214,7 +3218,7 @@ fn test_autofocus_attribute() {
32143218fn test_repl_components_feed_subcommands_recognized() {
32153219 // Just verify that the parser and codegen work for content that these commands would process
32163220 let result = htmlang::parser::parse(
3217− "@page Test Site\n@meta description A test\n@fn card $title\n @text $title",
3221+ "@page Test Site\n@meta description A test\n@let card $title\n @text $title",
32183222 );
32193223 assert!(
32203224 !result
@@ -3357,12 +3361,12 @@ fn output_contains_layer_wrapping() {
33573361 );
33583362}
33593363
3360−// --- Named slots in @fn assertions ---
3364+// --- Named slots in @let assertions ---
33613365
33623366#[test]
33633367fn fn_named_slots() {
33643368 let output = compile(
3365− "@fn layout\n @column\n @slot header\n Default Header\n @slot content\n@layout\n @slot header\n Custom Header\n @slot content\n Page body",
3369+ "@let layout\n @column\n @slot header\n Default Header\n @slot content\n@layout\n @slot header\n Custom Header\n @slot content\n Page body",
33663370 );
33673371 assert!(
33683372 output.contains("Custom Header"),
@@ -3384,7 +3388,7 @@ fn fn_named_slots() {
33843388#[test]
33853389fn fn_named_slot_default() {
33863390 let output = compile(
3387− "@fn layout\n @column\n @slot header\n Default Header\n @slot content\n@layout\n @slot content\n Only content",
3391+ "@let layout\n @column\n @slot header\n Default Header\n @slot content\n@layout\n @slot content\n Only content",
33883392 );
33893393 assert!(
33903394 output.contains("Default Header"),
@@ -3628,7 +3632,7 @@ fn no_warning_script_attrs() {
36283632}
36293633
36303634// ---------------------------------------------------------------------------
3631−// @mixin and spread attributes
3635+// @let attribute bundles (spread attributes)
36323636// ---------------------------------------------------------------------------
36333637
36343638#[test]
@@ -3638,7 +3642,7 @@ fn snapshot_mixin_spread() {
36383642
36393643#[test]
36403644fn mixin_expands_in_attrs() {
3641− let output = compile("@mixin card [padding 20, rounded 8]\n@el [...$card]\n Hi");
3645+ let output = compile("@let card [padding 20, rounded 8]\n@el [...$card]\n Hi");
36423646 assert!(
36433647 output.contains("padding:20px"),
36443648 "mixin should expand padding: {}",
@@ -3653,7 +3657,7 @@ fn mixin_expands_in_attrs() {
36533657
36543658#[test]
36553659fn mixin_with_dollar_syntax() {
3656− let output = compile("@mixin card [padding 20, rounded 8]\n@el [$card]\n Hi");
3660+ let output = compile("@let card [padding 20, rounded 8]\n@el [$card]\n Hi");
36573661 assert!(
36583662 output.contains("padding:20px"),
36593663 "mixin with $ syntax should expand: {}",
@@ -3663,7 +3667,7 @@ fn mixin_with_dollar_syntax() {
36633667
36643668#[test]
36653669fn mixin_compose_with_extra_attrs() {
3666− let output = compile("@mixin base [padding 10]\n@el [...$base, background red]\n Hi");
3670+ let output = compile("@let base [padding 10]\n@el [...$base, background red]\n Hi");
36673671 assert!(
36683672 output.contains("padding:10px"),
36693673 "mixin should expand: {}",
@@ -3678,19 +3682,23 @@ fn mixin_compose_with_extra_attrs() {
36783682
36793683#[test]
36803684fn warning_unused_mixin() {
3681− let diags = parse_diagnostics("@mixin card [padding 10]\n@el [background red]");
3685+ let diags = parse_diagnostics("@let card [padding 10]\n@el [background red]");
36823686 assert!(
3683− diags.iter().any(|d| d.message.contains("unused mixin")),
3684− "expected unused mixin warning, got: {:?}",
3687+ diags
3688+ .iter()
3689+ .any(|d| d.message.contains("unused attribute bundle")),
3690+ "expected unused attribute bundle warning, got: {:?}",
36853691 diags
36863692 );
36873693}
36883694
36893695#[test]
36903696fn no_warning_used_mixin() {
3691− let diags = parse_diagnostics("@mixin card [padding 10]\n@el [...$card]");
3697+ let diags = parse_diagnostics("@let card [padding 10]\n@el [...$card]");
36923698 assert!(
3693− !diags.iter().any(|d| d.message.contains("unused mixin")),
3699+ !diags
3700+ .iter()
3701+ .any(|d| d.message.contains("unused attribute bundle")),
36943702 "should not warn about used mixin, got: {:?}",
36953703 diags
36963704 );
@@ -4182,7 +4190,7 @@ fn test_error_for_missing_range() {
41824190fn test_error_circular_include() {
41834191 // A file including itself would be circular, but we test via in-memory parse
41844192 // by testing that the parser detects self-referential definitions
4185− let diags = parse_diagnostics("@fn recursive $x\n @recursive [$x]\n\n@recursive [hello]");
4193+ let diags = parse_diagnostics("@let recursive $x\n @recursive [$x]\n\n@recursive [hello]");
41864194 assert!(
41874195 diags.iter().any(|d| d.message.contains("recursive")),
41884196 "should report recursive function call"
@@ -4222,7 +4230,7 @@ fn test_warning_unused_variable() {
42224230
42234231#[test]
42244232fn test_warning_unused_function() {
4225− let diags = parse_diagnostics("@fn unused_fn\n @text Hello\n\n@text World");
4233+ let diags = parse_diagnostics("@let unused_fn\n @text Hello\n\n@text World");
42264234 assert!(
42274235 diags.iter().any(|d| d.message.contains("unused function")
42284236 && d.severity == htmlang::parser::Severity::Warning),
@@ -4245,7 +4253,7 @@ fn test_each_index_variable() {
42454253#[test]
42464254fn test_children_fallback_content() {
42474255 let html = compile(
4248− "@fn wrapper\n @el [padding 10]\n @children\n @text Default content\n\n@wrapper",
4256+ "@let wrapper\n @el [padding 10]\n @children\n @text Default content\n\n@wrapper",
42494257 );
42504258 assert!(
42514259 html.contains("Default content"),
@@ -4255,7 +4263,7 @@ fn test_children_fallback_content() {
42554263
42564264#[test]
42574265fn test_spread_define() {
4258− let html = compile("@define btn [padding 12, bold]\n@el [...$btn]\n Click");
4266+ let html = compile("@let btn [padding 12, bold]\n@el [...$btn]\n Click");
42594267 assert!(
42604268 html.contains("padding:12px"),
42614269 "spread define should apply padding"
@@ -5053,7 +5061,7 @@ fn import_with_alias_prefixes_definitions() {
50535061 let _ = std::fs::remove_dir_all(&dir);
50545062 std::fs::create_dir_all(&dir).unwrap();
50555063 let lib_path = dir.join("lib.hl");
5056− std::fs::write(&lib_path, "@fn card\n @el\n @text card-body\n").unwrap();
5064+ std::fs::write(&lib_path, "@let card\n @el\n @text card-body\n").unwrap();
50575065
50585066 let input = "@import lib.hl as ui\n@ui.card\n";
50595067 let result = htmlang::parser::parse_with_base(input, Some(&dir));