@@ -1173,6 +1173,8 @@ mod test {
1173
1173
CallToEmitEnumVariantArg(uint),
1174
1174
CallToEmitUint(uint),
1175
1175
CallToEmitNil,
1176
+ CallToEmitStruct(~str,uint),
1177
+ CallToEmitField(~str,uint),
1176
1178
// all of the ones I was too lazy to handle:
1177
1179
CallToOther
1178
1180
}
@@ -1251,11 +1253,11 @@ mod test {
1251
1253
fn emit_rec(&self, f: fn()) {
1252
1254
self.add_unknown_to_log(); f();
1253
1255
}
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();
1256
1258
}
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();
1259
1261
}
1260
1262
1261
1263
fn emit_tup(&self, +_len: uint, f: fn()) {
@@ -1267,23 +1269,12 @@ mod test {
1267
1269
}
1268
1270
1269
1271
1270
- #[auto_decode]
1271
- #[auto_encode]
1272
- struct Node {id: uint}
1273
-
1274
1272
fn to_call_log (val: Encodable<TestEncoder>) -> ~[call] {
1275
1273
let mut te = TestEncoder {call_log: ~[]};
1276
1274
val.encode(&te);
1277
1275
te.call_log
1278
1276
}
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
+
1287
1278
#[auto_encode]
1288
1279
enum Written {
1289
1280
Book(uint,uint),
@@ -1300,4 +1291,17 @@ mod test {
1300
1291
CallToEmitEnumVariantArg (1),
1301
1292
CallToEmitUint (44)]);
1302
1293
}
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
+ }
1303
1307
}
0 commit comments