• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vcfxb / wright-lang / 16336579506

17 Jul 2025 04:57AM UTC coverage: 75.6% (+0.2%) from 75.352%
16336579506

push

github

vcfxb
chore: clippy

0 of 1 new or added line in 1 file covered. (0.0%)

32 existing lines in 5 files now uncovered.

976 of 1291 relevant lines covered (75.6%)

35.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/wright/src/parser/ty/reference.rs
1
//! Referenced types. Types that are defined by users or in the standard library.
2

3
use crate::{
4
    ast::ty::{ReferenceTy, Type},
5
    lexer::token::TokenTy,
6
    parser::{
7
        Parser,
8
        error::{ParserError, ParserErrorKind},
9
    },
10
    source_tracking::fragment::Fragment,
11
};
12

13
impl ReferenceTy {
14
    /// Attempt to parse a reference type signature, i.e. `@u64`.
15
    ///
16
    /// This will leave the parser unmodified and return an error if it doesn't match the `@` symbol, however
17
    /// if it does match the `@` symbol it will advance the parser and then may still return an error if the
18
    /// `@` symbol is not followed by a type signature.
19
    pub fn parse(parser: &mut Parser) -> Result<Self, ParserError> {
6✔
20
        let Some(at_symbol) = parser.next_if_is(TokenTy::At) else {
6✔
UNCOV
21
            return Err(ParserErrorKind::ExpectedReferenceTypeSignature
×
22
                .at(parser.peek_fragment_or_rest_cloned()));
×
23
        };
24

25
        parser.consume_optional_whitespace();
6✔
26

27
        let referenced_type = Type::parse(parser)?;
6✔
28

29
        Ok(ReferenceTy {
6✔
30
            matching_source: Fragment::cover(
6✔
31
                &at_symbol.fragment,
6✔
32
                referenced_type.matching_source(),
6✔
33
            ),
6✔
34
            target_ty: Box::new(referenced_type),
6✔
35
        })
6✔
36
    }
6✔
37
}
38

39
#[cfg(test)]
40
mod tests {
41
    use crate::{
42
        ast::ty::{AtomicTyVariant, ReferenceTy},
43
        lexer::Lexer,
44
        parser::Parser,
45
    };
46

47
    #[test]
48
    fn test_reference_to_atomic() {
1✔
49
        let mut parser = Parser::new(Lexer::new_test("@u64"));
1✔
50
        let result = ReferenceTy::parse(&mut parser).unwrap();
1✔
51

52
        assert_eq!(result.matching_source.as_str(), "@u64");
1✔
53
        assert_eq!(result.target_ty.downcast_primitive().unwrap().variant, AtomicTyVariant::U64);
1✔
54
    }
1✔
55

56
    #[test]
57
    fn test_reference_to_a_reference_to_atomic() {
1✔
58
        let mut parser = Parser::new(Lexer::new_test("@@u64"));
1✔
59
        let result = ReferenceTy::parse(&mut parser).unwrap();
1✔
60

61
        assert_eq!(result.matching_source.as_str(), "@@u64");
1✔
62
        assert!(result.target_ty.downcast_reference().is_some());
1✔
63
    }
1✔
64

65
    #[test]
66
    fn test_u8_ref() {
1✔
67
        let mut parser = Parser::new(Lexer::new_test("@u8"));
1✔
68
        let ref_ty = ReferenceTy::parse(&mut parser).unwrap();
1✔
69
        assert_eq!(ref_ty.matching_source.len(), 3);
1✔
70
        assert_eq!(ref_ty.target_ty.downcast_primitive().unwrap().variant, AtomicTyVariant::U8);
1✔
71
    }
1✔
72

73
    #[test]
74
    fn test_nested_ref() {
1✔
75
        let mut parser = Parser::new(Lexer::new_test("@@u8"));
1✔
76
        let ref_ty = ReferenceTy::parse(&mut parser).unwrap();
1✔
77
        assert_eq!(ref_ty.matching_source.len(), 4);
1✔
78
        let inner_ref = ref_ty.target_ty.downcast_reference().unwrap();
1✔
79
        assert_eq!(inner_ref.matching_source.len(), 3);
1✔
80
        assert_eq!(inner_ref.target_ty.downcast_primitive().unwrap().variant, AtomicTyVariant::U8);
1✔
81
    }
1✔
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc