Skip to content

Commit 5e319fb

Browse files
committed
Adds (more) test cases for auto_encode.
1 parent 5328f3c commit 5e319fb

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/libsyntax/ext/auto_encode.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ mod test {
11731173
CallToEmitEnumVariantArg(uint),
11741174
CallToEmitUint(uint),
11751175
CallToEmitNil,
1176+
CallToEmitStruct(~str,uint),
1177+
CallToEmitField(~str,uint),
11761178
// all of the ones I was too lazy to handle:
11771179
CallToOther
11781180
}
@@ -1251,11 +1253,11 @@ mod test {
12511253
fn emit_rec(&self, f: fn()) {
12521254
self.add_unknown_to_log(); f();
12531255
}
1254-
fn emit_struct(&self, _name: &str, +_len: uint, f: fn()) {
1255-
self.add_unknown_to_log(); f();
1256+
fn emit_struct(&self, name: &str, +len: uint, f: fn()) {
1257+
self.add_to_log(CallToEmitStruct (name.to_str(),len)); f();
12561258
}
1257-
fn emit_field(&self, _name: &str, +_idx: uint, f: fn()) {
1258-
self.add_unknown_to_log(); f();
1259+
fn emit_field(&self, name: &str, +idx: uint, f: fn()) {
1260+
self.add_to_log(CallToEmitField (name.to_str(),idx)); f();
12591261
}
12601262
12611263
fn emit_tup(&self, +_len: uint, f: fn()) {
@@ -1267,23 +1269,12 @@ mod test {
12671269
}
12681270
12691271
1270-
#[auto_decode]
1271-
#[auto_encode]
1272-
struct Node {id: uint}
1273-
12741272
fn to_call_log (val: Encodable<TestEncoder>) -> ~[call] {
12751273
let mut te = TestEncoder {call_log: ~[]};
12761274
val.encode(&te);
12771275
te.call_log
12781276
}
1279-
/*
1280-
#[test] fn encode_test () {
1281-
check_equal (to_call_log(Node{id:34}
1282-
as Encodable::<std::json::Encoder>),
1283-
~[CallToEnum (~"Node"),
1284-
CallToEnumVariant]);
1285-
}
1286-
*/
1277+
12871278
#[auto_encode]
12881279
enum Written {
12891280
Book(uint,uint),
@@ -1300,4 +1291,17 @@ mod test {
13001291
CallToEmitEnumVariantArg (1),
13011292
CallToEmitUint (44)]);
13021293
}
1294+
1295+
pub enum BPos = uint;
1296+
1297+
#[auto_encode]
1298+
pub struct HasPos { pos : BPos }
1299+
1300+
#[test] fn encode_newtype_test () {
1301+
check_equal (to_call_log (HasPos {pos:BPos(48)}
1302+
as Encodable::<TestEncoder>),
1303+
~[CallToEmitStruct(~"HasPos",1),
1304+
CallToEmitField(~"pos",0),
1305+
CallToEmitUint(48)]);
1306+
}
13031307
}

0 commit comments

Comments
 (0)