<commit_before>// Copyright 2014 SteelSeries ApS.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file tests function evaluation.

package golisp

import (
	. "launchpad.net/gocheck"
)

type EvalSuite struct {
}

var _ = Suite(&EvalSuite{})

func (s *EvalSuite) SetUpSuite(c *C) {
	Global = NewSymbolTableFrameBelow(nil)
	InitBuiltins()
}

func (s *EvalSuite) TestEvalWithNilFunction(c *C) {
	code, _ := Parse("(no-function-named-this)")
	result, err := Eval(code, Global)
	c.Assert(err, NotNil)
	c.Assert(result, IsNil)
}

func (s *EvalSuite) TestEvalWithOverridingSearchEnv(c *C) {
	newEnv := NewSymbolTableFrameBelow(Global)
	sym := SymbolWithName("test")
	code, _ := Parse("test")
	Global.BindLocallyTo(sym, IntegerWithValue(10))
	newEnv.BindLocallyTo(sym, IntegerWithValue(42))
	globalVal, _ := Eval(code, Global)
	c.Assert(IntegerValue(globalVal), Equals, int64(10))
	newEnvVal, _ := Eval(code, Global, newEnv)
	c.Assert(IntegerValue(newEnvVal), Equals, int64(42))
}<commit_msg>Add a test for indirect evaluation<commit_after>// Copyright 2014 SteelSeries ApS.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file tests function evaluation.

package golisp

import (
	. "launchpad.net/gocheck"
)

type EvalSuite struct {
}

var _ = Suite(&EvalSuite{})

func (s *EvalSuite) SetUpSuite(c *C) {
	Global = NewSymbolTableFrameBelow(nil)
	InitBuiltins()
}

func (s *EvalSuite) TestEvalWithNilFunction(c *C) {
	code, _ := Parse("(no-function-named-this)")
	result, err := Eval(code, Global)
	c.Assert(err, NotNil)
	c.Assert(result, IsNil)
}

func (s *EvalSuite) TestEvalWithOverridingSearchEnv(c *C) {
	newEnv := NewSymbolTableFrameBelow(Global)
	sym := SymbolWithName("test")
	code, _ := Parse("test")
	Global.BindLocallyTo(sym, IntegerWithValue(10))
	newEnv.BindLocallyTo(sym, IntegerWithValue(42))
	globalVal, _ := Eval(code, Global)
	c.Assert(IntegerValue(globalVal), Equals, int64(10))
	newEnvVal, _ := Eval(code, Global, newEnv)
	c.Assert(IntegerValue(newEnvVal), Equals, int64(42))
}

func (s *EvalSuite) TestIndirectEvalWithOverridingSearchEnv(c *C) {
	newEnv := NewSymbolTableFrameBelow(Global)
	sym := SymbolWithName("test")
	code, _ := Parse("(+ (* test 2) 1)")
	Global.BindLocallyTo(sym, IntegerWithValue(10))
	newEnv.BindLocallyTo(sym, IntegerWithValue(42))
	globalVal, _ := Eval(code, Global)
	c.Assert(IntegerValue(globalVal), Equals, int64(21))
	newEnvVal, _ := Eval(code, Global, newEnv)
	c.Assert(IntegerValue(newEnvVal), Equals, int64(85))
}
{'fraction_non_alphanumeric': 0.13158825610187477, 'fraction_numerical': 0.01627166607711355, 'mean_word_length': 5.45662100456621, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6664230', 'n_tokens_mistral': 1008, 'n_tokens_neox': 966, 'n_words': 250}