提交 f91160b6 编写于 作者: J John Clements

json add enum encoder test case

上级 0e9495b9
......@@ -133,7 +133,8 @@ fn emit_enum_variant(&self, name: &str, _id: uint, _cnt: uint, f: fn()) {
f();
self.wr.write_char(']');
}
fn emit_enum_variant_arg(&self, idx: uint, f: fn()) {
fn emit_enum_variant_arg(&self, _idx: uint, f: fn()) {
self.wr.write_char(',');
f();
}
......@@ -1182,6 +1183,8 @@ mod tests {
use core::result;
use core::hashmap::linear::LinearMap;
use core::cmp;
fn mk_object(items: &[(~str, Json)]) -> Json {
let mut d = ~LinearMap::new();
......@@ -1249,6 +1252,43 @@ fn test_write_object() {
assert a == b;
}
// two fns copied from libsyntax/util/testing.rs.
// Should they be in their own crate?
pub pure fn check_equal_ptr<T : cmp::Eq> (given : &T, expected: &T) {
if !((given == expected) && (expected == given )) {
die!(fmt!("given %?, expected %?",given,expected));
}
}
pub pure fn check_equal<T : cmp::Eq> (given : T, expected: T) {
if !((given == expected) && (expected == given )) {
die!(fmt!("given %?, expected %?",given,expected));
}
}
// testing both auto_encode's calling patterns
// and json... not sure where to put these tests.
#[test]
fn test_write_enum () {
let bw = @io::BytesWriter {bytes: dvec::DVec(), pos: 0};
let bww : @io::Writer = (bw as @io::Writer);
let encoder = (@Encoder(bww) as @serialize::Encoder);
do encoder.emit_enum(~"animal") {
do encoder.emit_enum_variant (~"frog",37,1242) {
// name of frog:
do encoder.emit_enum_variant_arg (0) {
encoder.emit_owned_str(~"Henry")
}
// mass of frog in grams:
do encoder.emit_enum_variant_arg (1) {
encoder.emit_int(349);
}
}
}
check_equal(str::from_bytes(bw.bytes.data),
~"[\"frog\",\"Henry\",349]");
}
#[test]
fn test_trailing_characters() {
assert from_str(~"nulla") ==
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册