File: extern_class.rs

package info (click to toggle)
firefox 148.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,719,656 kB
  • sloc: cpp: 7,618,171; javascript: 6,701,506; ansic: 3,781,787; python: 1,418,364; xml: 638,647; asm: 438,962; java: 186,285; sh: 62,885; makefile: 19,010; objc: 13,092; perl: 12,763; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (58 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use objc2::{extern_class, ClassType};
use objc2_foundation::NSObject;
use static_assertions::assert_impl_all;

#[test]
fn allow_deprecated() {
    #![deny(deprecated)]

    // Test allow propagates to impls
    extern_class!(
        #[unsafe(super(NSObject))]
        #[deprecated]
        #[allow(deprecated)]
        struct AllowDeprecated;
    );
}

#[test]
fn cfg() {
    // Test `cfg`. We use `debug_assertions` here because it's something that we
    // know our CI already tests.

    extern_class!(
        #[unsafe(super(NSObject))]
        #[cfg(debug_assertions)]
        #[name = "NSObject"]
        struct OnlyOnDebugAssertions;
    );

    #[cfg(debug_assertions)]
    let _ = OnlyOnDebugAssertions::class();

    extern_class!(
        #[unsafe(super(NSObject))]
        #[cfg(not(debug_assertions))]
        #[name = "NSObject"]
        struct NeverOnDebugAssertions;
    );

    #[cfg(not(debug_assertions))]
    let _ = NeverOnDebugAssertions::class();
}

#[test]
fn derive() {
    extern_class!(
        #[rustfmt::skip]
        #[unsafe(super(NSObject))]
        #[derive(PartialEq)]
        #[derive()]
        #[derive(Eq,)]
        #[derive()]
        #[derive(Debug, Hash,)]
        struct Derive;
    );

    assert_impl_all!(Derive: PartialEq, Eq, core::hash::Hash, core::fmt::Debug);
}