Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions exercises/forth/tests/forth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unused_must_use)]

extern crate forth;

use forth::{Forth, Error};
Expand All @@ -13,7 +11,7 @@ fn no_input_no_stack() {
#[ignore]
fn numbers_just_get_pushed_onto_the_stack() {
let mut f = Forth::new();
f.eval("1 2 3 4 5 -1");
assert!(f.eval("1 2 3 4 5 -1").is_ok());
assert_eq!("1 2 3 4 5 -1", f.format_stack());
}

Expand All @@ -22,23 +20,23 @@ fn numbers_just_get_pushed_onto_the_stack() {
fn non_word_characters_are_separators() {
let mut f = Forth::new();
// Note the Ogham Space Mark ( ), this is a spacing character.
f.eval("1\u{0000}2\u{0001}3\n4\r5 6\t7");
assert!(f.eval("1\u{0000}2\u{0001}3\n4\r5 6\t7").is_ok());
assert_eq!("1 2 3 4 5 6 7", f.format_stack());
}

#[test]
#[ignore]
fn basic_arithmetic_1() {
let mut f = Forth::new();
f.eval("1 2 + 4 -");
assert!(f.eval("1 2 + 4 -").is_ok());
assert_eq!("-1", f.format_stack());
}

#[test]
#[ignore]
fn basic_arithmetic_2() {
let mut f = Forth::new();
f.eval("2 4 * 3 /");
assert!(f.eval("2 4 * 3 /").is_ok());
assert_eq!("2", f.format_stack());
}

Expand Down Expand Up @@ -96,15 +94,15 @@ fn division_by_zero() {
#[ignore]
fn dup() {
let mut f = Forth::new();
f.eval("1 DUP");
assert!(f.eval("1 DUP").is_ok());
assert_eq!("1 1", f.format_stack());
}

#[test]
#[ignore]
fn dup_case_insensitive() {
let mut f = Forth::new();
f.eval("1 Dup");
assert!(f.eval("1 Dup").is_ok());
assert_eq!("1 1", f.format_stack());
}

Expand All @@ -122,15 +120,15 @@ fn dup_error() {
#[ignore]
fn drop() {
let mut f = Forth::new();
f.eval("1 drop");
assert!(f.eval("1 drop").is_ok());
assert_eq!("", f.format_stack());
}

#[test]
#[ignore]
fn drop_with_two() {
let mut f = Forth::new();
f.eval("1 2 drop");
assert!(f.eval("1 2 drop").is_ok());
assert_eq!("1", f.format_stack());
}

Expand All @@ -148,15 +146,15 @@ fn drop_error() {
#[ignore]
fn swap() {
let mut f = Forth::new();
f.eval("1 2 swap");
assert!(f.eval("1 2 swap").is_ok());
assert_eq!("2 1", f.format_stack());
}

#[test]
#[ignore]
fn swap_with_three() {
let mut f = Forth::new();
f.eval("1 2 3 swap");
assert!(f.eval("1 2 3 swap").is_ok());
assert_eq!("1 3 2", f.format_stack());
}

Expand All @@ -178,15 +176,15 @@ fn swap_error() {
#[ignore]
fn over() {
let mut f = Forth::new();
f.eval("1 2 over");
assert!(f.eval("1 2 over").is_ok());
assert_eq!("1 2 1", f.format_stack());
}

#[test]
#[ignore]
fn over_with_three() {
let mut f = Forth::new();
f.eval("1 2 3 over");
assert!(f.eval("1 2 3 over").is_ok());
assert_eq!("1 2 3 2", f.format_stack());
}

Expand All @@ -208,35 +206,35 @@ fn over_error() {
#[ignore]
fn defining_a_new_word() {
let mut f = Forth::new();
f.eval(": CoUnT 1 2 3 ;");
f.eval("count COUNT");
assert!(f.eval(": CoUnT 1 2 3 ;").is_ok());
assert!(f.eval("count COUNT").is_ok());
assert_eq!("1 2 3 1 2 3", f.format_stack());
}

#[test]
#[ignore]
fn redefining_an_existing_word() {
let mut f = Forth::new();
f.eval(": foo dup ;");
f.eval(": foo dup dup ;");
f.eval("1 foo");
assert!(f.eval(": foo dup ;").is_ok());
assert!(f.eval(": foo dup dup ;").is_ok());
assert!(f.eval("1 foo").is_ok());
assert_eq!("1 1 1", f.format_stack());
}

#[test]
#[ignore]
fn redefining_an_existing_built_in_word() {
let mut f = Forth::new();
f.eval(": swap dup ;");
f.eval("1 swap");
assert!(f.eval(": swap dup ;").is_ok());
assert!(f.eval("1 swap").is_ok());
assert_eq!("1 1", f.format_stack());
}

#[test]
#[ignore]
fn defining_words_with_odd_characters() {
let mut f = Forth::new();
f.eval(": € 220371 ; €");
assert!(f.eval(": € 220371 ; €").is_ok());
assert_eq!("220371", f.format_stack());
}

Expand Down