Exemple #1
0
    public void dup()
    {
        Assert.Equal("1 1", Forth.Eval("1 DUP"));
        Assert.Equal("1 2 2", Forth.Eval("1 2 Dup"));

        var exception = Assert.Throws <ForthException>(() => Forth.Eval("dup"));

        Assert.Equal(ForthError.StackUnderflow, exception.Error);
    }
Exemple #2
0
    public void drop()
    {
        Assert.Equal("", Forth.Eval("1 drop"));
        Assert.Equal("1", Forth.Eval("1 2 drop"));

        var exception = Assert.Throws <ForthException>(() => Forth.Eval("drop"));

        Assert.Equal(ForthError.StackUnderflow, exception.Error);
    }
Exemple #3
0
    public void drop()
    {
        Assert.That(Forth.Eval("1 drop"), Is.EqualTo(""));
        Assert.That(Forth.Eval("1 2 drop"), Is.EqualTo("1"));

        var exception = Assert.Throws <ForthException>(() => Forth.Eval("drop"));

        Assert.That(exception.Error, Is.EqualTo(ForthError.StackUnderflow));
    }
Exemple #4
0
    public void dup()
    {
        Assert.That(Forth.Eval("1 DUP"), Is.EqualTo("1 1"));
        Assert.That(Forth.Eval("1 2 Dup"), Is.EqualTo("1 2 2"));

        var exception = Assert.Throws <ForthException>(() => Forth.Eval("dup"));

        Assert.That(exception.Error, Is.EqualTo(ForthError.StackUnderflow));
    }
Exemple #5
0
    public void over()
    {
        Assert.Equal("1 2 1", Forth.Eval("1 2 over"));
        Assert.Equal("1 2 3 2", Forth.Eval("1 2 3 over"));

        var exception1 = Assert.Throws <ForthException>(() => Forth.Eval("1 over"));

        Assert.Equal(ForthError.StackUnderflow, exception1.Error);

        var exception2 = Assert.Throws <ForthException>(() => Forth.Eval("over"));

        Assert.Equal(ForthError.StackUnderflow, exception2.Error);
    }
Exemple #6
0
    public void swap()
    {
        Assert.Equal("2 1", Forth.Eval("1 2 swap"));
        Assert.Equal("1 3 2", Forth.Eval("1 2 3 swap"));

        var exception1 = Assert.Throws <ForthException>(() => Forth.Eval("1 swap"));

        Assert.Equal(ForthError.StackUnderflow, exception1.Error);

        var exception2 = Assert.Throws <ForthException>(() => Forth.Eval("swap"));

        Assert.Equal(ForthError.StackUnderflow, exception2.Error);
    }
Exemple #7
0
    public void over()
    {
        Assert.That(Forth.Eval("1 2 over"), Is.EqualTo("1 2 1"));
        Assert.That(Forth.Eval("1 2 3 over"), Is.EqualTo("1 2 3 2"));

        var exception1 = Assert.Throws <ForthException>(() => Forth.Eval("1 over"));

        Assert.That(exception1.Error, Is.EqualTo(ForthError.StackUnderflow));

        var exception2 = Assert.Throws <ForthException>(() => Forth.Eval("over"));

        Assert.That(exception2.Error, Is.EqualTo(ForthError.StackUnderflow));
    }
Exemple #8
0
    public void swap()
    {
        Assert.That(Forth.Eval("1 2 swap"), Is.EqualTo("2 1"));
        Assert.That(Forth.Eval("1 2 3 swap"), Is.EqualTo("1 3 2"));

        var exception1 = Assert.Throws <ForthException>(() => Forth.Eval("1 swap"));

        Assert.That(exception1.Error, Is.EqualTo(ForthError.StackUnderflow));

        var exception2 = Assert.Throws <ForthException>(() => Forth.Eval("swap"));

        Assert.That(exception2.Error, Is.EqualTo(ForthError.StackUnderflow));
    }
Exemple #9
0
 public void Redefining_an_existing_built_in_word()
 {
     Assert.That(Forth.Eval(": swap dup ; 1 swap"), Is.EqualTo("1 1"));
 }
Exemple #10
0
    public void Division_by_zero()
    {
        var exception = Assert.Throws <ForthException>(() => Forth.Eval("4 2 2 - /"));

        Assert.That(exception.Error, Is.EqualTo(ForthError.DivisionByZero));
    }
Exemple #11
0
 public void Basic_arithmetic()
 {
     Assert.That(Forth.Eval("1 2 + 4 -"), Is.EqualTo("-1"));
     Assert.That(Forth.Eval("2 4 * 3 /"), Is.EqualTo("2"));
 }
Exemple #12
0
 public void Non_word_characters_are_separators()
 {
     Assert.That(Forth.Eval("1\v2\t3\n4\r5 6\t7"), Is.EqualTo("1 2 3 4 5 6 7"));
 }
Exemple #13
0
    public void Calling_a_non_existing_word()
    {
        var exception = Assert.Throws <ForthException>(() => Forth.Eval("1 foo"));

        Assert.That(exception.Error, Is.EqualTo(ForthError.UnknownWord));
    }
Exemple #14
0
 public void No_input()
 {
     Assert.Equal("", Forth.Eval(""));
 }
Exemple #15
0
 public void Defining_a_new_word()
 {
     Assert.That(Forth.Eval(": dup-twice dup dup ; 1 dup-twice"), Is.EqualTo("1 1 1"));
 }
Exemple #16
0
 public void Defining_a_new_word()
 {
     Assert.Equal("1 1 1", Forth.Eval(": dup-twice dup dup ; 1 dup-twice"));
 }
Exemple #17
0
 public void Redefining_an_existing_word()
 {
     Assert.Equal("1 1 1", Forth.Eval(": foo dup ; : foo dup dup ; 1 foo"));
 }
Exemple #18
0
 public void No_input()
 {
     Assert.That(Forth.Eval(""), Is.EqualTo(""));
 }
Exemple #19
0
 public void Defining_words_with_odd_characters()
 {
     Assert.That(Forth.Eval(": € 220371 ; €"), Is.EqualTo("220371"));
 }
Exemple #20
0
 public void Numbers_just_get_pushed_onto_the_stack()
 {
     Assert.That(Forth.Eval("1 2 3 4 5"), Is.EqualTo("1 2 3 4 5"));
 }
Exemple #21
0
    public void Defining_a_number()
    {
        var exception = Assert.Throws <ForthException>(() => Forth.Eval(": 1 2 ;"));

        Assert.That(exception.Error, Is.EqualTo(ForthError.InvalidWord));
    }
Exemple #22
0
 public void Redefining_an_existing_word()
 {
     Assert.That(Forth.Eval(": foo dup ; : foo dup dup ; 1 foo"), Is.EqualTo("1 1 1"));
 }
Exemple #23
0
 public void Basic_arithmetic()
 {
     Assert.Equal("-1", Forth.Eval("1 2 + 4 -"));
     Assert.Equal("2", Forth.Eval("2 4 * 3 /"));
 }