Browse Source

update: tests module

dev
Dnomd343 2 years ago
parent
commit
c13a208c2a
  1. 151
      src/to-json/src/tests.rs

151
src/to-json/src/tests.rs

@ -1,71 +1,80 @@
use crate::convert::to_json; use crate::convert::to_json;
const JSON_TEST_CONTENT: &str = r#" #[allow(dead_code)]
{ const JSON_TEST_CONTENT: &str = r#"
"int": 123, {
"bool": true, "int": 123,
"float": 3.141592, "bool": true,
"string": "json test", "float": 3.141592,
"array": [1, 2, 3, 4, 5], "string": "json test",
"object": { "array": [1, 2, 3, 4, 5],
"sub": "test" "object": {
} "sub": "test"
} }
"#; }
"#;
const YAML_TEST_CONTENT: &str = r#"
int: 123 #[allow(dead_code)]
bool: true const YAML_TEST_CONTENT: &str = r#"
float: 3.141592 int: 123
string: "json test" bool: true
array: float: 3.141592
- 1 string: "json test"
- 2 array:
- 3 - 1
- 4 - 2
- 5 - 3
object: - 4
sub: test - 5
"#; object:
sub: test
const TOML_TEST_CONTENT: &str = r#" "#;
int = 123
bool = true #[allow(dead_code)]
float = 3.141592 const TOML_TEST_CONTENT: &str = r#"
string = "json test" int = 123
array = [ 1, 2, 3, 4, 5 ] bool = true
float = 3.141592
[object] string = "json test"
sub = "test" array = [ 1, 2, 3, 4, 5 ]
"#;
[object]
fn format_json(raw: &str) -> String { sub = "test"
match to_json(raw) { "#;
Some(data) => data,
None => panic!("JSON format error"),
} mod tests {
} use super::*;
#[test] #[allow(dead_code)]
fn json_to_json() { fn format_json(raw: &str) -> String {
assert_eq!( match to_json(raw) {
format_json(JSON_TEST_CONTENT), Some(data) => data,
format_json(&to_json(JSON_TEST_CONTENT).unwrap()), None => panic!("JSON format error"),
); }
} }
#[test] #[test]
fn yaml_to_json() { fn json_to_json() {
assert_eq!( assert_eq!(
format_json(JSON_TEST_CONTENT), format_json(JSON_TEST_CONTENT),
format_json(&to_json(YAML_TEST_CONTENT).unwrap()), format_json(&to_json(JSON_TEST_CONTENT).unwrap()),
); );
} }
#[test] #[test]
fn toml_to_json() { fn yaml_to_json() {
assert_eq!( assert_eq!(
format_json(JSON_TEST_CONTENT), format_json(JSON_TEST_CONTENT),
format_json(&to_json(TOML_TEST_CONTENT).unwrap()), format_json(&to_json(YAML_TEST_CONTENT).unwrap()),
); );
} }
#[test]
fn toml_to_json() {
assert_eq!(
format_json(JSON_TEST_CONTENT),
format_json(&to_json(TOML_TEST_CONTENT).unwrap()),
);
}
}

Loading…
Cancel
Save