aboutsummaryrefslogtreecommitdiff
path: root/macros/src/tests/single.rs
blob: f20c9ccbb3a635538b2d0255dd11b5d2f871acb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use quote::quote;
use rtic_syntax::Settings;

#[test]
fn analyze() {
    let mut settings = Settings::default();
    settings.parse_extern_interrupt = true;
    let (app, analysis) = rtic_syntax::parse2(
        // First interrupt is assigned to the highest priority dispatcher
        quote!(device = pac, dispatchers = [B, A]),
        quote!(
            mod app {
                #[shared]
                struct Shared {}

                #[local]
                struct Local {}

                #[init]
                fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
                    (Shared {}, Local {}, init::Monotonics())
                }

                #[task(priority = 1)]
                fn a(_: a::Context) {}

                #[task(priority = 2)]
                fn b(_: b::Context) {}
            }
        ),
        settings,
    )
    .unwrap();

    let analysis = crate::analyze::app(analysis, &app);
    let interrupts = &analysis.interrupts;
    assert_eq!(interrupts.len(), 2);
    assert_eq!(interrupts[&2].0.to_string(), "B");
    assert_eq!(interrupts[&1].0.to_string(), "A");
}