commit bcf8045763e91d2ed0a2a023febd46618afc8fbf
parent e0295a53f9c157459246c4e60b2601602a32f403
Author: ~karx <karx@tilde.team>
Date: Tue, 9 Mar 2021 11:25:47 -0600
Move tests to seperate file
Diffstat:
M | src/main.rs | | | 59 | +---------------------------------------------------------- |
A | src/tests.rs | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 46 insertions(+), 58 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -212,61 +212,4 @@ fn main() {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- fn make_program(contents: &str) -> Program {
- Program::from_string(contents.to_string())
- }
-
- #[test]
- fn test_math() {
- assert_eq!(eval::do_math("2-2".to_string(), '+'), 4);
- }
-
- #[test]
- #[should_panic]
- fn test_undefined_opcode() {
- make_program("Hello\nWorld!").run();
- }
-
- #[test]
- #[should_panic]
- fn test_undefined_variable() {
- make_program("p$v").run();
- }
-
- #[test]
- #[should_panic]
- fn test_undefined_function() {
- make_program("p*x").run();
- }
-
- #[test]
- fn test_factory() {
- let prog = make_program("lhHello\nlwWorld\np$h $w");
- let vec_to_check: Vec<String> = vec!["lhHello", "lwWorld", "p$h $w"].into_iter().map(|s| s.to_string()).collect();
-
- assert_eq!(prog.data, vec_to_check);
- }
-
- #[test]
- fn test_args() {
- let mut prog = make_program("lhHello\nlwWorld\np$h $w");
- prog.run();
-
- let args_to_check: HashMap<char, String> = [('h', String::from("Hello")), ('w', String::from("World"))].iter().cloned().collect();
-
- assert_eq!(prog.vars, args_to_check);
- }
-
- #[test]
- fn test_funcs() {
- let mut prog = make_program("fxa10-10\nfys10-5\np*x *y");
- prog.run();
-
- let funcs_to_check: HashMap<char, String> = [('x', String::from("a10-10")), ('y', String::from("s10-5"))].iter().cloned().collect();
-
- assert_eq!(prog.funcs, funcs_to_check);
- }
-}
+mod tests;
diff --git a/src/tests.rs b/src/tests.rs
@@ -0,0 +1,45 @@
+use super::*;
+
+fn make_program(contents: &str) -> Program {
+ Program::from_string(contents.to_string())
+}
+#[test]
+fn test_math() {
+ assert_eq!(eval::do_math("2-2".to_string(), '+'), 4);
+}
+#[test]
+#[should_panic]
+fn test_undefined_opcode() {
+ make_program("Hello\nWorld!").run();
+}
+#[test]
+#[should_panic]
+fn test_undefined_variable() {
+ make_program("p$v").run();
+}
+#[test]
+#[should_panic]
+fn test_undefined_function() {
+ make_program("p*x").run();
+}
+#[test]
+fn test_factory() {
+ let prog = make_program("lhHello\nlwWorld\np$h $w");
+ let vec_to_check: Vec<String> = vec!["lhHello", "lwWorld", "p$h $w"].into_iter().map(|s| s.to_string()).collect();
+ assert_eq!(prog.data, vec_to_check);
+}
+#[test]
+fn test_args() {
+ let mut prog = make_program("lhHello\nlwWorld\np$h $w");
+ prog.run();
+ let args_to_check: HashMap<char, String> = [('h', String::from("Hello")), ('w', String::from("World"))].iter().cloned().collect();
+ assert_eq!(prog.vars, args_to_check);
+}
+
+#[test]
+fn test_funcs() {
+ let mut prog = make_program("fxa10-10\nfys10-5\np*x *y");
+ prog.run();
+ let funcs_to_check: HashMap<char, String> = [('x', String::from("a10-10")), ('y', String::from("s10-5"))].iter().cloned().collect();
+ assert_eq!(prog.funcs, funcs_to_check);
+}