Guest User

Untitled

a guest
Nov 22nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. ## todo
  2. ## error messageの変数名がtest caseのほうではない
  3. ## leftはrightのsubsetだがrightにマージしているので値が変わっているのでわかりにくい?ここは仕様の問題でもあると思うが、、
  4.  
  5. defmodule AssertionMatch do
  6. import ExUnit.Assertions
  7.  
  8. def assert_match?(left, right) do
  9. right_map = case right do
  10. %_{} -> Map.from_struct(right)
  11. %{} -> right
  12. _ -> :error
  13. end
  14.  
  15. left = Map.merge(right_map , left);
  16. assert left == right_map
  17. end
  18.  
  19. end
  20.  
  21. defmodule Struct do
  22. defstruct a: 1, b: 1, z: 10
  23. end
  24. defmodule Main do
  25. left_main = %{a: 1, b: 2 };
  26. right_main = %Struct{}
  27.  
  28. import AssertionMatch
  29. assert_match?(left_main,right_main)
  30. # Assertion with == failed
  31. # code: left == right_map
  32. # left: %{a: 1, b: 2, z: 10}
  33. # right: %{a: 1, b: 1, z: 10}
  34. end
Add Comment
Please, Sign In to add comment