Skip to content

Commit ab0373f

Browse files
committed
KCL: Add unit tests for cleanup_type_string
1 parent 8ca76e8 commit ab0373f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

rust/kcl-lib/src/docs/gen_std_tests.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,53 @@ async fn run_example(text: &str) -> Result<()> {
650650
ctx.run(&program, &mut exec_state).await?;
651651
Ok(())
652652
}
653+
654+
#[cfg(test)]
655+
mod tests {
656+
use super::*;
657+
658+
#[test]
659+
fn test_cleanup_type_string() {
660+
let kcl_std = crate::docs::kcl_doc::walk_prelude();
661+
662+
struct Test {
663+
input: &'static str,
664+
expected_text: &'static str,
665+
expected_no_text: &'static str,
666+
}
667+
668+
let tests = [
669+
Test {
670+
input: "v",
671+
expected_text: "`v`",
672+
expected_no_text: "v",
673+
},
674+
Test {
675+
input: "number(mm)",
676+
expected_text: "[`number(mm)`](/docs/kcl-std/types/std-types-number)",
677+
expected_no_text: "number(mm)",
678+
},
679+
Test {
680+
input: "number(mm) | string",
681+
expected_text: "[`number(mm)`](/docs/kcl-std/types/std-types-number) or [`string`](/docs/kcl-std/types/std-types-string)",
682+
expected_no_text: "number(mm) | string",
683+
},
684+
Test {
685+
input: "[string; 1+]",
686+
expected_text: "[`[string; 1+]`](/docs/kcl-std/types/std-types-string)",
687+
expected_no_text: "[string; 1+]",
688+
},
689+
Test {
690+
input: "[string; 1+] | number(mm)",
691+
expected_text: "[`[string; 1+]`](/docs/kcl-std/types/std-types-string) or [`number(mm)`](/docs/kcl-std/types/std-types-number)",
692+
expected_no_text: "[string; 1+] | number(mm)",
693+
},
694+
];
695+
for test in tests {
696+
let actual_text = cleanup_type_string(test.input, true, &kcl_std);
697+
assert_eq!(actual_text, test.expected_text);
698+
let actual_no_text = cleanup_type_string(test.input, false, &kcl_std);
699+
assert_eq!(actual_no_text, test.expected_no_text);
700+
}
701+
}
702+
}

0 commit comments

Comments
 (0)