<commit_before>// Copyright 2013 Masterminds

// This package provides the execution context for a Cookoo request.
package context

import (
	"github.com/bmizerany/assert"
	"testing"
	"fmt"
)

// An example datasource as can add to our store.
type ExampleDatasource struct {
	name string
}

func TestDatasource(t *testing.T) {
	foo := new(ExampleDatasource)
	foo.name = "bar"

	cxt := NewExecutionContext()

	cxt.AddDatasource("foo", foo)

	foo2 := cxt.Datasource("foo").(*ExampleDatasource)

	assert.Equal(t, foo, foo2)
	assert.Equal(t, "bar", foo2.name)
}

func TestAddGet(t *testing.T) {
	cxt := NewExecutionContext()

	cxt.Add("test1", 42)
	cxt.Add("test2", "Geronimo!")
	cxt.Add("test3", func()string{return "Hello"})

	// Test Get
	assert.Equal(t, 42, cxt.Get("test1"))
	assert.Equal(t, "Geronimo!", cxt.Get("test2"))

	// Test has
	val, ok := cxt.Has("test1")
	if !ok {
		t.Error("! Failed to get 'test1'")
	}
	assert.Equal(t, 42, cxt.Get("test1"))

	_, ok = cxt.Has("test999")
	if ok {
		t.Error("! Unexpected result for 'test999'")
	}

	val, ok = cxt.Get("test3").(func()string)
	if ok {
		fmt.Println(val)
	} else {
		t.Error("! Expected a function.")
	}

}<commit_msg>Updated context_test.<commit_after>// Copyright 2013 Masterminds

// This package provides the execution context for a Cookoo request.
package context

import (
	"github.com/bmizerany/assert"
	"testing"
	//"fmt"
	"reflect"
)

// An example datasource as can add to our store.
type ExampleDatasource struct {
	name string
}

func TestDatasource(t *testing.T) {
	foo := new(ExampleDatasource)
	foo.name = "bar"

	cxt := NewExecutionContext()

	cxt.AddDatasource("foo", foo)

	foo2 := cxt.Datasource("foo").(*ExampleDatasource)

	assert.Equal(t, foo, foo2)
	assert.Equal(t, "bar", foo2.name)
}

func TestAddGet(t *testing.T) {
	cxt := NewExecutionContext()

	cxt.Add("test1", 42)
	cxt.Add("test2", "Geronimo!")
	cxt.Add("test3", func()string{return "Hello"})

	// Test Get
	assert.Equal(t, 42, cxt.Get("test1"))
	assert.Equal(t, "Geronimo!", cxt.Get("test2"))

	// Test has
	val, ok := cxt.Has("test1")
	if !ok {
		t.Error("! Failed to get 'test1'")
	}
	assert.Equal(t, 42, cxt.Get("test1"))

	_, ok = cxt.Has("test999")
	if ok {
		t.Error("! Unexpected result for 'test999'")
	}

	val, ok = cxt.Get("test3").(func()string)
	fn := val
	if ok {
		assert.Equal(t, 1,  fn());
	} else {
		t.Error("! Expected a function.")
	}

}
{'fraction_non_alphanumeric': 0.17833333333333334, 'fraction_numerical': 0.02375, 'mean_word_length': 4.044117647058823, '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': '3727369', 'n_tokens_mistral': 1008, 'n_tokens_neox': 949, 'n_words': 222}