diff options
| author | bors <bors@rust-lang.org> | 2013-02-26 20:00:38 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-02-26 20:00:38 -0800 |
| commit | 99a902c81d7bc57fece1b520591f328afe76154a (patch) | |
| tree | feb170d7d7bbae635fa641076ab97d1b3fbc9e14 /src/libsyntax/ext/auto_encode.rs | |
| parent | 28b50a48927db9408060d141b8dcb3a830272365 (diff) | |
| parent | 6aefaf22c758b76703ed850bcf817dda127a5d67 (diff) | |
| download | rust-99a902c81d7bc57fece1b520591f328afe76154a.tar.gz rust-99a902c81d7bc57fece1b520591f328afe76154a.zip | |
auto merge of #5120 : jbclements/rust/macros-have-scope, r=pcwalton
r? After this patch, macros declared in a module, function, or block can only be used inside of that module, function or block, with the exception of modules declared with the #[macro_escape] attribute; these modules allow macros to escape, and can be used as a limited macro export mechanism. This pull request also includes miscellaneous comments, lots of new test cases, a few renamings, and a few as-yet-unused data definitions for hygiene.
Diffstat (limited to 'src/libsyntax/ext/auto_encode.rs')
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index b345b116425..0019acc1291 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1173,6 +1173,8 @@ mod test { CallToEmitEnumVariantArg(uint), CallToEmitUint(uint), CallToEmitNil, + CallToEmitStruct(~str,uint), + CallToEmitField(~str,uint), // all of the ones I was too lazy to handle: CallToOther } @@ -1251,11 +1253,11 @@ mod test { fn emit_rec(&self, f: fn()) { self.add_unknown_to_log(); f(); } - fn emit_struct(&self, _name: &str, +_len: uint, f: fn()) { - self.add_unknown_to_log(); f(); + fn emit_struct(&self, name: &str, +len: uint, f: fn()) { + self.add_to_log(CallToEmitStruct (name.to_str(),len)); f(); } - fn emit_field(&self, _name: &str, +_idx: uint, f: fn()) { - self.add_unknown_to_log(); f(); + fn emit_field(&self, name: &str, +idx: uint, f: fn()) { + self.add_to_log(CallToEmitField (name.to_str(),idx)); f(); } fn emit_tup(&self, +_len: uint, f: fn()) { @@ -1267,23 +1269,12 @@ mod test { } - #[auto_decode] - #[auto_encode] - struct Node {id: uint} - fn to_call_log (val: Encodable<TestEncoder>) -> ~[call] { let mut te = TestEncoder {call_log: @mut ~[]}; val.encode(&te); copy *te.call_log } -/* - #[test] fn encode_test () { - check_equal (to_call_log(Node{id:34} - as Encodable::<std::json::Encoder>), - ~[CallToEnum (~"Node"), - CallToEnumVariant]); - } -*/ + #[auto_encode] enum Written { Book(uint,uint), @@ -1300,4 +1291,17 @@ mod test { CallToEmitEnumVariantArg (1), CallToEmitUint (44)]); } + + pub enum BPos = uint; + + #[auto_encode] + pub struct HasPos { pos : BPos } + + #[test] fn encode_newtype_test () { + check_equal (to_call_log (HasPos {pos:BPos(48)} + as Encodable::<TestEncoder>), + ~[CallToEmitStruct(~"HasPos",1), + CallToEmitField(~"pos",0), + CallToEmitUint(48)]); + } } |
