Skip to content

Commit

Permalink
test(doc): added test case for doc comments & natspec (#9923)
Browse files Browse the repository at this point in the history
test(doc): added testcase for doc comments & natspec
  • Loading branch information
srdtrk authored Feb 28, 2025
1 parent 86422ee commit ee562e8
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion crates/doc/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,45 @@ mod tests {
assert!(matches!(fallback.source, ParseSource::Function(_)));
}

// TODO: test regular doc comments & natspec
#[test]
fn contract_with_doc_comments() {
let items = parse_source(
r"
pragma solidity ^0.8.19;
/// @name Test
/// no tag
///@notice Cool contract
/// @ dev This is not a dev tag
/**
* @dev line one
* line 2
*/
contract Test {
/*** my function
i like whitespace
*/
function test() {}
}
",
);

assert_eq!(items.len(), 1);

let contract = items.first().unwrap();
assert_eq!(contract.comments.len(), 2);
assert_eq!(
*contract.comments.first().unwrap(),
Comment::new(CommentTag::Notice, "Cool contract".to_owned())
);
assert_eq!(
*contract.comments.get(1).unwrap(),
Comment::new(CommentTag::Dev, "line one\nline 2".to_owned())
);

let function = contract.children.first().unwrap();
assert_eq!(
*function.comments.first().unwrap(),
Comment::new(CommentTag::Notice, "my function\ni like whitespace".to_owned())
);
}
}

0 comments on commit ee562e8

Please sign in to comment.