Skip to main content

shape_vm/feature_tests/
annotation_tests.rs

1//! Tests for annotation features
2//!
3//! This module covers annotation grammar rules from shape.pest:
4//! - annotation: `@my_ann`
5//! - annotation_args: `@timeout(5000)`
6//! - annotation_def: `annotation @custom(x) { }`
7
8use super::{FeatureCategory, FeatureTest};
9
10pub const TESTS: &[FeatureTest] = &[
11    // === Basic Annotations ===
12    FeatureTest {
13        name: "annotation_simple",
14        covers: &["annotation", "annotation_name", "annotations"],
15        code: r#"annotation test_ann() {} @test_ann function test() { return 42; }"#,
16        function: "test",
17        category: FeatureCategory::Function,
18        requires_data: false,
19    },
20    FeatureTest {
21        name: "annotation_with_args",
22        covers: &["annotation", "annotation_args", "annotation_name"],
23        code: r#"annotation timeout(ms) {} @timeout(5000) function test() { return 42; }"#,
24        function: "test",
25        category: FeatureCategory::Function,
26        requires_data: false,
27    },
28    FeatureTest {
29        name: "annotation_multiple_args",
30        covers: &["annotation", "annotation_args"],
31        code: r#"annotation config(name, value) {} @config("option1", 100) function test() { return 42; }"#,
32        function: "test",
33        category: FeatureCategory::Function,
34        requires_data: false,
35    },
36    FeatureTest {
37        name: "annotation_multiple",
38        covers: &["annotations", "annotation"],
39        code: r#"annotation ann_a() {} annotation ann_b() {} @ann_a @ann_b function test() { return 42; }"#,
40        function: "test",
41        category: FeatureCategory::Function,
42        requires_data: false,
43    },
44    // === Annotation Definitions ===
45    FeatureTest {
46        name: "annotation_def_simple",
47        covers: &["annotation_def", "annotation_def_params"],
48        code: r#"
49            annotation warmup(amount) {
50                return amount;
51            }
52            function test() { return 42; }
53        "#,
54        function: "test",
55        category: FeatureCategory::Module,
56        requires_data: false,
57    },
58    FeatureTest {
59        name: "annotation_def_multiple_params",
60        covers: &["annotation_def", "annotation_def_params"],
61        code: r#"
62            annotation range(min, max) {
63                return min + max;
64            }
65            function test() { return 42; }
66        "#,
67        function: "test",
68        category: FeatureCategory::Module,
69        requires_data: false,
70    },
71    FeatureTest {
72        name: "annotation_def_no_params",
73        covers: &["annotation_def"],
74        code: r#"
75            annotation memoize() {
76                return null;
77            }
78            function test() { return 42; }
79        "#,
80        function: "test",
81        category: FeatureCategory::Module,
82        requires_data: false,
83    },
84];
85
86#[cfg(test)]
87mod tests {
88    use super::*;
89    use std::collections::HashSet;
90
91    #[test]
92    fn test_annotation_tests_defined() {
93        assert!(!TESTS.is_empty());
94        // Verify all tests have unique names
95        let names: HashSet<_> = TESTS.iter().map(|t| t.name).collect();
96        assert_eq!(names.len(), TESTS.len(), "All test names should be unique");
97    }
98
99    #[test]
100    fn test_covers_annotation_rules() {
101        let all_covered: HashSet<_> = TESTS.iter().flat_map(|t| t.covers.iter()).collect();
102        // Check that key annotation rules are covered
103        assert!(
104            all_covered.contains(&"annotation"),
105            "Should cover 'annotation' rule"
106        );
107        assert!(
108            all_covered.contains(&"annotation_args"),
109            "Should cover 'annotation_args' rule"
110        );
111        assert!(
112            all_covered.contains(&"annotation_def"),
113            "Should cover 'annotation_def' rule"
114        );
115    }
116}