|
| 1 | +use cargo_platform::{CheckCfg, ExpectedValues}; |
| 2 | +use std::collections::HashSet; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn print_check_cfg_none() { |
| 6 | + let mut check_cfg = CheckCfg::default(); |
| 7 | + |
| 8 | + check_cfg.parse_print_check_cfg_line("cfg_a").unwrap(); |
| 9 | + assert_eq!( |
| 10 | + *check_cfg.expecteds.get("cfg_a").unwrap(), |
| 11 | + ExpectedValues::Some(HashSet::from([None])) |
| 12 | + ); |
| 13 | +} |
| 14 | + |
| 15 | +#[test] |
| 16 | +fn print_check_cfg_empty() { |
| 17 | + let mut check_cfg = CheckCfg::default(); |
| 18 | + |
| 19 | + check_cfg.parse_print_check_cfg_line("cfg_b=").unwrap(); |
| 20 | + assert_eq!( |
| 21 | + *check_cfg.expecteds.get("cfg_b").unwrap(), |
| 22 | + ExpectedValues::Some(HashSet::from([])) |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +#[test] |
| 27 | +fn print_check_cfg_any() { |
| 28 | + let mut check_cfg = CheckCfg::default(); |
| 29 | + |
| 30 | + check_cfg.parse_print_check_cfg_line("cfg_c=any()").unwrap(); |
| 31 | + assert_eq!( |
| 32 | + *check_cfg.expecteds.get("cfg_c").unwrap(), |
| 33 | + ExpectedValues::Any |
| 34 | + ); |
| 35 | + |
| 36 | + check_cfg.parse_print_check_cfg_line("cfg_c").unwrap(); |
| 37 | + assert_eq!( |
| 38 | + *check_cfg.expecteds.get("cfg_c").unwrap(), |
| 39 | + ExpectedValues::Any |
| 40 | + ); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn print_check_cfg_value() { |
| 45 | + let mut check_cfg = CheckCfg::default(); |
| 46 | + |
| 47 | + check_cfg |
| 48 | + .parse_print_check_cfg_line("cfg_d=\"test\"") |
| 49 | + .unwrap(); |
| 50 | + assert_eq!( |
| 51 | + *check_cfg.expecteds.get("cfg_d").unwrap(), |
| 52 | + ExpectedValues::Some(HashSet::from([Some("test".to_string())])) |
| 53 | + ); |
| 54 | + |
| 55 | + check_cfg |
| 56 | + .parse_print_check_cfg_line("cfg_d=\"tmp\"") |
| 57 | + .unwrap(); |
| 58 | + assert_eq!( |
| 59 | + *check_cfg.expecteds.get("cfg_d").unwrap(), |
| 60 | + ExpectedValues::Some(HashSet::from([ |
| 61 | + Some("test".to_string()), |
| 62 | + Some("tmp".to_string()) |
| 63 | + ])) |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +#[test] |
| 68 | +fn print_check_cfg_none_and_value() { |
| 69 | + let mut check_cfg = CheckCfg::default(); |
| 70 | + |
| 71 | + check_cfg.parse_print_check_cfg_line("cfg").unwrap(); |
| 72 | + check_cfg.parse_print_check_cfg_line("cfg=\"foo\"").unwrap(); |
| 73 | + assert_eq!( |
| 74 | + *check_cfg.expecteds.get("cfg").unwrap(), |
| 75 | + ExpectedValues::Some(HashSet::from([None, Some("foo".to_string())])) |
| 76 | + ); |
| 77 | +} |
| 78 | + |
| 79 | +#[test] |
| 80 | +fn print_check_cfg_quote_in_value() { |
| 81 | + let mut check_cfg = CheckCfg::default(); |
| 82 | + |
| 83 | + check_cfg |
| 84 | + .parse_print_check_cfg_line("cfg_e=\"quote_in_value\"\"") |
| 85 | + .unwrap(); |
| 86 | + assert_eq!( |
| 87 | + *check_cfg.expecteds.get("cfg_e").unwrap(), |
| 88 | + ExpectedValues::Some(HashSet::from([Some("quote_in_value\"".to_string())])) |
| 89 | + ); |
| 90 | +} |
| 91 | + |
| 92 | +#[test] |
| 93 | +fn print_check_cfg_value_and_any() { |
| 94 | + let mut check_cfg = CheckCfg::default(); |
| 95 | + |
| 96 | + // having both a value and `any()` shouldn't be possible but better |
| 97 | + // handle this correctly anyway |
| 98 | + |
| 99 | + check_cfg |
| 100 | + .parse_print_check_cfg_line("cfg_1=\"foo\"") |
| 101 | + .unwrap(); |
| 102 | + check_cfg.parse_print_check_cfg_line("cfg_1=any()").unwrap(); |
| 103 | + assert_eq!( |
| 104 | + *check_cfg.expecteds.get("cfg_1").unwrap(), |
| 105 | + ExpectedValues::Any |
| 106 | + ); |
| 107 | + |
| 108 | + check_cfg.parse_print_check_cfg_line("cfg_2=any()").unwrap(); |
| 109 | + check_cfg |
| 110 | + .parse_print_check_cfg_line("cfg_2=\"foo\"") |
| 111 | + .unwrap(); |
| 112 | + assert_eq!( |
| 113 | + *check_cfg.expecteds.get("cfg_2").unwrap(), |
| 114 | + ExpectedValues::Any |
| 115 | + ); |
| 116 | +} |
| 117 | + |
| 118 | +#[test] |
| 119 | +#[should_panic] |
| 120 | +fn print_check_cfg_missing_quote_value() { |
| 121 | + let mut check_cfg = CheckCfg::default(); |
| 122 | + check_cfg.parse_print_check_cfg_line("foo=bar").unwrap(); |
| 123 | +} |
0 commit comments