Skip to content

Commit 2046c85

Browse files
AI Issue Solverclaude
andcommitted
Move macro unit tests to separate file
- Move tests from lib.rs to tests.rs in links-notation-macro crate - Mark doc examples as `ignore` since they reference links_notation which can't be a dependency of a proc-macro crate - Keep test logic and implementation logic in separate files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 295c31f commit 2046c85

File tree

2 files changed

+78
-72
lines changed

2 files changed

+78
-72
lines changed

rust/links-notation-macro/src/lib.rs

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syn::{parse::Parse, parse::ParseStream, LitStr};
1717
///
1818
/// Write Links Notation directly without quotes:
1919
///
20-
/// ```rust
20+
/// ```rust,ignore
2121
/// use links_notation::lino;
2222
///
2323
/// let result = lino!(papa (lovesMama: loves mama));
@@ -29,7 +29,7 @@ use syn::{parse::Parse, parse::ParseStream, LitStr};
2929
///
3030
/// Use string literals for complex cases with special characters:
3131
///
32-
/// ```rust
32+
/// ```rust,ignore
3333
/// use links_notation::lino;
3434
///
3535
/// let result = lino!("papa (lovesMama: loves mama)");
@@ -39,7 +39,7 @@ use syn::{parse::Parse, parse::ParseStream, LitStr};
3939
///
4040
/// # Examples
4141
///
42-
/// ```rust
42+
/// ```rust,ignore
4343
/// use links_notation::lino;
4444
///
4545
/// // Direct syntax - cleaner and more native
@@ -333,73 +333,6 @@ fn validate_lino_syntax(input: &str) -> Result<(), String> {
333333
Ok(())
334334
}
335335

336+
// Unit tests are in a separate file: tests.rs
336337
#[cfg(test)]
337-
mod tests {
338-
use super::*;
339-
340-
#[test]
341-
fn test_validate_balanced_parens() {
342-
assert!(validate_lino_syntax("(a b c)").is_ok());
343-
assert!(validate_lino_syntax("((a) (b))").is_ok());
344-
assert!(validate_lino_syntax("a b c").is_ok());
345-
}
346-
347-
#[test]
348-
fn test_validate_unbalanced_parens() {
349-
assert!(validate_lino_syntax("(a b c").is_err());
350-
assert!(validate_lino_syntax("a b c)").is_err());
351-
assert!(validate_lino_syntax("((a) (b)").is_err());
352-
}
353-
354-
#[test]
355-
fn test_validate_quotes() {
356-
assert!(validate_lino_syntax(r#"("quoted" value)"#).is_ok());
357-
assert!(validate_lino_syntax("('quoted' value)").is_ok());
358-
assert!(validate_lino_syntax(r#"("unclosed)"#).is_err());
359-
assert!(validate_lino_syntax("('unclosed)").is_err());
360-
}
361-
362-
#[test]
363-
fn test_validate_nested_quotes() {
364-
assert!(validate_lino_syntax(r#"("string with (parens)" value)"#).is_ok());
365-
}
366-
367-
#[test]
368-
fn test_validate_empty() {
369-
assert!(validate_lino_syntax("").is_ok());
370-
assert!(validate_lino_syntax(" ").is_ok());
371-
}
372-
373-
#[test]
374-
fn test_tokens_to_lino_basic() {
375-
// Test basic token conversion
376-
let tokens: proc_macro2::TokenStream = "papa has car".parse().unwrap();
377-
let mut output = String::new();
378-
tokens_to_lino_string(tokens, &mut output);
379-
assert_eq!(output, "papa has car");
380-
}
381-
382-
#[test]
383-
fn test_tokens_to_lino_with_parens() {
384-
let tokens: proc_macro2::TokenStream = "papa (loves mama)".parse().unwrap();
385-
let mut output = String::new();
386-
tokens_to_lino_string(tokens, &mut output);
387-
assert_eq!(output, "papa (loves mama)");
388-
}
389-
390-
#[test]
391-
fn test_tokens_to_lino_with_colon() {
392-
let tokens: proc_macro2::TokenStream = "(lovesMama: loves mama)".parse().unwrap();
393-
let mut output = String::new();
394-
tokens_to_lino_string(tokens, &mut output);
395-
assert_eq!(output, "(lovesMama: loves mama)");
396-
}
397-
398-
#[test]
399-
fn test_tokens_to_lino_nested() {
400-
let tokens: proc_macro2::TokenStream = "(outer (inner value))".parse().unwrap();
401-
let mut output = String::new();
402-
tokens_to_lino_string(tokens, &mut output);
403-
assert_eq!(output, "(outer (inner value))");
404-
}
405-
}
338+
mod tests;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//! Unit tests for the links-notation-macro internal functions.
2+
//!
3+
//! These tests validate the internal helper functions:
4+
//! - `validate_lino_syntax`: Basic syntax validation
5+
//! - `tokens_to_lino_string`: Token to string conversion
6+
7+
use super::*;
8+
9+
#[test]
10+
fn test_validate_balanced_parens() {
11+
assert!(validate_lino_syntax("(a b c)").is_ok());
12+
assert!(validate_lino_syntax("((a) (b))").is_ok());
13+
assert!(validate_lino_syntax("a b c").is_ok());
14+
}
15+
16+
#[test]
17+
fn test_validate_unbalanced_parens() {
18+
assert!(validate_lino_syntax("(a b c").is_err());
19+
assert!(validate_lino_syntax("a b c)").is_err());
20+
assert!(validate_lino_syntax("((a) (b)").is_err());
21+
}
22+
23+
#[test]
24+
fn test_validate_quotes() {
25+
assert!(validate_lino_syntax(r#"("quoted" value)"#).is_ok());
26+
assert!(validate_lino_syntax("('quoted' value)").is_ok());
27+
assert!(validate_lino_syntax(r#"("unclosed)"#).is_err());
28+
assert!(validate_lino_syntax("('unclosed)").is_err());
29+
}
30+
31+
#[test]
32+
fn test_validate_nested_quotes() {
33+
assert!(validate_lino_syntax(r#"("string with (parens)" value)"#).is_ok());
34+
}
35+
36+
#[test]
37+
fn test_validate_empty() {
38+
assert!(validate_lino_syntax("").is_ok());
39+
assert!(validate_lino_syntax(" ").is_ok());
40+
}
41+
42+
#[test]
43+
fn test_tokens_to_lino_basic() {
44+
// Test basic token conversion
45+
let tokens: proc_macro2::TokenStream = "papa has car".parse().unwrap();
46+
let mut output = String::new();
47+
tokens_to_lino_string(tokens, &mut output);
48+
assert_eq!(output, "papa has car");
49+
}
50+
51+
#[test]
52+
fn test_tokens_to_lino_with_parens() {
53+
let tokens: proc_macro2::TokenStream = "papa (loves mama)".parse().unwrap();
54+
let mut output = String::new();
55+
tokens_to_lino_string(tokens, &mut output);
56+
assert_eq!(output, "papa (loves mama)");
57+
}
58+
59+
#[test]
60+
fn test_tokens_to_lino_with_colon() {
61+
let tokens: proc_macro2::TokenStream = "(lovesMama: loves mama)".parse().unwrap();
62+
let mut output = String::new();
63+
tokens_to_lino_string(tokens, &mut output);
64+
assert_eq!(output, "(lovesMama: loves mama)");
65+
}
66+
67+
#[test]
68+
fn test_tokens_to_lino_nested() {
69+
let tokens: proc_macro2::TokenStream = "(outer (inner value))".parse().unwrap();
70+
let mut output = String::new();
71+
tokens_to_lino_string(tokens, &mut output);
72+
assert_eq!(output, "(outer (inner value))");
73+
}

0 commit comments

Comments
 (0)