...

Source file src/cloud.google.com/go/internal/pretty/diff_test.go

Documentation: cloud.google.com/go/internal/pretty

     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  
    15  //go:build linux
    16  // +build linux
    17  
    18  package pretty
    19  
    20  import (
    21  	"testing"
    22  )
    23  
    24  func TestDiff(t *testing.T) {
    25  	for _, test := range []struct {
    26  		v1, v2 interface{}
    27  		ok     bool
    28  		want   string
    29  	}{
    30  		{5, 5, true, ""},
    31  		{"foo", "foo", true, ""},
    32  		{[]int{1, 2, 3}, []int{1, 0, 3}, false, `--- want
    33  +++ got
    34  @@ -1,5 +1,5 @@
    35   []int{
    36       1,
    37  -    2,
    38  +    0,
    39       3,
    40   }
    41  `},
    42  	} {
    43  		got, ok, err := Diff(test.v1, test.v2)
    44  		if err != nil {
    45  			t.Errorf("%v vs. %v: %v", test.v1, test.v2, err)
    46  			continue
    47  		}
    48  		if ok != test.ok {
    49  			t.Errorf("%v vs. %v: got %t, want %t", test.v1, test.v2, ok, test.ok)
    50  		}
    51  		if got != test.want {
    52  			t.Errorf("%v vs. %v: got:\n%q\nwant:\n%q", test.v1, test.v2, got, test.want)
    53  		}
    54  	}
    55  }
    56  

View as plain text