Guest User

Untitled

a guest
May 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. // extensible takes a jsonnet value and if it's an object it recursively
  2. // computes a version of the object where each of its fields is converted
  3. // to the "+:" form.
  4. local extensible(o) = if std.isObject(o) then {
  5. [n]+: extensible(o[n])
  6. for n in std.objectFields(o)
  7. } else o;
  8.  
  9. // merge takes two objects and merges them recursively.
  10. local merge(a, b) = a + extensible(b);
  11.  
  12. local testCases = [
  13. [
  14. {
  15. a: 1,
  16. },
  17. {
  18. b: 2,
  19. },
  20. {
  21. a: 1,
  22. b: 2,
  23. },
  24. ],
  25. [
  26. {
  27. x: {
  28. a: 1,
  29. },
  30. },
  31. {
  32. x: {
  33. b: 2,
  34. },
  35. },
  36. {
  37. x: {
  38. a: 1,
  39. b: 2,
  40. },
  41. },
  42. ],
  43. ];
  44.  
  45. local check = [
  46. std.assertEqual(merge(e[0], e[1]), e[2])
  47. for e in testCases
  48. ];
  49.  
  50. check
Add Comment
Please, Sign In to add comment