You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 regels
1.2 KiB

  1. // Copyright 2016 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package pretty
  15. import "testing"
  16. func TestDiff(t *testing.T) {
  17. for _, test := range []struct {
  18. v1, v2 interface{}
  19. ok bool
  20. want string
  21. }{
  22. {5, 5, true, ""},
  23. {"foo", "foo", true, ""},
  24. {[]int{1, 2, 3}, []int{1, 0, 3}, false, `--- want
  25. +++ got
  26. @@ -1,5 +1,5 @@
  27. []int{
  28. 1,
  29. - 2,
  30. + 0,
  31. 3,
  32. }
  33. `},
  34. } {
  35. got, ok, err := Diff(test.v1, test.v2)
  36. if err != nil {
  37. t.Errorf("%v vs. %v: %v", test.v1, test.v2, err)
  38. continue
  39. }
  40. if ok != test.ok {
  41. t.Errorf("%v vs. %v: got %t, want %t", test.v1, test.v2, ok, test.ok)
  42. }
  43. if got != test.want {
  44. t.Errorf("%v vs. %v: got:\n%q\nwant:\n%q", test.v1, test.v2, got, test.want)
  45. }
  46. }
  47. }