123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /*
- * ECAL
- *
- * Copyright 2020 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the MIT
- * License, If a copy of the MIT License was not distributed with this
- * file, You can obtain one at https://opensource.org/licenses/MIT.
- */
- package main
- import (
- "bytes"
- "fmt"
- "io/ioutil"
- "os"
- "testing"
- )
- const InvalidFileName = "**" + string(0x0)
- func TestGenerate(t *testing.T) {
- filename = InvalidFileName
- var buf bytes.Buffer
- stderrPrint = func(v ...interface{}) (int, error) {
- buf.WriteString(fmt.Sprint(v...))
- return 0, nil
- }
- stdoutPrint = func(v ...interface{}) (int, error) {
- return 0, nil
- }
- main()
- if buf.String() != "Error:open **"+string(0)+": invalid argument" {
- t.Error("Unexpected output:", buf.String())
- return
- }
- filename = "test_out.txt"
- pkgNames = map[string][]string{
- "math": {"Pi"},
- "fmt": {"Println"},
- }
- defer func() {
- os.Remove(filename)
- }()
- main()
- out, err := ioutil.ReadFile(filename)
- if err != nil {
- t.Error("Could not read file:", filename, " ", err)
- return
- }
- if string(out) != `
- // Code generated by ecal/stdlib/generate; DO NOT EDIT.
- package stdlib
- import (
- "fmt"
- "math"
- "reflect"
- )
- /*
- genStdlib contains all generated stdlib constructs.
- */
- var genStdlib = map[interface{}]interface{}{
- "fmt-const" : fmtConstMap,
- "fmt-func" : fmtFuncMap,
- "math-const" : mathConstMap,
- "math-func" : mathFuncMap,
- }
- /*
- fmtConstMap contains the mapping of stdlib fmt constants.
- */
- var fmtConstMap = map[interface{}]interface{}{
- }
- /*
- fmtFuncMap contains the mapping of stdlib fmt functions.
- */
- var fmtFuncMap = map[interface{}]interface{}{
- "Println": &ECALFunctionAdapter{reflect.ValueOf(fmt.Println)},
- }
- /*
- mathConstMap contains the mapping of stdlib math constants.
- */
- var mathConstMap = map[interface{}]interface{}{
- "Pi": float64(math.Pi),
- }
- /*
- mathFuncMap contains the mapping of stdlib math functions.
- */
- var mathFuncMap = map[interface{}]interface{}{
- }
- ` {
- t.Errorf("Unexpected result: Go string: %#v\nNormal output: %v", string(out), string(out))
- return
- }
- }
|