1 use full_moon::{node::Node, parse};
2 
3 #[test]
surrounding_trivia()4 fn surrounding_trivia() {
5     let ast = parse(include_str!("cases/pass/local-assignment-5/source.lua")).unwrap();
6     let stmt = ast.nodes().stmts().nth(1);
7 
8     let (prev, _) = stmt.surrounding_trivia();
9 
10     let mut prev = prev.into_iter();
11     assert_eq!(prev.next().unwrap().to_string(), "-- Then a comment");
12     assert_eq!(prev.next().unwrap().to_string(), "\n");
13     assert_eq!(prev.next(), None);
14 }
15 
16 #[test]
test_similar()17 fn test_similar() {
18     let ast = parse("local x = 1; --[[ uh oh, filler ]] local x = 1; local x = 2;").unwrap();
19     let stmts = ast.nodes().stmts().collect::<Vec<_>>();
20 
21     assert!(stmts[0].similar(stmts[1]));
22     assert!(stmts[1].similar(stmts[0]));
23     assert!(!stmts[0].similar(stmts[2]));
24 }
25 
26 #[test]
test_tokens_collect()27 fn test_tokens_collect() {
28     let source = parse("local abcd = 1").unwrap();
29     let tokens = source.nodes().tokens().collect::<Vec<_>>();
30     assert_eq!(tokens.len(), 4);
31 }
32 
33 #[test]
test_tokens_back()34 fn test_tokens_back() {
35     let source = parse("local abcd = 1").unwrap();
36     let mut tokens = source.nodes().tokens();
37     assert_eq!(tokens.next_back().unwrap().to_string(), "1");
38 }
39