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

vcfxb / wright-lang / 15061769677

16 May 2025 06:02AM UTC coverage: 75.523% (+0.7%) from 74.809%
15061769677

push

github

vcfxb
chore: cargo fmt

6 of 13 new or added lines in 4 files covered. (46.15%)

27 existing lines in 2 files now uncovered.

938 of 1242 relevant lines covered (75.52%)

29.83 hits per line

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

92.31
/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
        whitespace,
10
    },
11
    source_tracking::fragment::Fragment,
12
};
13

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

26
        whitespace::optional_whitespace(parser);
3✔
27

28
        let referenced_type = Type::parse(parser)?;
3✔
29

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

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

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

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

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

62
        assert_eq!(result.matching_source.as_str(), "@@u64");
1✔
63
        assert!(result.target_ty.downcast_reference().is_some());
1✔
64
    }
1✔
65
}
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