util_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package eql
  2. import (
  3. "testing"
  4. )
  5. func TestRefineQuery(t *testing.T) {
  6. gm, _ := songGraph()
  7. res, _ := RunQuery("test", "main", "get Author with ordering(ascending key)", gm)
  8. if res.String() != `
  9. Labels: Author Key, Author Name
  10. Format: auto, auto
  11. Data: 1:n:key, 1:n:name
  12. 000, John
  13. 123, Mike
  14. 456, Hans
  15. `[1:] {
  16. t.Error("Unexpected result: ", res)
  17. return
  18. }
  19. refres, err := RefineQueryByResultRows(res, []int{0, 2})
  20. if err != nil || refres != `lookup Author "000", "456"
  21. with
  22. ordering(ascending key)` {
  23. t.Error("Unexpected result: ", refres, err)
  24. return
  25. }
  26. res, _ = RunQuery("test", "main", "lookup Author '000', '123', '456' with ordering(ascending key)", gm)
  27. if res.String() != `
  28. Labels: Author Key, Author Name
  29. Format: auto, auto
  30. Data: 1:n:key, 1:n:name
  31. 000, John
  32. 123, Mike
  33. 456, Hans
  34. `[1:] {
  35. t.Error("Unexpected result: ", res)
  36. return
  37. }
  38. refres, err = RefineQueryByResultRows(res, []int{0, 2})
  39. if err != nil || refres != `lookup Author "000", "456"
  40. with
  41. ordering(ascending key)` {
  42. t.Error("Unexpected result: ", refres, err)
  43. return
  44. }
  45. res, _ = RunQuery("test", "main", "get Author", gm)
  46. refres, err = RefineQueryByResultRows(res, []int{0, 1, 2, 3})
  47. if err != nil || refres != `lookup Author "000", "123", "456"` {
  48. t.Error("Unexpected result: ", refres, err)
  49. return
  50. }
  51. refres, err = RefineQueryByResultRows(res, []int{3})
  52. if err == nil || err.Error() != "Could not find requested row" {
  53. t.Error("Unexpected result: ", refres, err)
  54. return
  55. }
  56. }