mirror of
https://github.com/m-lamonaca/json-to-env.git
synced 2025-04-05 02:16:40 +00:00
add array parsing tests
This commit is contained in:
parent
15d7ee5dcc
commit
d116a49b11
1 changed files with 34 additions and 1 deletions
35
src/main.rs
35
src/main.rs
|
@ -186,7 +186,7 @@ impl Display for EnvVar {
|
|||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{EnvVar, JsonParser};
|
||||
use crate::{EnvVar, JsonParser, ParseOptions};
|
||||
|
||||
const KEY: &str = r#""key""#;
|
||||
|
||||
|
@ -277,4 +277,37 @@ mod tests {
|
|||
// ASSERT
|
||||
assert_eq!(result, "")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_array_not_enumerated() {
|
||||
let json = json!({ "array": [1, 2, 3] });
|
||||
let options = ParseOptions::new("__".to_string(), ",".to_string(), false);
|
||||
let mut parser = JsonParser::new(options);
|
||||
let environ = parser.parse(&json);
|
||||
|
||||
assert_eq!(
|
||||
*environ,
|
||||
vec![EnvVar(
|
||||
"array".to_string(),
|
||||
serde_json::Value::String("1,2,3".to_string())
|
||||
)]
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_array_enumerated() {
|
||||
let json = json!({ "array": [1, 2, 3] });
|
||||
let options = ParseOptions::new("__".to_string(), ",".to_string(), true);
|
||||
let mut parser = JsonParser::new(options);
|
||||
let environ = parser.parse(&json);
|
||||
|
||||
assert_eq!(
|
||||
*environ,
|
||||
vec![
|
||||
EnvVar("array__0".to_string(), serde_json::Value::Number(1.into())),
|
||||
EnvVar("array__1".to_string(), serde_json::Value::Number(2.into())),
|
||||
EnvVar("array__2".to_string(), serde_json::Value::Number(3.into()))
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue