Esempio n. 1
0
// SetupExecutionEnvironment initializes the REPL session and set of tmp files.
func SetupExecutionEnvironment() {

	var err error
	REPLSession, err = repl.NewSession()
	if err != nil {
		panic(err)
	}

	fset = token.NewFileSet()
}
Esempio n. 2
0
// TestRun_Const tests a constant within the replpkg
func TestRun_Const(t *testing.T) {
	s, err := repl.NewSession()
	noError(t, err)

	codes := []string{
		`const ( a = iota; b )`,
		`a`,
		`b`,
	}

	for _, code := range codes {
		_, _, err := s.Eval(code)
		noError(t, err)
	}
}
Esempio n. 3
0
// TestRun_QuickFix_used_as_value tests assignment of values to variables
// and subsequent use
func TestRun_QuickFix_used_as_value(t *testing.T) {
	s, err := repl.NewSession()
	noError(t, err)

	codes := []string{
		`:import log`,
		`a := 1`,
		`log.SetPrefix("")`,
	}

	for _, code := range codes {
		_, _, err := s.Eval(code)
		noError(t, err)
	}
}
Esempio n. 4
0
// TestRun_import tests importing and use of a package
func TestRun_import(t *testing.T) {
	s, err := repl.NewSession()
	noError(t, err)

	codes := []string{
		":import encoding/json",
		"b, err := json.Marshal(nil)",
		"string(b)",
	}

	for _, code := range codes {
		_, _, err := s.Eval(code)
		noError(t, err)
	}
}
Esempio n. 5
0
// TestRun_Copy tests a copy within the replpkg
func TestRun_Copy(t *testing.T) {
	s, err := repl.NewSession()
	noError(t, err)

	codes := []string{
		`a := []string{"hello", "world"}`,
		`b := []string{"goodbye", "world"}`,
		`copy(a, b)`,
		`if (a[0] != "goodbye") {
			panic("should be copied")
		}`,
	}

	for _, code := range codes {
		_, _, err := s.Eval(code)
		noError(t, err)
	}
}
Esempio n. 6
0
// TestRun_QuickFix_evaluated_but_not_used makes sure errors are not thrown for
// evaluations of variables that aren't used
func TestRun_QuickFix_evaluated_but_not_used(t *testing.T) {
	s, err := repl.NewSession()
	noError(t, err)

	codes := []string{
		`[]byte("")`,
		`make([]int, 0)`,
		`1+1`,
		`func() {}`,
		`(4 & (1 << 1))`,
		`1`,
	}

	for _, code := range codes {
		_, _, err := s.Eval(code)
		noError(t, err)
	}
}