diff --git a/Cargo.toml b/Cargo.toml index b1311d4b..f5709d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ authors = ["Manuel Cillero "] [workspace.dependencies] serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" static-files = "0.2.4" # Helpers diff --git a/packages/pagetop-hljs/src/config.rs b/packages/pagetop-hljs/src/config.rs index 3da7243f..6a4bb5ce 100644 --- a/packages/pagetop-hljs/src/config.rs +++ b/packages/pagetop-hljs/src/config.rs @@ -11,7 +11,7 @@ //! //! Uso: //! -//! ```rust +//! ```rust#ignore //! use pagetop_hljs::config; //! //! assert_eq!(config::SETTINGS.hljs.theme, "zenburn"); diff --git a/packages/pagetop-hljs/src/lang.rs b/packages/pagetop-hljs/src/lang.rs index eb28dedb..b1e56910 100644 --- a/packages/pagetop-hljs/src/lang.rs +++ b/packages/pagetop-hljs/src/lang.rs @@ -11,7 +11,7 @@ use std::fmt; /// Languages are represented by *PascalCase* enums within the code and are mapped to corresponding /// [highlight.js](https://highlightjs.org/) language names. /// -/// ```rust +/// ```rust#ignore /// use pagetop_hljs::HljsLang; /// /// assert_eq!(HljsLang::CoffeeScript.to_string(), "coffeescript".to_string()); diff --git a/packages/pagetop-hljs/src/lib.rs b/packages/pagetop-hljs/src/lib.rs index 3b9c6d7f..9111d2a7 100644 --- a/packages/pagetop-hljs/src/lib.rs +++ b/packages/pagetop-hljs/src/lib.rs @@ -15,14 +15,14 @@ //! //! Añade `pagetop-hljs` a tu archivo `Cargo.toml`: //! -//! ```rust +//! ```rust#ignore //! [dependencies] //! pagetop-hljs = "" //! ``` //! //! Incluye `pagetop_hljs::HighlightJS` en las dependencias del paquete o aplicación que lo requiera: //! -//! ```rust +//! ```rust#ignore //! use pagetop::prelude::*; //! //! impl PackageTrait for MyPackage { @@ -44,12 +44,12 @@ //! //! Y finalmente añade tus fragmentos de código con resaltado de sintaxis en páginas web: //! -//! ```rust +//! ```rust#ignore //! use pagetop_hljs::prelude::*; //! //! async fn hljs_sample(request: HttpRequest) -> ResultPage { //! Page::new(request) -//! .with_component(Snippet::with( +//! .with_component(HljsSnippet::with( //! HljsLang::Rust, //! r###" //! // This is the main function. diff --git a/packages/pagetop-hljs/src/theme.rs b/packages/pagetop-hljs/src/theme.rs index d8a65e2f..c002c058 100644 --- a/packages/pagetop-hljs/src/theme.rs +++ b/packages/pagetop-hljs/src/theme.rs @@ -13,7 +13,7 @@ use std::fmt; /// Themes are defined as *PascalCase* enums in the code and correspond to *kebab-case* string /// identifiers. /// -/// ```rust +/// ```rust#ignore /// use pagetop_hljs::HljsTheme; /// /// assert_eq!(HljsTheme::AtelierPlateauLight.to_string(), "atelier-plateau-light".to_string()); diff --git a/packages/pagetop-seaorm/src/db/migration/schema.rs b/packages/pagetop-seaorm/src/db/migration/schema.rs index f30170ee..ef35d1c3 100644 --- a/packages/pagetop-seaorm/src/db/migration/schema.rs +++ b/packages/pagetop-seaorm/src/db/migration/schema.rs @@ -10,7 +10,7 @@ //! The following example shows how the user migration file should be and using //! the schema helpers to create the Db fields. //! -//! ```rust +//! ```rust#ignore //! use sea_orm_migration::{prelude::*, schema::*}; //! //! #[derive(DeriveMigrationName)] diff --git a/pagetop/Cargo.toml b/pagetop/Cargo.toml index fc793f75..90764f5e 100644 --- a/pagetop/Cargo.toml +++ b/pagetop/Cargo.toml @@ -47,3 +47,6 @@ pagetop-macros.workspace = true [build-dependencies] pagetop-build.workspace = true + +[dev-dependencies] +serde_json.workspace = true diff --git a/pagetop/src/util.rs b/pagetop/src/util.rs index c113214a..c6078924 100644 --- a/pagetop/src/util.rs +++ b/pagetop/src/util.rs @@ -175,7 +175,7 @@ macro_rules! hm { /// /// # Ejemplo /// -/// ``` +/// ```rust#ignore /// // Concatena todos los fragmentos directamente. /// let result = join_string!("Hello", " ", "World"); /// assert_eq!(result, "Hello World".to_string()); @@ -206,7 +206,7 @@ macro_rules! join_string { /// /// # Ejemplo /// -/// ``` +/// ```rust#ignore /// // Concatena los fragmentos no vacíos con un espacio como separador. /// let result_with_separator = option_string!(["Hello", "", "World"]; " "); /// assert_eq!(result_with_separator, Some("Hello World".to_string())); @@ -244,7 +244,7 @@ macro_rules! option_string { /// /// # Ejemplo /// -/// ``` +/// ```rust#ignore /// let first = "Hello"; /// let separator = "-"; /// let second = "World"; diff --git a/pagetop/tests/html/mod.rs b/pagetop/tests/html/mod.rs new file mode 100644 index 00000000..d5a9c941 --- /dev/null +++ b/pagetop/tests/html/mod.rs @@ -0,0 +1 @@ +mod unit; diff --git a/pagetop/tests/html/unit.rs b/pagetop/tests/html/unit.rs new file mode 100644 index 00000000..ed7809f5 --- /dev/null +++ b/pagetop/tests/html/unit.rs @@ -0,0 +1,27 @@ +use pagetop::prelude::*; + +use serde_json; + +#[pagetop::test] +async fn test_deserialize_absolute_units() { + let value: unit::Value = serde_json::from_str("\"50px\"").unwrap(); + assert!(matches!(value, unit::Value::Px(50))); + + let value: unit::Value = serde_json::from_str("\"10cm\"").unwrap(); + assert!(matches!(value, unit::Value::Cm(10))); +} + +#[pagetop::test] +async fn test_deserialize_relative_units() { + let value: unit::Value = serde_json::from_str("\"1.5em\"").unwrap(); + assert!(matches!(value, unit::Value::RelEm(1.5))); + + let value: unit::Value = serde_json::from_str("\"100%\"").unwrap(); + assert!(matches!(value, unit::Value::RelPct(100.0))); +} + +#[pagetop::test] +async fn test_invalid_format() { + let result: Result = serde_json::from_str("\"invalid\""); + assert!(result.is_err()); +} diff --git a/tests/main.rs b/pagetop/tests/main.rs similarity index 51% rename from tests/main.rs rename to pagetop/tests/main.rs index b93d337f..a1c87be9 100644 --- a/tests/main.rs +++ b/pagetop/tests/main.rs @@ -1,2 +1,5 @@ #[cfg(test)] mod server; + +#[cfg(test)] +mod html; diff --git a/tests/server/health_check.rs b/pagetop/tests/server/health_check.rs similarity index 91% rename from tests/server/health_check.rs rename to pagetop/tests/server/health_check.rs index 578ffc66..41415c7a 100644 --- a/tests/server/health_check.rs +++ b/pagetop/tests/server/health_check.rs @@ -9,6 +9,4 @@ async fn health_check_works() { let app = service::test::init_service(Application::prepare(&HealthCheck).test()).await; let req = service::test::TestRequest::get().uri("/").to_request(); let _resp = service::test::call_service(&app, req).await; - - // assert_eq!("OK", "OK"); } diff --git a/tests/server/mod.rs b/pagetop/tests/server/mod.rs similarity index 100% rename from tests/server/mod.rs rename to pagetop/tests/server/mod.rs