Browse Source

Move sample code to test block

Getty Ritter 4 years ago
parent
commit
e47c999f79
1 changed files with 21 additions and 16 deletions
  1. 21 16
      src/lib.rs

+ 21 - 16
src/lib.rs

@@ -1,16 +1,4 @@
-use specs::join::Join;
-
-struct Pos {
-    x: usize,
-}
-impl specs::Component for Pos {
-    type Storage = specs::VecStorage<Pos>;
-}
-struct Mov;
-impl specs::Component for Mov {
-    type Storage = specs::VecStorage<Mov>;
-}
-
+#[macro_export]
 macro_rules! system {
     ($name:ident $pat:tt => $block:block ) => {
         struct $name;
@@ -70,7 +58,24 @@ macro_rules! args_to_join {
     };
 }
 
-system!{ Foo (_x: Mov, mut y: Pos) => {
-    y.x += 1;
-}
+#[cfg(test)]
+mod tests {
+    use specs::join::Join;
+
+    struct Pos {
+        x: usize,
+    }
+    impl specs::Component for Pos {
+        type Storage = specs::VecStorage<Pos>;
+    }
+
+    struct Mov;
+    impl specs::Component for Mov {
+        type Storage = specs::VecStorage<Mov>;
+    }
+
+    system!{ Foo (_x: Mov, mut y: Pos) => {
+        y.x += 1;
+    }
+    }
 }