| 91 | |
| 92 | #[test] |
| 93 | fn test_basis() -> Result<()> { |
| 94 | let temp_dir = tempfile::tempdir()?; |
| 95 | let file1_path = temp_dir.path().join("a.toml"); |
| 96 | let file2_path = temp_dir.path().join("b.toml"); |
| 97 | let mut file1 = std::fs::File::create(&file1_path)?; |
| 98 | write!( |
| 99 | file1, |
| 100 | "{}", |
| 101 | r#" |
| 102 | include=["./b.toml"] |
| 103 | a=1 |
| 104 | b="string in a" |
| 105 | c=[1,2,3] |
| 106 | d=[4,5,6] |
| 107 | e={a=1, b=2}"# |
| 108 | )?; |
| 109 | let mut file2 = std::fs::File::create(&file2_path)?; |
| 110 | write!( |
| 111 | file2, |
| 112 | "{}", |
| 113 | r#" |
| 114 | include=[] |
| 115 | a=2 |
| 116 | b="string in b" |
| 117 | c=[4,5,6] |
| 118 | d=[1,2,3] |
| 119 | e={c=3, b=4}"# |
| 120 | )?; |
| 121 | let config: Config = Parser::from_file(&file1_path, None)?; |
| 122 | assert_eq!(config.a, 1); |
| 123 | assert_eq!(config.b, "string in a"); |
| 124 | assert_eq!(config.c, vec![1, 2, 3, 4, 5, 6]); |
| 125 | assert_eq!( |
| 126 | config |
| 127 | .d |
| 128 | .difference(&(1..=6).collect::<HashSet<i32>>()) |
| 129 | .count(), |
| 130 | 0 |
| 131 | ); |
| 132 | assert_eq!(config.e.len(), 3); |
| 133 | assert_eq!(config.e["a"], 1); |
| 134 | assert_eq!(config.e["b"], 2); |
| 135 | assert_eq!(config.e["c"], 3); |
| 136 | Ok(()) |
| 137 | } |
| 138 | |
| 139 | #[test] |
| 140 | #[should_panic] |