Example #1
0
func Test_evaluate_list(t *testing.T) {
	rt := minimalRuntime()
	rt.stack.Assign("blop", types.MakeFuString("bar"))
	elements := []dsl.ASTExpression{
		dsl.NewASTString("\"foo\""),
		dsl.NewASTName("blop"),
		dsl.NewASTString("\"baz\""),
	}
	astlist := dsl.NewASTList(elements)

	actual, errs := rt.evaluate(astlist)
	testutils.NoErrors(t, errs)
	expect := types.MakeStringList("foo", "bar", "baz")
	assert.Equal(t, expect, actual)
}
Example #2
0
func Test_evaluate_list_errors(t *testing.T) {
	rt := minimalRuntime()
	rt.stack.Assign("src", types.MakeFuString("foo.c"))
	elements := []dsl.ASTExpression{
		dsl.NewASTString("\"whee!\""),
		dsl.NewASTName("bogus"),
		dsl.NewASTName("src"),
		dsl.NewASTString("\"bop\""),
		dsl.NewASTName("morebogus"),
	}
	astlist := dsl.NewASTList(elements)

	actual, errs := rt.evaluate(astlist)
	if len(errs) != 2 {
		t.Fatalf("expected 2 errors, but got %d: %v", len(errs), errs)
	}
	assert.Equal(t, "name not defined: 'bogus'", errs[0].Error())
	assert.Equal(t, "name not defined: 'morebogus'", errs[1].Error())
	assert.Nil(t, actual)
}