Mercurial > touhou
comparison src/th06/ecl_vm.rs @ 695:f5b34a1c2707
ecl_vm: add a test for Call and Return.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 23 Aug 2019 02:30:57 +0200 |
parents | 14fddc27e6f5 |
children | 7ae576a418ff |
comparison
equal
deleted
inserted
replaced
694:3ff1af76e413 | 695:f5b34a1c2707 |
---|---|
954 | 954 |
955 _ => unimplemented!("{:?}", instruction) | 955 _ => unimplemented!("{:?}", instruction) |
956 } | 956 } |
957 } | 957 } |
958 } | 958 } |
959 | |
960 #[cfg(test)] | |
961 mod tests { | |
962 use super::*; | |
963 use crate::th06::anm0::Anm0; | |
964 use crate::th06::ecl::{Sub, CallSub, Rank}; | |
965 use crate::th06::enemy::{Game, Position}; | |
966 use std::io::{self, Read}; | |
967 use std::fs::File; | |
968 | |
969 fn setup() -> (Rc<RefCell<Game>>, Rc<RefCell<Enemy>>) { | |
970 let file = File::open("EoSD/ST/stg1enm.anm").unwrap(); | |
971 let mut file = io::BufReader::new(file); | |
972 let mut buf = vec![]; | |
973 file.read_to_end(&mut buf).unwrap(); | |
974 let anm0 = Anm0::from_slice(&buf).unwrap(); | |
975 let anm0 = Rc::new(RefCell::new(anm0)); | |
976 let prng = Rc::new(RefCell::new(Prng::new(0))); | |
977 let game = Game::new(prng, Rank::Easy); | |
978 let game = Rc::new(RefCell::new(game)); | |
979 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); | |
980 (game, enemy) | |
981 } | |
982 | |
983 #[test] | |
984 fn call_and_return() { | |
985 let (game, enemy) = setup(); | |
986 let ecl = Ecl { mains: vec![], subs: vec![ | |
987 Sub { instructions: vec![ | |
988 CallSub::new(0, Rank::Easy, SubInstruction::Call(1, 13, 12.)), | |
989 ]}, | |
990 Sub { instructions: vec![ | |
991 CallSub::new(0, Rank::Easy, SubInstruction::Noop()), | |
992 CallSub::new(1, Rank::Easy, SubInstruction::Return()), | |
993 ]}, | |
994 ]}; | |
995 let mut ecl_runner = EclRunner::new(&ecl, enemy, 0); | |
996 ecl_runner.run_frame(); | |
997 assert_eq!(ecl_runner.frame.ints1[0], 13); | |
998 assert_eq!(ecl_runner.frame.floats[0], 12.); | |
999 assert_eq!(ecl_runner.stack.len(), 1); | |
1000 ecl_runner.run_frame(); | |
1001 assert_eq!(ecl_runner.frame.ints1[0], 0); | |
1002 assert_eq!(ecl_runner.frame.floats[0], 0.); | |
1003 assert_eq!(ecl_runner.stack.len(), 0); | |
1004 } | |
1005 } |