mirror of https://github.com/dnomd343/ClearDNS
Dnomd343
2 years ago
3 changed files with 72 additions and 23 deletions
@ -1,3 +1,4 @@ |
|||
mod ffi; |
|||
mod tests; |
|||
mod parser; |
|||
mod convert; |
|||
|
@ -0,0 +1,71 @@ |
|||
use crate::convert::to_json; |
|||
|
|||
const JSON_TEST_CONTENT: &str = r#" |
|||
{ |
|||
"int": 123, |
|||
"bool": true, |
|||
"float": 3.141592, |
|||
"string": "json test", |
|||
"array": [1, 2, 3, 4, 5], |
|||
"object": { |
|||
"sub": "test" |
|||
} |
|||
} |
|||
"#; |
|||
|
|||
const YAML_TEST_CONTENT: &str = r#" |
|||
int: 123 |
|||
bool: true |
|||
float: 3.141592 |
|||
string: "json test" |
|||
array: |
|||
- 1 |
|||
- 2 |
|||
- 3 |
|||
- 4 |
|||
- 5 |
|||
object: |
|||
sub: test |
|||
"#; |
|||
|
|||
const TOML_TEST_CONTENT: &str = r#" |
|||
int = 123 |
|||
bool = true |
|||
float = 3.141592 |
|||
string = "json test" |
|||
array = [ 1, 2, 3, 4, 5 ] |
|||
|
|||
[object] |
|||
sub = "test" |
|||
"#; |
|||
|
|||
fn format_json(raw: &str) -> String { |
|||
match to_json(raw) { |
|||
Some(data) => data, |
|||
None => panic!("JSON format error"), |
|||
} |
|||
} |
|||
|
|||
#[test] |
|||
fn json_to_json() { |
|||
assert_eq!( |
|||
format_json(JSON_TEST_CONTENT), |
|||
format_json(&to_json(JSON_TEST_CONTENT).unwrap()), |
|||
); |
|||
} |
|||
|
|||
#[test] |
|||
fn yaml_to_json() { |
|||
assert_eq!( |
|||
format_json(JSON_TEST_CONTENT), |
|||
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()), |
|||
); |
|||
} |
@ -1,23 +0,0 @@ |
|||
const JSON_TEST_CONTENT: &str = r#" |
|||
{ |
|||
"int": 123, |
|||
"float": 2.3333, |
|||
"string": "dnomd343", |
|||
"array": [1, 2, 3, 4, 5], |
|||
"dict": { |
|||
"test": "demo" |
|||
} |
|||
} |
|||
"#; |
|||
|
|||
#[cfg(test)] |
|||
mod tests { |
|||
use super::*; |
|||
|
|||
#[test] |
|||
fn json_to_json() { |
|||
println!("{}", JSON_TEST_CONTENT); |
|||
assert_eq!(1, 2); |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue