use links_notation::{parse_lino, LiNo};
#[test]
fn test_is_ref() {
let reference = LiNo::Ref("some_value".to_string());
assert!(reference.is_ref());
assert!(!reference.is_link());
}
#[test]
fn test_is_link() {
let link = LiNo::Link {
id: Some("id".to_string()),
values: vec![LiNo::Ref("child".to_string())],
};
assert!(link.is_link());
assert!(!link.is_ref());
}
#[test]
fn test_is_ref_equivalent() {
let reference = LiNo::Ref("some_value".to_string());
assert!(reference.is_ref());
assert!(!reference.is_link());
}
#[test]
fn test_is_link_equivalent() {
let link = LiNo::Link {
id: Some("id".to_string()),
values: vec![LiNo::Ref("child".to_string())],
};
assert!(link.is_link());
assert!(!link.is_ref());
}
#[test]
fn test_empty_link() {
let link = LiNo::Link::<String> {
id: None,
values: vec![],
};
let output = link.to_string();
assert_eq!(output, "()");
}
#[test]
fn test_simple_link() {
let input = "(1: 1 1)";
let parsed = parse_lino(input).expect("Failed to parse input");
let output = parsed.to_string();
let expected = "((1: 1 1))"; assert_eq!(expected, output);
let output_alternate = format!("{:#}", parsed);
assert_eq!(input, output_alternate);
}
#[test]
fn test_link_with_source_target() {
let input = "(index: source target)";
let parsed = parse_lino(input).expect("Failed to parse input");
let output = parsed.to_string();
let expected = "((index: source target))"; assert_eq!(expected, output);
let output_alternate = format!("{:#}", parsed);
assert_eq!(input, output_alternate);
}
#[test]
fn test_link_with_source_type_target() {
let input = "(index: source type target)";
let parsed = parse_lino(input).expect("Failed to parse input");
let output = parsed.to_string();
let expected = "((index: source type target))"; assert_eq!(expected, output);
let output_alternate = format!("{:#}", parsed);
assert_eq!(input, output_alternate);
}
#[test]
fn test_single_line_format() {
let input = "id: value1 value2";
let parsed = parse_lino(input).expect("Failed to parse input");
let output = parsed.to_string();
assert!(output.contains("id") && output.contains("value1") && output.contains("value2"));
}
#[test]
fn test_quoted_references() {
let input = r#"("quoted id": "value with spaces")"#;
let parsed = parse_lino(input).expect("Failed to parse input");
let output = parsed.to_string();
assert!(output.contains("quoted id") && output.contains("value with spaces"));
}
#[test]
fn test_quoted_references_parsing() {
let input = r#"("quoted id": "value with spaces")"#;
let parsed = parse_lino(input).expect("Failed to parse input");
let output = format!("{}", parsed);
assert!(output.contains("quoted id"));
assert!(output.contains("value with spaces"));
}
#[test]
fn test_indented_id_syntax_parsing() {
use links_notation::{format_links, parse_lino_to_links};
let indented = "id:\n value1\n value2";
let inline = "(id: value1 value2)";
let indented_parsed = parse_lino_to_links(indented).expect("Failed to parse indented");
let inline_parsed = parse_lino_to_links(inline).expect("Failed to parse inline");
let indented_output = format_links(&indented_parsed);
let inline_output = format_links(&inline_parsed);
assert_eq!(indented_output, inline_output);
assert_eq!(indented_output, "(id: value1 value2)");
}
#[test]
fn test_multiple_indented_id_syntax_parsing() {
use links_notation::{format_links, parse_lino_to_links};
let indented = "id1:\n a\n b\nid2:\n c\n d";
let inline = "(id1: a b)\n(id2: c d)";
let indented_parsed = parse_lino_to_links(indented).expect("Failed to parse indented");
let inline_parsed = parse_lino_to_links(inline).expect("Failed to parse inline");
let indented_output = format_links(&indented_parsed);
let inline_output = format_links(&inline_parsed);
assert_eq!(indented_output, inline_output);
assert_eq!(indented_output, "(id1: a b)\n(id2: c d)");
}
#[test]
fn test_indented_id_syntax_roundtrip() {
use links_notation::{format_config::FormatConfig, parse_lino_to_links};
let indented = "id:\n value1\n value2";
let parsed = parse_lino_to_links(indented).expect("Failed to parse indented");
let config = FormatConfig::builder()
.max_inline_refs(Some(1)) .prefer_inline(false)
.build();
assert!(!parsed.is_empty());
assert_eq!(config.max_inline_refs, Some(1));
assert!(!config.prefer_inline);
assert!(config.should_indent_by_ref_count(2));
}
#[test]
fn test_multiple_indented_id_syntax_roundtrip() {
use links_notation::{format_config::FormatConfig, parse_lino_to_links};
let indented = "id1:\n a\n b\nid2:\n c\n d";
let parsed = parse_lino_to_links(indented).expect("Failed to parse indented");
let config = FormatConfig::builder()
.max_inline_refs(Some(1)) .prefer_inline(false)
.build();
assert!(parsed.len() >= 2);
assert_eq!(config.max_inline_refs, Some(1));
assert!(!config.prefer_inline);
assert!(config.should_indent_by_ref_count(2));
}