diff options
author | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 18:43:32 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 18:43:32 -0700 |
commit | 6e0701caa513e11f939899c4d6c258537796c0d3 (patch) | |
tree | 03bb4acf60952f0129969d7c7c283486a3a8d3ed /src | |
parent | 806a7bd93701d8634fc1cf011c8fa9b89fa80e43 (diff) | |
download | milf-rs-6e0701caa513e11f939899c4d6c258537796c0d3.tar.gz milf-rs-6e0701caa513e11f939899c4d6c258537796c0d3.zip |
Add a test for _ => - translation
Diffstat (limited to 'src')
-rw-r--r-- | src/serialization.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/serialization.rs b/src/serialization.rs index 94bd201..7c11fb5 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use std::mem; use std::fmt; -use std::str; use serialize; use {Value, Table, Array, String, Integer, Float, Boolean, Parser}; @@ -558,7 +557,7 @@ impl serialize::Decoder<DecodeError> for Decoder { let toml = match self.toml { Some(Table(ref mut table)) => { table.pop(&field) - .or_else(|| table.pop(&hyphenate(f_name))) + .or_else(|| table.pop(&f_name.replace("_", "-"))) }, ref found => return Err(self.mismatch("table", found)), }; @@ -698,10 +697,6 @@ impl serialize::Decoder<DecodeError> for Decoder { } } -fn hyphenate(string: &str) -> String { - str::replace(string, "_", "-") -} - impl fmt::Show for DecodeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(match self.kind { @@ -782,6 +777,20 @@ mod tests { } #[test] + fn smoke_hyphen() { + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Foo { a_b: int } + + let v = Foo { a_b: 2 }; + assert_eq!(encode!(v), map! { a_b: Integer(2) }); + assert_eq!(v, decode!(Table(encode!(v)))); + + let mut m = HashMap::new(); + m.insert("a-b".to_string(), Integer(2)); + assert_eq!(v, decode!(Table(encode!(v)))); + } + + #[test] fn nested() { #[deriving(Encodable, Decodable, PartialEq, Show)] struct Foo { a: int, b: Bar } |