helpers_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package interpreter
  11. import (
  12. "testing"
  13. "devt.de/krotik/eliasdb/eql/parser"
  14. )
  15. func TestHelperRuntime(t *testing.T) {
  16. gm, _ := simpleGraph()
  17. rt := NewGetRuntimeProvider("test", "main", gm, &testNodeInfo{&defaultNodeInfo{gm}})
  18. // Test simple value runtime
  19. ast, err := parser.ParseWithRuntime("test", "get mynode", rt)
  20. if err != nil {
  21. t.Error(err)
  22. return
  23. }
  24. if val, _ := ast.Children[0].Runtime.Eval(); val != "mynode" {
  25. t.Error("Unexpected eval result:", val)
  26. return
  27. }
  28. if err := ast.Children[0].Runtime.Validate(); err != err {
  29. t.Error(err)
  30. return
  31. }
  32. // Test not implemented runtime
  33. irt := invalidRuntimeInst(rt.eqlRuntimeProvider, ast.Children[0])
  34. if err := irt.Validate(); err.Error() != "EQL error in test: Invalid construct (value) (Line:1 Pos:5)" {
  35. t.Error("Unexpected validate result:", err)
  36. return
  37. }
  38. if _, err := irt.Eval(); err.Error() != "EQL error in test: Invalid construct (value) (Line:1 Pos:5)" {
  39. t.Error("Unexpected validate result:", err)
  40. return
  41. }
  42. }