stdlib_test.go 1.7 KB

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