StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use super::CursorThemeCrawler; |
| 2 | use ::virtual_fs::{Stub, VirtualFS}; |
| 3 | |
| 4 | #[test] |
| 5 | fn test_no_themes_found() { |
| 6 | VirtualFS::test("test_no_themes_found", |dirs, mut sandbox| { |
| 7 | sandbox.mkdir("icons"); |
| 8 | let crawler = CursorThemeCrawler { |
| 9 | directories: vec![dirs.tests().join("icons")], |
| 10 | }; |
| 11 | |
| 12 | assert_eq!(crawler.determine_cursor_theme(), None); |
| 13 | }); |
| 14 | } |
| 15 | |
| 16 | #[test] |
| 17 | fn test_default_theme_found() { |
| 18 | VirtualFS::test("test_default_theme_found", |dirs, mut sandbox| { |
| 19 | sandbox.mkdir("icons/default/cursors"); |
| 20 | let crawler = CursorThemeCrawler { |
| 21 | directories: vec![dirs.tests().join("icons")], |
| 22 | }; |
| 23 | |
| 24 | assert_eq!( |
| 25 | crawler.determine_cursor_theme(), |
| 26 | Some("default".to_string()) |
| 27 | ); |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn test_known_theme_found() { |
| 33 | VirtualFS::test("test_known_theme_found", |dirs, mut sandbox| { |
| 34 | sandbox.mkdir("icons/Yaru/cursors"); |
| 35 | let crawler = CursorThemeCrawler { |
| 36 | directories: vec![dirs.tests().join("icons")], |
| 37 | }; |
| 38 | |
| 39 | assert_eq!(crawler.determine_cursor_theme(), Some("Yaru".to_string())); |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | #[test] |
| 44 | fn test_default_theme_found_via_index() { |
| 45 | VirtualFS::test("test_default_theme_found_via_index", |dirs, mut sandbox| { |
| 46 | sandbox.mkdir("icons/Darmok/cursors"); |
| 47 | sandbox.mkdir("icons/default"); |
| 48 | sandbox.with_files(vec![Stub::FileWithContent( |
| 49 | "icons/default/index.theme", |
| 50 | r#" |
| 51 | [Icon Theme] |
| 52 | Inherits=Darmok |
| 53 | "#, |
| 54 | )]); |
| 55 | let crawler: CursorThemeCrawler = CursorThemeCrawler { |
| 56 | directories: vec![dirs.tests().join("icons")], |
| 57 | }; |
| 58 | |
| 59 | assert_eq!( |
| 60 | crawler.determine_cursor_theme(), |
| 61 | Some("default".to_string()) |
| 62 | ); |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | #[test] |
| 67 | fn test_default_theme_is_prioritized_over_known_theme() { |
| 68 | VirtualFS::test( |
| 69 | "test_default_theme_is_prioritized_over_known_theme", |
| 70 | |dirs, mut sandbox| { |
| 71 | sandbox.mkdir("icons/Darmok/cursors"); |
| 72 | sandbox.mkdir("icons/Yaru/cursors"); |
| 73 | sandbox.mkdir("icons/default"); |
| 74 | sandbox.with_files(vec![Stub::FileWithContent( |
| 75 | "icons/default/index.theme", |
| 76 | r#" |
| 77 | [Icon Theme] |
| 78 | Inherits=Darmok |
| 79 | "#, |
| 80 | )]); |
| 81 | let crawler = CursorThemeCrawler { |
| 82 | directories: vec![dirs.tests().join("icons")], |
| 83 | }; |
| 84 | |
| 85 | assert_eq!( |
| 86 | crawler.determine_cursor_theme(), |
| 87 | Some("default".to_string()) |
| 88 | ); |
| 89 | }, |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | #[test] |
| 94 | fn test_multiple_directories() { |
| 95 | VirtualFS::test("test_multiple_directories", |dirs, mut sandbox| { |
| 96 | sandbox.mkdir("icons2/Darmok/cursors"); |
| 97 | sandbox.mkdir("icons/default"); |
| 98 | sandbox.with_files(vec![Stub::FileWithContent( |
| 99 | "icons/default/index.theme", |
| 100 | r#" |
| 101 | [Icon Theme] |
| 102 | Inherits=Darmok |
| 103 | "#, |
| 104 | )]); |
| 105 | let crawler = CursorThemeCrawler { |
| 106 | directories: vec![dirs.tests().join("icons"), dirs.tests().join("icons2")], |
| 107 | }; |
| 108 | |
| 109 | assert_eq!( |
| 110 | crawler.determine_cursor_theme(), |
| 111 | Some("default".to_string()) |
| 112 | ); |
| 113 | }); |
| 114 | } |
| 115 | #[test] |
| 116 | fn test_resolution_order() { |
| 117 | VirtualFS::test("test_resolution_order", |dirs, mut sandbox| { |
| 118 | sandbox.mkdir("icons2/Darmok/cursors"); |
| 119 | sandbox.mkdir("icons/default"); |
| 120 | sandbox.mkdir("icons2/default"); |
| 121 | sandbox.with_files(vec![ |
| 122 | Stub::FileWithContent( |
| 123 | "icons/default/index.theme", |
| 124 | r#" |
| 125 | [Icon Theme] |
| 126 | Inherits=Jalad |
| 127 | "#, |
| 128 | ), |
| 129 | Stub::FileWithContent( |
| 130 | "icons2/default/index.theme", |
| 131 | r#" |
| 132 | [Icon Theme] |
| 133 | Inherits=Darmok |
| 134 | "#, |
| 135 | ), |
| 136 | ]); |
| 137 | |
| 138 | // Case 1: we find the index file in icons first. |
| 139 | // The index file points to a non-existent theme Jalad, |
| 140 | // so we return None |
| 141 | let crawler = CursorThemeCrawler { |
| 142 | directories: vec![dirs.tests().join("icons"), dirs.tests().join("icons2")], |
| 143 | }; |
| 144 | |
| 145 | assert_eq!(crawler.determine_cursor_theme(), None); |
| 146 | |
| 147 | // Case 2: we find the index file in icons first. |
| 148 | // The index file points to the valid theme Darmok, |
| 149 | // so we return Some("default") |
| 150 | let crawler = CursorThemeCrawler { |
| 151 | directories: vec![dirs.tests().join("icons2"), dirs.tests().join("icons")], |
| 152 | }; |
| 153 | |
| 154 | assert_eq!( |
| 155 | crawler.determine_cursor_theme(), |
| 156 | Some("default".to_string()) |
| 157 | ); |
| 158 | }); |
| 159 | } |
| 160 |