error_test.go 798 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package util
  11. import (
  12. "fmt"
  13. "testing"
  14. "devt.de/krotik/ecal/parser"
  15. )
  16. func TestRuntimeError(t *testing.T) {
  17. ast, _ := parser.Parse("foo", "a")
  18. err1 := NewRuntimeError("foo", fmt.Errorf("foo"), "bar", ast)
  19. if err1.Error() != "ECAL error in foo: foo (bar) (Line:1 Pos:1)" {
  20. t.Error("Unexpected result:", err1)
  21. return
  22. }
  23. ast.Token = nil
  24. err2 := NewRuntimeError("foo", fmt.Errorf("foo"), "bar", ast)
  25. if err2.Error() != "ECAL error in foo: foo (bar)" {
  26. t.Error("Unexpected result:", err2)
  27. return
  28. }
  29. }