stdlib_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 stdlib
  11. import (
  12. "math"
  13. "testing"
  14. )
  15. func TestSplitModuleAndName(t *testing.T) {
  16. if m, n := splitModuleAndName("fmt.Println"); m != "fmt" || n != "Println" {
  17. t.Error("Unexpected result:", m, n)
  18. return
  19. }
  20. if m, n := splitModuleAndName(""); m != "" || n != "" {
  21. t.Error("Unexpected result:", m, n)
  22. return
  23. }
  24. if m, n := splitModuleAndName("a"); m != "a" || n != "" {
  25. t.Error("Unexpected result:", m, n)
  26. return
  27. }
  28. if m, n := splitModuleAndName("my.FuncCall"); m != "my" || n != "FuncCall" {
  29. t.Error("Unexpected result:", m, n)
  30. return
  31. }
  32. }
  33. func TestGetStdLibItems(t *testing.T) {
  34. if f, _ := GetStdlibFunc("fmt.Println"); f != fmtFuncMap["Println"] {
  35. t.Error("Unexpected resutl: functions should lookup correctly")
  36. return
  37. }
  38. if c, ok := GetStdlibFunc("foo"); c != nil || ok {
  39. t.Error("Unexpected resutl: constants should lookup correctly")
  40. return
  41. }
  42. if c, _ := GetStdlibConst("math.Pi"); c != math.Pi {
  43. t.Error("Unexpected resutl: constants should lookup correctly")
  44. return
  45. }
  46. if c, ok := GetStdlibConst("foo"); c != nil || ok {
  47. t.Error("Unexpected resutl: constants should lookup correctly")
  48. return
  49. }
  50. }