~tim/scheme-vm

ref: f23168670146fb6810d3293d5539579fe261db4d scheme-vm/spec/lib/bool_spec.rb -rw-r--r-- 881 bytes
f2316867Tim Morgan Add boolean? predicate 6 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require_relative '../spec_helper'
require 'stringio'

describe 'Library' do
  let(:stdout) { StringIO.new }

  let(:subject) { Program.new(code, stdout: stdout) }

  before { subject.run }

  describe 'boolean?' do
    context 'given #t' do
      let(:code) do
        <<-END
          (boolean? #t)
        END
      end

      it 'returns #t' do
        expect(subject.vm.pop_val).to eq(VM::BoolTrue.instance)
      end
    end

    context 'given #f' do
      let(:code) do
        <<-END
          (boolean? #f)
        END
      end

      it 'returns #t' do
        expect(subject.vm.pop_val).to eq(VM::BoolTrue.instance)
      end
    end

    context 'given a list' do
      let(:code) do
        <<-END
          (boolean? (list))
        END
      end

      it 'returns #f' do
        expect(subject.vm.pop_val).to eq(VM::BoolFalse.instance)
      end
    end
  end
end