stdlib_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 TestSymbols(t *testing.T) {
  16. p, c, f := GetStdlibSymbols()
  17. if len(p) == 0 || len(c) == 0 || len(f) == 0 {
  18. t.Error("Should have some entries in symbol lists:", p, c, f)
  19. return
  20. }
  21. }
  22. func TestSplitModuleAndName(t *testing.T) {
  23. if m, n := splitModuleAndName("fmt.Println"); m != "fmt" || n != "Println" {
  24. t.Error("Unexpected result:", m, n)
  25. return
  26. }
  27. if m, n := splitModuleAndName(""); m != "" || n != "" {
  28. t.Error("Unexpected result:", m, n)
  29. return
  30. }
  31. if m, n := splitModuleAndName("a"); m != "a" || n != "" {
  32. t.Error("Unexpected result:", m, n)
  33. return
  34. }
  35. if m, n := splitModuleAndName("my.FuncCall"); m != "my" || n != "FuncCall" {
  36. t.Error("Unexpected result:", m, n)
  37. return
  38. }
  39. }
  40. func TestGetStdLibItems(t *testing.T) {
  41. if f, _ := GetStdlibFunc("fmt.Println"); f != fmtFuncMap["Println"] {
  42. t.Error("Unexpected resutl: functions should lookup correctly")
  43. return
  44. }
  45. if c, ok := GetStdlibFunc("foo"); c != nil || ok {
  46. t.Error("Unexpected resutl: constants should lookup correctly")
  47. return
  48. }
  49. if c, _ := GetStdlibConst("math.Pi"); c != math.Pi {
  50. t.Error("Unexpected resutl: constants should lookup correctly")
  51. return
  52. }
  53. if c, ok := GetStdlibConst("foo"); c != nil || ok {
  54. t.Error("Unexpected resutl: constants should lookup correctly")
  55. return
  56. }
  57. }