~tim/scheme-vm

acee0bd207aff6403c9a8045bcf594ab9993ee45 — Tim Morgan 5 years ago 4e835d9
Add specs for lambda arguments
3 files changed, 28 insertions(+), 2 deletions(-)

M lib/assert.scm
A spec/lib/lambda-spec.scm
M spec/lib_spec.rb
M lib/assert.scm => lib/assert.scm +10 -0
@@ 7,3 7,13 @@
          (print expected)
          (write "  actual:   ")
          (print actual)))))

(define assert-eqv
  (lambda (expected actual)
    (if (not (eqv? expected actual))
        (begin
          (print "assert-eq failed:")
          (write "  expected: ")
          (print expected)
          (write "  actual:   ")
          (print actual)))))

A spec/lib/lambda-spec.scm => spec/lib/lambda-spec.scm +17 -0
@@ 0,0 1,17 @@
(include "assert")

(define fixed-args
  (lambda (x y z)
    (list x y z)))

(define variable-args
  (lambda args
    args))

(define rest-args
  (lambda (x y . rest)
    (list x y rest)))

(assert-eqv (list 1 2 3) (fixed-args 1 2 3))
(assert-eqv (list 1 2 3) (variable-args 1 2 3))
(assert-eqv (list 1 2 (list 3 4)) (rest-args 1 2 3 4))

M spec/lib_spec.rb => spec/lib_spec.rb +1 -2
@@ 2,11 2,10 @@ require_relative './spec_helper'
require 'stringio'

describe 'Libs' do
  let(:out) { StringIO.new }

  it 'passes all tests' do
    failed = false
    Dir[File.expand_path('../lib/**/*.scm', __FILE__)].each do |path|
      out = StringIO.new
      Program.new(File.read(path), filename: File.split(path).last, stdout: out).run
      out.rewind
      result = out.read