Ensure printing/parsing edn strings is isomorphic
Signed-off-by: Victor Porof <vporof@mozilla.com>
This commit is contained in:
parent
a627f532f0
commit
4d83aafa2a
1 changed files with 32 additions and 28 deletions
|
@ -97,7 +97,7 @@ impl Display for Value {
|
||||||
Map(ref v) => {
|
Map(ref v) => {
|
||||||
write!(f, "{{")?;
|
write!(f, "{{")?;
|
||||||
for (key, val) in v {
|
for (key, val) in v {
|
||||||
write!(f, " :{} {}", key, val)?;
|
write!(f, " {} {}", key, val)?;
|
||||||
}
|
}
|
||||||
write!(f, " }}")
|
write!(f, " }}")
|
||||||
}
|
}
|
||||||
|
@ -279,12 +279,13 @@ mod test {
|
||||||
|
|
||||||
use std::collections::{BTreeSet, BTreeMap, LinkedList};
|
use std::collections::{BTreeSet, BTreeMap, LinkedList};
|
||||||
use std::cmp::{Ordering};
|
use std::cmp::{Ordering};
|
||||||
|
use std::iter::FromIterator;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
|
|
||||||
use symbols;
|
use symbols;
|
||||||
|
use parse;
|
||||||
use num::BigInt;
|
use num::BigInt;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use std::iter::FromIterator;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_value_from() {
|
fn test_value_from() {
|
||||||
|
@ -294,32 +295,35 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_print_edn() {
|
fn test_print_edn() {
|
||||||
assert_eq!("[ 1 2 ( 3.14 ) #{ 4N } { :foo/bar 42 } [ ] :five :six/seven eight nine/ten true false nil #f NaN #f -Infinity #f +Infinity ]",
|
let string = "[ 1 2 ( 3.14 ) #{ 4N } { foo/bar 42 :baz/boz 43 } [ ] :five :six/seven eight nine/ten true false nil #f NaN #f -Infinity #f +Infinity ]";
|
||||||
Value::Vector(vec![
|
let data = Value::Vector(vec![
|
||||||
Value::Integer(1),
|
Value::Integer(1),
|
||||||
Value::Integer(2),
|
Value::Integer(2),
|
||||||
Value::List(LinkedList::from_iter(vec![
|
Value::List(LinkedList::from_iter(vec![
|
||||||
Value::Float(OrderedFloat(3.14))
|
Value::Float(OrderedFloat(3.14))
|
||||||
])),
|
])),
|
||||||
Value::Set(BTreeSet::from_iter(vec![
|
Value::Set(BTreeSet::from_iter(vec![
|
||||||
Value::from_bigint("4").unwrap()
|
Value::from_bigint("4").unwrap()
|
||||||
])),
|
])),
|
||||||
Value::Map(BTreeMap::from_iter(vec![
|
Value::Map(BTreeMap::from_iter(vec![
|
||||||
(Value::from_symbol("foo", "bar"), Value::Integer(42))
|
(Value::from_symbol("foo", "bar"), Value::Integer(42)),
|
||||||
])),
|
(Value::from_keyword("baz", "boz"), Value::Integer(43))
|
||||||
Value::Vector(vec![]),
|
])),
|
||||||
Value::Keyword(symbols::Keyword::new("five")),
|
Value::Vector(vec![]),
|
||||||
Value::NamespacedKeyword(symbols::NamespacedKeyword::new("six", "seven")),
|
Value::Keyword(symbols::Keyword::new("five")),
|
||||||
Value::PlainSymbol(symbols::PlainSymbol::new("eight")),
|
Value::NamespacedKeyword(symbols::NamespacedKeyword::new("six", "seven")),
|
||||||
Value::NamespacedSymbol(symbols::NamespacedSymbol::new("nine", "ten")),
|
Value::PlainSymbol(symbols::PlainSymbol::new("eight")),
|
||||||
Value::Boolean(true),
|
Value::NamespacedSymbol(symbols::NamespacedSymbol::new("nine", "ten")),
|
||||||
Value::Boolean(false),
|
Value::Boolean(true),
|
||||||
Value::Nil,
|
Value::Boolean(false),
|
||||||
Value::Float(OrderedFloat(f64::NAN)),
|
Value::Nil,
|
||||||
Value::Float(OrderedFloat(f64::NEG_INFINITY)),
|
Value::Float(OrderedFloat(f64::NAN)),
|
||||||
Value::Float(OrderedFloat(f64::INFINITY)),
|
Value::Float(OrderedFloat(f64::NEG_INFINITY)),
|
||||||
]
|
Value::Float(OrderedFloat(f64::INFINITY)),
|
||||||
).to_string());
|
]);
|
||||||
|
|
||||||
|
assert_eq!(string, data.to_string());
|
||||||
|
assert_eq!(string, parse::value(&data.to_string()).unwrap().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue