diff --git a/crates/plotnik-cli/src/commands/langs.rs b/crates/plotnik-cli/src/commands/langs.rs index ab2680a0..608f2377 100644 --- a/crates/plotnik-cli/src/commands/langs.rs +++ b/crates/plotnik-cli/src/commands/langs.rs @@ -5,211 +5,3 @@ pub fn run() { println!(" {}", lang.name()); } } - -#[cfg(test)] -mod tests { - use plotnik_langs::Lang; - - fn smoke_test(lang: Lang, source: &str, expected_root: &str) { - let tree = lang.parse(source); - let root = tree.root_node(); - assert_eq!(root.kind(), expected_root); - assert!(!root.has_error()); - } - - #[test] - #[cfg(feature = "lang-bash")] - fn smoke_parse_bash() { - smoke_test(plotnik_langs::bash(), "echo hello", "program"); - } - - #[test] - #[cfg(feature = "lang-c")] - fn smoke_parse_c() { - smoke_test( - plotnik_langs::c(), - "int main() { return 0; }", - "translation_unit", - ); - } - - #[test] - #[cfg(feature = "lang-cpp")] - fn smoke_parse_cpp() { - smoke_test( - plotnik_langs::cpp(), - "int main() { return 0; }", - "translation_unit", - ); - } - - #[test] - #[cfg(feature = "lang-c-sharp")] - fn smoke_parse_csharp() { - smoke_test(plotnik_langs::csharp(), "class Foo { }", "compilation_unit"); - } - - #[test] - #[cfg(feature = "lang-css")] - fn smoke_parse_css() { - smoke_test(plotnik_langs::css(), "body { color: red; }", "stylesheet"); - } - - #[test] - #[cfg(feature = "lang-elixir")] - fn smoke_parse_elixir() { - smoke_test(plotnik_langs::elixir(), "defmodule Foo do end", "source"); - } - - #[test] - #[cfg(feature = "lang-go")] - fn smoke_parse_go() { - smoke_test(plotnik_langs::go(), "package main", "source_file"); - } - - #[test] - #[cfg(feature = "lang-haskell")] - fn smoke_parse_haskell() { - smoke_test( - plotnik_langs::haskell(), - "main = putStrLn \"hello\"", - "haskell", - ); - } - - #[test] - #[cfg(feature = "lang-hcl")] - fn smoke_parse_hcl() { - smoke_test( - plotnik_langs::hcl(), - "resource \"aws_instance\" \"x\" {}", - "config_file", - ); - } - - #[test] - #[cfg(feature = "lang-html")] - fn smoke_parse_html() { - smoke_test(plotnik_langs::html(), "", "document"); - } - - #[test] - #[cfg(feature = "lang-java")] - fn smoke_parse_java() { - smoke_test(plotnik_langs::java(), "class Foo {}", "program"); - } - - #[test] - #[cfg(feature = "lang-javascript")] - fn smoke_parse_javascript() { - smoke_test( - plotnik_langs::javascript(), - "function hello() { return 42; }", - "program", - ); - } - - #[test] - #[cfg(feature = "lang-json")] - fn smoke_parse_json() { - smoke_test(plotnik_langs::json(), r#"{"key": "value"}"#, "document"); - } - - #[test] - #[cfg(feature = "lang-kotlin")] - fn smoke_parse_kotlin() { - smoke_test(plotnik_langs::kotlin(), "fun main() {}", "source_file"); - } - - #[test] - #[cfg(feature = "lang-lua")] - fn smoke_parse_lua() { - smoke_test(plotnik_langs::lua(), "print('hello')", "chunk"); - } - - #[test] - #[cfg(feature = "lang-nix")] - fn smoke_parse_nix() { - smoke_test(plotnik_langs::nix(), "{ x = 1; }", "source_code"); - } - - #[test] - #[cfg(feature = "lang-php")] - fn smoke_parse_php() { - smoke_test(plotnik_langs::php(), ";", "program"); - } - - #[test] - #[cfg(feature = "lang-yaml")] - fn smoke_parse_yaml() { - smoke_test(plotnik_langs::yaml(), "key: value", "stream"); - } - - #[test] - #[cfg(feature = "lang-javascript")] - fn lang_from_name() { - assert_eq!(plotnik_langs::from_name("js").unwrap().name(), "javascript"); - assert_eq!( - plotnik_langs::from_name("JavaScript").unwrap().name(), - "javascript" - ); - assert!(plotnik_langs::from_name("unknown").is_none()); - } - - #[test] - #[cfg(feature = "lang-javascript")] - fn lang_from_extension() { - assert_eq!(plotnik_langs::from_ext("js").unwrap().name(), "javascript"); - assert_eq!(plotnik_langs::from_ext("mjs").unwrap().name(), "javascript"); - } -} diff --git a/crates/plotnik-cli/src/commands/langs_tests.rs b/crates/plotnik-cli/src/commands/langs_tests.rs new file mode 100644 index 00000000..5f83b82c --- /dev/null +++ b/crates/plotnik-cli/src/commands/langs_tests.rs @@ -0,0 +1,186 @@ +use plotnik_langs::Lang; + +fn smoke_test(lang: Lang, source: &str, expected_root: &str) { + let tree = lang.parse(source); + let root = tree.root_node(); + assert_eq!(root.kind(), expected_root); + assert!(!root.has_error()); +} + +#[test] +#[cfg(feature = "lang-bash")] +fn smoke_parse_bash() { + smoke_test(plotnik_langs::bash(), "echo hello", "program"); +} + +#[test] +#[cfg(feature = "lang-c")] +fn smoke_parse_c() { + smoke_test( + plotnik_langs::c(), + "int main() { return 0; }", + "translation_unit", + ); +} + +#[test] +#[cfg(feature = "lang-cpp")] +fn smoke_parse_cpp() { + smoke_test( + plotnik_langs::cpp(), + "int main() { return 0; }", + "translation_unit", + ); +} + +#[test] +#[cfg(feature = "lang-c-sharp")] +fn smoke_parse_csharp() { + smoke_test(plotnik_langs::csharp(), "class Foo { }", "compilation_unit"); +} + +#[test] +#[cfg(feature = "lang-css")] +fn smoke_parse_css() { + smoke_test(plotnik_langs::css(), "body { color: red; }", "stylesheet"); +} + +#[test] +#[cfg(feature = "lang-elixir")] +fn smoke_parse_elixir() { + smoke_test(plotnik_langs::elixir(), "defmodule Foo do end", "source"); +} + +#[test] +#[cfg(feature = "lang-go")] +fn smoke_parse_go() { + smoke_test(plotnik_langs::go(), "package main", "source_file"); +} + +#[test] +#[cfg(feature = "lang-haskell")] +fn smoke_parse_haskell() { + smoke_test( + plotnik_langs::haskell(), + "main = putStrLn \"hello\"", + "haskell", + ); +} + +#[test] +#[cfg(feature = "lang-hcl")] +fn smoke_parse_hcl() { + smoke_test( + plotnik_langs::hcl(), + "resource \"aws_instance\" \"x\" {}", + "config_file", + ); +} + +#[test] +#[cfg(feature = "lang-html")] +fn smoke_parse_html() { + smoke_test(plotnik_langs::html(), "", "document"); +} + +#[test] +#[cfg(feature = "lang-java")] +fn smoke_parse_java() { + smoke_test(plotnik_langs::java(), "class Foo {}", "program"); +} + +#[test] +#[cfg(feature = "lang-javascript")] +fn smoke_parse_javascript() { + smoke_test( + plotnik_langs::javascript(), + "function hello() { return 42; }", + "program", + ); +} + +#[test] +#[cfg(feature = "lang-json")] +fn smoke_parse_json() { + smoke_test(plotnik_langs::json(), r#"{"key": "value"}"#, "document"); +} + +#[test] +#[cfg(feature = "lang-kotlin")] +fn smoke_parse_kotlin() { + smoke_test(plotnik_langs::kotlin(), "fun main() {}", "source_file"); +} + +#[test] +#[cfg(feature = "lang-lua")] +fn smoke_parse_lua() { + smoke_test(plotnik_langs::lua(), "print('hello')", "chunk"); +} + +#[test] +#[cfg(feature = "lang-nix")] +fn smoke_parse_nix() { + smoke_test(plotnik_langs::nix(), "{ x = 1; }", "source_code"); +} + +#[test] +#[cfg(feature = "lang-php")] +fn smoke_parse_php() { + smoke_test(plotnik_langs::php(), ";", "program"); +} + +#[test] +#[cfg(feature = "lang-yaml")] +fn smoke_parse_yaml() { + smoke_test(plotnik_langs::yaml(), "key: value", "stream"); +} diff --git a/crates/plotnik-cli/src/commands/mod.rs b/crates/plotnik-cli/src/commands/mod.rs index 7118f82a..f5e59a46 100644 --- a/crates/plotnik-cli/src/commands/mod.rs +++ b/crates/plotnik-cli/src/commands/mod.rs @@ -2,3 +2,6 @@ pub mod debug; pub mod exec; pub mod langs; pub mod types; + +#[cfg(test)] +mod langs_tests;