Beispiel #1
0
 public void User_defined_words_can_override_built_in_words()
 {
     Assert.Equal("1 1", Forth.Evaluate(new[] { ": swap dup ;", "1 swap" }));
 }
Beispiel #2
0
 public void Over_copies_the_second_element_if_there_are_more_than_two()
 {
     Assert.Equal("1 2 3 2", Forth.Evaluate(new[] { "1 2 3 over" }));
 }
Beispiel #3
0
 public void User_defined_words_can_consist_of_built_in_words()
 {
     Assert.Equal("1 1 1", Forth.Evaluate(new[] { ": dup-twice dup dup ;", "1 dup-twice" }));
 }
Beispiel #4
0
 public void Drop_removes_the_top_value_on_the_stack_if_it_is_not_the_only_one()
 {
     Assert.Equal("1", Forth.Evaluate(new[] { "1 2 drop" }));
 }
Beispiel #5
0
 public void Swap_swaps_the_top_two_values_on_the_stack_if_they_are_not_the_only_ones()
 {
     Assert.Equal("1 3 2", Forth.Evaluate(new[] { "1 2 3 swap" }));
 }
Beispiel #6
0
 public void Division_errors_if_dividing_by_zero()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "4 0 /" }));
 }
Beispiel #7
0
 public void Combined_arithmetic_multiplication_and_division()
 {
     Assert.Equal("2", Forth.Evaluate(new[] { "2 4 * 3 /" }));
 }
Beispiel #8
0
 public void Case_insensitivity_dup_is_case_insensitive()
 {
     Assert.Equal("1 1 1 1", Forth.Evaluate(new[] { "1 DUP Dup dup" }));
 }
Beispiel #9
0
 public void Case_insensitivity_drop_is_case_insensitive()
 {
     Assert.Equal("1", Forth.Evaluate(new[] { "1 2 3 4 DROP Drop drop" }));
 }
Beispiel #10
0
 public void User_defined_words_cannot_redefine_numbers()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { ": 1 2 ;" }));
 }
Beispiel #11
0
 public void User_defined_words_errors_if_executing_a_non_existent_word()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "foo" }));
 }
Beispiel #12
0
 public void User_defined_words_can_define_word_that_uses_word_with_the_same_name()
 {
     Assert.Equal("11", Forth.Evaluate(new[] { ": foo 10 ;", ": foo foo 1 + ;", "foo" }));
 }
Beispiel #13
0
 public void User_defined_words_can_use_different_words_with_the_same_name()
 {
     Assert.Equal("5 6", Forth.Evaluate(new[] { ": foo 5 ;", ": bar foo ;", ": foo 6 ;", "bar foo" }));
 }
Beispiel #14
0
 public void User_defined_words_can_override_built_in_operators()
 {
     Assert.Equal("12", Forth.Evaluate(new[] { ": + * ;", "3 4 +" }));
 }
Beispiel #15
0
 public void Division_performs_integer_division()
 {
     Assert.Equal("2", Forth.Evaluate(new[] { "8 3 /" }));
 }
Beispiel #16
0
 public void Case_insensitivity_swap_is_case_insensitive()
 {
     Assert.Equal("2 3 4 1", Forth.Evaluate(new[] { "1 2 SWAP 3 Swap 4 swap" }));
 }
Beispiel #17
0
 public void Parsing_and_numbers_numbers_just_get_pushed_onto_the_stack()
 {
     Assert.Equal("1 2 3 4 5", Forth.Evaluate(new[] { "1 2 3 4 5" }));
 }
Beispiel #18
0
 public void Case_insensitivity_over_is_case_insensitive()
 {
     Assert.Equal("1 2 1 2 1", Forth.Evaluate(new[] { "1 2 OVER Over over" }));
 }
Beispiel #19
0
 public void Combined_arithmetic_addition_and_subtraction()
 {
     Assert.Equal("-1", Forth.Evaluate(new[] { "1 2 + 4 -" }));
 }
Beispiel #20
0
 public void Case_insensitivity_user_defined_words_are_case_insensitive()
 {
     Assert.Equal("1 1 1 1", Forth.Evaluate(new[] { ": foo dup ;", "1 FOO Foo foo" }));
 }
Beispiel #21
0
 public void Dup_copies_the_top_value_on_the_stack()
 {
     Assert.Equal("1 2 2", Forth.Evaluate(new[] { "1 2 dup" }));
 }
Beispiel #22
0
 public void Case_insensitivity_definitions_are_case_insensitive()
 {
     Assert.Equal("1 1 1 1", Forth.Evaluate(new[] { ": SWAP DUP Dup dup ;", "1 swap" }));
 }
Beispiel #23
0
 public void Addition_can_add_two_numbers()
 {
     Assert.Equal("3", Forth.Evaluate(new[] { "1 2 +" }));
 }
Beispiel #24
0
 public void Subtraction_can_subtract_two_numbers()
 {
     Assert.Equal("-1", Forth.Evaluate(new[] { "3 4 -" }));
 }
Beispiel #25
0
 public void Over_copies_the_second_element_if_there_are_only_two()
 {
     Assert.Equal("1 2 1", Forth.Evaluate(new[] { "1 2 over" }));
 }
Beispiel #26
0
 public void Multiplication_can_multiply_two_numbers()
 {
     Assert.Equal("8", Forth.Evaluate(new[] { "2 4 *" }));
 }
Beispiel #27
0
 public void Over_errors_if_there_is_only_one_value_on_the_stack()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "1 over" }));
 }
Beispiel #28
0
 public void Division_can_divide_two_numbers()
 {
     Assert.Equal("4", Forth.Evaluate(new[] { "12 3 /" }));
 }
Beispiel #29
0
 public void Addition_errors_if_there_is_nothing_on_the_stack()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "+" }));
 }
Beispiel #30
0
 public void User_defined_words_can_override_other_user_defined_words()
 {
     Assert.Equal("1 1 1", Forth.Evaluate(new[] { ": foo dup ;", ": foo dup dup ;", "1 foo" }));
 }