|
1 | 1 | use super::*; |
2 | 2 |
|
3 | | -// TODO: make these test actually test something, |
4 | | -// this is just so I can see if they're coming into ray |
| 3 | +// TODO: Add mocking? look into the request body and add tests to ensure the correct data is being sent |
5 | 4 | #[test] |
6 | | -fn test_ray_log() { |
7 | | - ray!("Hello, Log!"); |
| 5 | +fn test_ray_macro_no_args() { |
| 6 | + let ray = ray!(); |
| 7 | + assert_eq!(ray.request.payloads.len(), 0); |
8 | 8 | } |
9 | 9 |
|
10 | 10 | #[test] |
11 | | -fn test_ray_text() { |
12 | | - ray!().text("Hello, Text!"); |
| 11 | +fn test_ray_macro_with_one_arg() { |
| 12 | + let ray = ray!("Hello, Ray Macro"); |
| 13 | + assert_eq!(ray.request.payloads.len(), 1); |
13 | 14 | } |
14 | 15 |
|
15 | 16 | #[test] |
16 | | -fn test_ray_color() { |
17 | | - ray!("Hello Color").color("green"); |
| 17 | +fn test_ray_macro_with_multiple_args() { |
| 18 | + let ray = ray!("Hello", "Ray Macro"); |
| 19 | + assert_eq!(ray.request.payloads.len(), 1); |
18 | 20 | } |
19 | 21 |
|
20 | 22 | #[test] |
21 | | -fn test_ray_html() { |
22 | | - ray!().html("<strong>Hello, HTML!</strong>"); |
| 23 | +#[should_panic(expected = "exited with code 1")] |
| 24 | +fn test_rd_marco_no_args() { |
| 25 | + std::panic::set_hook(Box::new(|panic_info| { |
| 26 | + if let Some(payload) = panic_info.payload().downcast_ref::<&str>() { |
| 27 | + if *payload == "exited with code 1" { |
| 28 | + std::process::exit(1); |
| 29 | + } |
| 30 | + } |
| 31 | + })); |
| 32 | + |
| 33 | + let ray = rd!(); |
| 34 | + assert_eq!(ray.request.payloads.len(), 0); |
| 35 | +} |
| 36 | + |
| 37 | +#[test] |
| 38 | +#[should_panic(expected = "exited with code 1")] |
| 39 | +fn test_rd_macro_with_one_arg() { |
| 40 | + std::panic::set_hook(Box::new(|panic_info| { |
| 41 | + if let Some(payload) = panic_info.payload().downcast_ref::<&str>() { |
| 42 | + if *payload == "exited with code 1" { |
| 43 | + std::process::exit(1); |
| 44 | + } |
| 45 | + } |
| 46 | + })); |
| 47 | + |
| 48 | + let ray = rd!("Hello, Rd Macro"); |
| 49 | + assert_eq!(ray.request.payloads.len(), 1); |
| 50 | +} |
| 51 | + |
| 52 | +#[test] |
| 53 | +#[should_panic(expected = "exited with code 1")] |
| 54 | +fn test_rd_macro_with_multiple_args() { |
| 55 | + std::panic::set_hook(Box::new(|panic_info| { |
| 56 | + if let Some(payload) = panic_info.payload().downcast_ref::<&str>() { |
| 57 | + if *payload == "exited with code 1" { |
| 58 | + std::process::exit(1); |
| 59 | + } |
| 60 | + } |
| 61 | + })); |
| 62 | + |
| 63 | + let ray = rd!("Hello", "Rd Macro"); |
| 64 | + assert_eq!(ray.request.payloads.len(), 1); |
| 65 | +} |
| 66 | + |
| 67 | +#[test] |
| 68 | +fn test_ray_log_function() { |
| 69 | + let mut ray = Ray::new(); |
| 70 | + ray.log(vec!["Hello, Log!".to_string()]); |
| 71 | + assert_eq!(ray.request.payloads.len(), 1); |
| 72 | +} |
| 73 | + |
| 74 | +#[test] |
| 75 | +fn test_ray_text_function() { |
| 76 | + let mut ray = Ray::new(); |
| 77 | + ray.text("Hello, Text!"); |
| 78 | + assert_eq!(ray.request.payloads.len(), 1); |
| 79 | +} |
| 80 | + |
| 81 | +#[test] |
| 82 | +fn test_ray_color_function() { |
| 83 | + let mut ray = Ray::new(); |
| 84 | + ray.text("Hello, Color").color("green"); |
| 85 | + assert_eq!(ray.request.payloads.len(), 2); |
| 86 | +} |
| 87 | + |
| 88 | +#[test] |
| 89 | +fn test_ray_html_function() { |
| 90 | + let mut ray = Ray::new(); |
| 91 | + ray.html("<strong>Hello, HTML!</strong>"); |
| 92 | + assert_eq!(ray.request.payloads.len(), 1); |
| 93 | +} |
| 94 | + |
| 95 | +#[test] |
| 96 | +fn test_ray_clear_all_function() { |
| 97 | + let mut ray = Ray::new(); |
| 98 | + ray.clear_all(); |
| 99 | + assert_eq!(ray.request.payloads.len(), 1); |
| 100 | +} |
| 101 | + |
| 102 | +#[test] |
| 103 | +fn test_ray_confetti_function() { |
| 104 | + let mut ray = Ray::new(); |
| 105 | + ray.confetti(); |
| 106 | + assert_eq!(ray.request.payloads.len(), 1); |
| 107 | +} |
| 108 | + |
| 109 | +#[test] |
| 110 | +fn test_ray_charles_function() { |
| 111 | + let mut ray = Ray::new(); |
| 112 | + ray.charles(); |
| 113 | + assert_eq!(ray.request.payloads.len(), 1); |
| 114 | +} |
| 115 | + |
| 116 | +#[test] |
| 117 | +fn test_ray_new_screen_function() { |
| 118 | + let mut ray = Ray::new(); |
| 119 | + ray.new_screen(None); |
| 120 | + assert_eq!(ray.request.payloads.len(), 1); |
| 121 | +} |
| 122 | + |
| 123 | +#[test] |
| 124 | +fn test_ray_new_screen_with_name_function() { |
| 125 | + let mut ray = Ray::new(); |
| 126 | + ray.new_screen(Some("Hello, New Screen!")); |
| 127 | + assert_eq!(ray.request.payloads.len(), 1); |
23 | 128 | } |
24 | 129 |
|
25 | 130 | #[test] |
26 | | -fn test_ray_clear_all() { |
27 | | - ray!("Hello Clear"); |
28 | | - ray!().clear_all(); |
| 131 | +fn test_ray_disable() { |
| 132 | + // TODO: Add a test to ensure the request is not sent |
| 133 | + let mut ray = Ray::new(); |
| 134 | + ray.disable(); |
| 135 | + assert_eq!(ray.disabled(), true); |
| 136 | + assert_eq!(ray.enabled(), false); |
29 | 137 | } |
30 | 138 |
|
31 | 139 | #[test] |
32 | | -fn test_ray_conffiti() { |
33 | | - ray!().confetti(); |
| 140 | +fn test_ray_enabled() { |
| 141 | + // TODO: Add a test to ensure the request is sent |
| 142 | + let mut ray = Ray::new(); |
| 143 | + ray.enable(); |
| 144 | + assert_eq!(ray.enabled(), true); |
| 145 | + assert_eq!(ray.disabled(), false); |
34 | 146 | } |
0 commit comments