From 2b7d8eaaca5ebb0073a36aaf702554df88c5e97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 1 Apr 2025 02:54:45 +0200 Subject: [PATCH] Test different `Theme` variants in `styling` example --- .github/workflows/test.yml | 4 +- Cargo.lock | 2 + core/src/input_method.rs | 33 ---------------- examples/styling/Cargo.toml | 4 ++ .../catppuccin_frappé-tiny-skia.sha256 | 1 + .../catppuccin_latte-tiny-skia.sha256 | 1 + .../catppuccin_macchiato-tiny-skia.sha256 | 1 + .../catppuccin_mocha-tiny-skia.sha256 | 1 + .../styling/snapshots/dark-tiny-skia.sha256 | 1 + .../snapshots/dracula-tiny-skia.sha256 | 1 + .../styling/snapshots/ferra-tiny-skia.sha256 | 1 + .../snapshots/gruvbox_dark-tiny-skia.sha256 | 1 + .../snapshots/gruvbox_light-tiny-skia.sha256 | 1 + .../kanagawa_dragon-tiny-skia.sha256 | 1 + .../snapshots/kanagawa_lotus-tiny-skia.sha256 | 1 + .../snapshots/kanagawa_wave-tiny-skia.sha256 | 1 + .../styling/snapshots/light-tiny-skia.sha256 | 1 + .../snapshots/moonfly-tiny-skia.sha256 | 1 + .../snapshots/nightfly-tiny-skia.sha256 | 1 + .../styling/snapshots/nord-tiny-skia.sha256 | 1 + .../snapshots/oxocarbon-tiny-skia.sha256 | 1 + .../snapshots/solarized_dark-tiny-skia.sha256 | 1 + .../solarized_light-tiny-skia.sha256 | 1 + .../snapshots/tokyo_night-tiny-skia.sha256 | 1 + .../tokyo_night_light-tiny-skia.sha256 | 1 + .../tokyo_night_storm-tiny-skia.sha256 | 1 + examples/styling/src/main.rs | 39 +++++++++++++++++++ 27 files changed, 69 insertions(+), 35 deletions(-) create mode 100644 examples/styling/snapshots/catppuccin_frappé-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/catppuccin_latte-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/catppuccin_macchiato-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/catppuccin_mocha-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/dark-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/dracula-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/ferra-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/gruvbox_dark-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/gruvbox_light-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/kanagawa_dragon-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/kanagawa_lotus-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/kanagawa_wave-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/light-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/moonfly-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/nightfly-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/nord-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/oxocarbon-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/solarized_dark-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/solarized_light-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/tokyo_night-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/tokyo_night_light-tiny-skia.sha256 create mode 100644 examples/styling/snapshots/tokyo_night_storm-tiny-skia.sha256 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f35556f..1e988195 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,5 +23,5 @@ jobs: sudo apt-get install -y libxkbcommon-dev libgtk-3-dev - name: Run tests run: | - cargo test --verbose --workspace - cargo test --verbose --workspace --all-features + cargo test --verbose --workspace -- --ignored + cargo test --verbose --workspace --all-features -- --ignored diff --git a/Cargo.lock b/Cargo.lock index 8aebb086..33210bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5519,6 +5519,8 @@ name = "styling" version = "0.1.0" dependencies = [ "iced", + "iced_test", + "rayon", ] [[package]] diff --git a/core/src/input_method.rs b/core/src/input_method.rs index cd8d459d..1d82279c 100644 --- a/core/src/input_method.rs +++ b/core/src/input_method.rs @@ -151,39 +151,6 @@ impl InputMethod { /// However, one couldn't possibly have a key for every single /// unicode character that the user might want to type. The solution operating systems employ is /// to allow the user to type these using _a sequence of keypresses_ instead. -/// -/// A prominent example of this is accents—many keyboard layouts allow you to first click the -/// "accent key", and then the character you want to apply the accent to. In this case, some -/// platforms will generate the following event sequence: -/// -/// ```ignore -/// // Press "`" key -/// Ime::Preedit("`", Some((0, 0))) -/// // Press "E" key -/// Ime::Preedit("", None) // Synthetic event generated to clear preedit. -/// Ime::Commit("é") -/// ``` -/// -/// Additionally, certain input devices are configured to display a candidate box that allow the -/// user to select the desired character interactively. (To properly position this box, you must use -/// [`Shell::request_input_method`](crate::Shell::request_input_method).) -/// -/// An example of a keyboard layout which uses candidate boxes is pinyin. On a latin keyboard the -/// following event sequence could be obtained: -/// -/// ```ignore -/// // Press "A" key -/// Ime::Preedit("a", Some((1, 1))) -/// // Press "B" key -/// Ime::Preedit("a b", Some((3, 3))) -/// // Press left arrow key -/// Ime::Preedit("a b", Some((1, 1))) -/// // Press space key -/// Ime::Preedit("啊b", Some((3, 3))) -/// // Press space key -/// Ime::Preedit("", None) // Synthetic event generated to clear preedit. -/// Ime::Commit("啊不") -/// ``` #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Event { /// Notifies when the IME was opened. diff --git a/examples/styling/Cargo.toml b/examples/styling/Cargo.toml index 75cc520d..6e05ae34 100644 --- a/examples/styling/Cargo.toml +++ b/examples/styling/Cargo.toml @@ -7,3 +7,7 @@ publish = false [dependencies] iced.workspace = true + +[dev-dependencies] +iced_test.workspace = true +rayon = "1" diff --git a/examples/styling/snapshots/catppuccin_frappé-tiny-skia.sha256 b/examples/styling/snapshots/catppuccin_frappé-tiny-skia.sha256 new file mode 100644 index 00000000..e4038c0b --- /dev/null +++ b/examples/styling/snapshots/catppuccin_frappé-tiny-skia.sha256 @@ -0,0 +1 @@ +9e67e429f88fd5a64744d9cd4d42e123950bea4a45fea78581bc3d64b12e11f0 \ No newline at end of file diff --git a/examples/styling/snapshots/catppuccin_latte-tiny-skia.sha256 b/examples/styling/snapshots/catppuccin_latte-tiny-skia.sha256 new file mode 100644 index 00000000..43f380cf --- /dev/null +++ b/examples/styling/snapshots/catppuccin_latte-tiny-skia.sha256 @@ -0,0 +1 @@ +811a22238f3a40e3e3998f514c0a95f24f2b45449250682d86c8ec392fec5e28 \ No newline at end of file diff --git a/examples/styling/snapshots/catppuccin_macchiato-tiny-skia.sha256 b/examples/styling/snapshots/catppuccin_macchiato-tiny-skia.sha256 new file mode 100644 index 00000000..4d7e694e --- /dev/null +++ b/examples/styling/snapshots/catppuccin_macchiato-tiny-skia.sha256 @@ -0,0 +1 @@ +6bf957efe807f87f38cfc672f9a05325aadee6256aacca87bbc3281b98160c8a \ No newline at end of file diff --git a/examples/styling/snapshots/catppuccin_mocha-tiny-skia.sha256 b/examples/styling/snapshots/catppuccin_mocha-tiny-skia.sha256 new file mode 100644 index 00000000..12ca25d5 --- /dev/null +++ b/examples/styling/snapshots/catppuccin_mocha-tiny-skia.sha256 @@ -0,0 +1 @@ +d3f4110fae78a3be3b7a4813e9a432b48b81fff1e982c0244e4ea394074bef55 \ No newline at end of file diff --git a/examples/styling/snapshots/dark-tiny-skia.sha256 b/examples/styling/snapshots/dark-tiny-skia.sha256 new file mode 100644 index 00000000..f4d2328e --- /dev/null +++ b/examples/styling/snapshots/dark-tiny-skia.sha256 @@ -0,0 +1 @@ +578e7420de69d82906d284c59d81fcea0edf81098481fc4dd7b4c1fb577b7f1c \ No newline at end of file diff --git a/examples/styling/snapshots/dracula-tiny-skia.sha256 b/examples/styling/snapshots/dracula-tiny-skia.sha256 new file mode 100644 index 00000000..9c3af7e9 --- /dev/null +++ b/examples/styling/snapshots/dracula-tiny-skia.sha256 @@ -0,0 +1 @@ +422e841113efaa86e9e37593d0d14f8dd36ad483a81c30a08588f48805e4f9f3 \ No newline at end of file diff --git a/examples/styling/snapshots/ferra-tiny-skia.sha256 b/examples/styling/snapshots/ferra-tiny-skia.sha256 new file mode 100644 index 00000000..f344175f --- /dev/null +++ b/examples/styling/snapshots/ferra-tiny-skia.sha256 @@ -0,0 +1 @@ +3d616a31842a29b4a3d31fbeef25f95c7b50f33360f1c05e069e0b29b3f7553e \ No newline at end of file diff --git a/examples/styling/snapshots/gruvbox_dark-tiny-skia.sha256 b/examples/styling/snapshots/gruvbox_dark-tiny-skia.sha256 new file mode 100644 index 00000000..528e4662 --- /dev/null +++ b/examples/styling/snapshots/gruvbox_dark-tiny-skia.sha256 @@ -0,0 +1 @@ +9a21865bfc075669d368ccac69b975c3e1f6c22ba297dddfa003d4ee1a06641c \ No newline at end of file diff --git a/examples/styling/snapshots/gruvbox_light-tiny-skia.sha256 b/examples/styling/snapshots/gruvbox_light-tiny-skia.sha256 new file mode 100644 index 00000000..0846526d --- /dev/null +++ b/examples/styling/snapshots/gruvbox_light-tiny-skia.sha256 @@ -0,0 +1 @@ +d5164fb10a92177afd0aab353557d1e3fdaa743962c6a901f05cbfcd0d91e9fb \ No newline at end of file diff --git a/examples/styling/snapshots/kanagawa_dragon-tiny-skia.sha256 b/examples/styling/snapshots/kanagawa_dragon-tiny-skia.sha256 new file mode 100644 index 00000000..1ea91e22 --- /dev/null +++ b/examples/styling/snapshots/kanagawa_dragon-tiny-skia.sha256 @@ -0,0 +1 @@ +3d5ba3b50f192f8700edbfbf54007e92dfd66997bce7342671afc2b60d556aca \ No newline at end of file diff --git a/examples/styling/snapshots/kanagawa_lotus-tiny-skia.sha256 b/examples/styling/snapshots/kanagawa_lotus-tiny-skia.sha256 new file mode 100644 index 00000000..aed0d8ba --- /dev/null +++ b/examples/styling/snapshots/kanagawa_lotus-tiny-skia.sha256 @@ -0,0 +1 @@ +90cb13c900d58a56ce170afeefbceb77410d024e7eae6030e181df1c929c3944 \ No newline at end of file diff --git a/examples/styling/snapshots/kanagawa_wave-tiny-skia.sha256 b/examples/styling/snapshots/kanagawa_wave-tiny-skia.sha256 new file mode 100644 index 00000000..e5785815 --- /dev/null +++ b/examples/styling/snapshots/kanagawa_wave-tiny-skia.sha256 @@ -0,0 +1 @@ +71b625bc39aaead7a1298e4b2dad51b266526c53deab139858774986395878db \ No newline at end of file diff --git a/examples/styling/snapshots/light-tiny-skia.sha256 b/examples/styling/snapshots/light-tiny-skia.sha256 new file mode 100644 index 00000000..e2bc2896 --- /dev/null +++ b/examples/styling/snapshots/light-tiny-skia.sha256 @@ -0,0 +1 @@ +f08f80a79959ef1c2fd8f8696a26555f2b2eab6618dd3653a042acab563bcced \ No newline at end of file diff --git a/examples/styling/snapshots/moonfly-tiny-skia.sha256 b/examples/styling/snapshots/moonfly-tiny-skia.sha256 new file mode 100644 index 00000000..f873883f --- /dev/null +++ b/examples/styling/snapshots/moonfly-tiny-skia.sha256 @@ -0,0 +1 @@ +3302b7934051ff8aa01d70c45e28c444bdc93e8a4da219931aa22465b51c6748 \ No newline at end of file diff --git a/examples/styling/snapshots/nightfly-tiny-skia.sha256 b/examples/styling/snapshots/nightfly-tiny-skia.sha256 new file mode 100644 index 00000000..4c44a93c --- /dev/null +++ b/examples/styling/snapshots/nightfly-tiny-skia.sha256 @@ -0,0 +1 @@ +661ec43b66213f369ce5a3680e9e8ead56c98d94718da25b12fbb313386944e0 \ No newline at end of file diff --git a/examples/styling/snapshots/nord-tiny-skia.sha256 b/examples/styling/snapshots/nord-tiny-skia.sha256 new file mode 100644 index 00000000..8dc1da2e --- /dev/null +++ b/examples/styling/snapshots/nord-tiny-skia.sha256 @@ -0,0 +1 @@ +b5dd22b064220d5f2f90c6f0f381eff41d25f534587d1649ed59e25f878eda97 \ No newline at end of file diff --git a/examples/styling/snapshots/oxocarbon-tiny-skia.sha256 b/examples/styling/snapshots/oxocarbon-tiny-skia.sha256 new file mode 100644 index 00000000..56f26dc9 --- /dev/null +++ b/examples/styling/snapshots/oxocarbon-tiny-skia.sha256 @@ -0,0 +1 @@ +dd6e7e7ba125a2549143501c3de44427633f0bfa6c0d8b6f66aa95d503874065 \ No newline at end of file diff --git a/examples/styling/snapshots/solarized_dark-tiny-skia.sha256 b/examples/styling/snapshots/solarized_dark-tiny-skia.sha256 new file mode 100644 index 00000000..063a9c50 --- /dev/null +++ b/examples/styling/snapshots/solarized_dark-tiny-skia.sha256 @@ -0,0 +1 @@ +44b5afe743b753a54f3e68da2fd2701837e7e8cff276ff1e8c349030c83ac72e \ No newline at end of file diff --git a/examples/styling/snapshots/solarized_light-tiny-skia.sha256 b/examples/styling/snapshots/solarized_light-tiny-skia.sha256 new file mode 100644 index 00000000..0bb49deb --- /dev/null +++ b/examples/styling/snapshots/solarized_light-tiny-skia.sha256 @@ -0,0 +1 @@ +1b46820f12611b2759eb843688cd13b6024f2096b7986f205398bb029e0c60bd \ No newline at end of file diff --git a/examples/styling/snapshots/tokyo_night-tiny-skia.sha256 b/examples/styling/snapshots/tokyo_night-tiny-skia.sha256 new file mode 100644 index 00000000..d6eb163d --- /dev/null +++ b/examples/styling/snapshots/tokyo_night-tiny-skia.sha256 @@ -0,0 +1 @@ +27a9a8bb08cea7b0a9b9763e332a6833d4fead1a885cdd59a1f5161e3726d6b1 \ No newline at end of file diff --git a/examples/styling/snapshots/tokyo_night_light-tiny-skia.sha256 b/examples/styling/snapshots/tokyo_night_light-tiny-skia.sha256 new file mode 100644 index 00000000..f9eb9211 --- /dev/null +++ b/examples/styling/snapshots/tokyo_night_light-tiny-skia.sha256 @@ -0,0 +1 @@ +ab0dee2cc24f30eb51b376a0385302b45bfeddb373348525dab7f551c27ffec2 \ No newline at end of file diff --git a/examples/styling/snapshots/tokyo_night_storm-tiny-skia.sha256 b/examples/styling/snapshots/tokyo_night_storm-tiny-skia.sha256 new file mode 100644 index 00000000..a642d939 --- /dev/null +++ b/examples/styling/snapshots/tokyo_night_storm-tiny-skia.sha256 @@ -0,0 +1 @@ +aef404c7e38aec5387c39cf3a2911688324c1b9b520e5f541b9fd3fd6eefd3a8 \ No newline at end of file diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index fce2b162..322b2b94 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -167,3 +167,42 @@ impl Styling { self.theme.clone() } } + +#[cfg(test)] +mod tests { + use super::*; + use rayon::prelude::*; + + use iced_test::{Error, simulator}; + + #[test] + #[ignore] + fn it_showcases_every_theme() -> Result<(), Error> { + Theme::ALL + .par_iter() + .map(|theme| { + let mut styling = Styling::default(); + styling.update(Message::ThemeChanged(theme.clone())); + + let theme = styling.theme(); + + let mut ui = simulator(styling.view()); + + let snapshot = ui.snapshot(&theme)?; + + assert!( + snapshot.matches_hash(format!( + "snapshots/{theme}", + theme = theme + .to_string() + .to_ascii_lowercase() + .replace(" ", "_") + ))?, + "snapshots for {theme} should match!" + ); + + Ok(()) + }) + .collect() + } +}