From b6f0f90ac5087836ac1d1575a33127b57cb5481f Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Thu, 16 Feb 2023 12:09:06 +0100 Subject: [PATCH] Fix docs gen test --- packages/cli/src/gen/mod.rs | 3 ++- packages/cli/src/tests/file_checks.rs | 2 +- packages/cli/src/tests/file_type.rs | 13 +++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/gen/mod.rs b/packages/cli/src/gen/mod.rs index 4da1f3a..a9c8ac6 100644 --- a/packages/cli/src/gen/mod.rs +++ b/packages/cli/src/gen/mod.rs @@ -9,7 +9,8 @@ mod doc; const GENERATED_COMMENT_TAG: &str = "@generated with lune-cli"; -use self::doc::{DocsFunctionParamLink, DocumentationVisitor}; +use self::doc::DocsFunctionParamLink; +pub use self::doc::DocumentationVisitor; pub fn generate_docs_json_from_definitions(contents: &str, namespace: &str) -> Result { let visitor = DocumentationVisitor::from_definitions(contents)?; diff --git a/packages/cli/src/tests/file_checks.rs b/packages/cli/src/tests/file_checks.rs index 0d7090e..9d72e92 100644 --- a/packages/cli/src/tests/file_checks.rs +++ b/packages/cli/src/tests/file_checks.rs @@ -31,7 +31,7 @@ async fn inner(file_name: &str, desired_type: FileType) -> Result<()> { fmt_path_relative_to_workspace_root(file_name) ) })?; - let parsed_type = FileType::from_contents(&file_contents); + let parsed_type = FileType::sniff(&file_contents); if parsed_type != Some(desired_type) { bail!( "Generating definitions file at '{}' created '{}', expected '{}'", diff --git a/packages/cli/src/tests/file_type.rs b/packages/cli/src/tests/file_type.rs index 7398245..a6a1eef 100644 --- a/packages/cli/src/tests/file_type.rs +++ b/packages/cli/src/tests/file_type.rs @@ -1,6 +1,7 @@ -use serde_json::Value; +use serde_json::Value as JsonValue; +use serde_yaml::Value as YamlValue; -use crate::gen::parse_definitions; +use crate::gen::DocumentationVisitor; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum FileType { @@ -10,12 +11,12 @@ pub enum FileType { } impl FileType { - pub fn from_contents(contents: &str) -> Option { - if serde_json::from_str::(contents).is_ok() { + pub fn sniff(contents: &str) -> Option { + if serde_json::from_str::(contents).is_ok() { Some(Self::Json) - } else if serde_yaml::from_str::(contents).is_ok() { + } else if serde_yaml::from_str::(contents).is_ok() { Some(Self::Yaml) - } else if parse_definitions(contents).is_ok() { + } else if DocumentationVisitor::from_definitions(contents).is_ok() { Some(Self::Luau) } else { None