...

Source file src/github.com/go-kivik/kivik/v4/x/mango/selector_test.go

Documentation: github.com/go-kivik/kivik/v4/x/mango

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  package mango
    14  
    15  import (
    16  	"testing"
    17  
    18  	"github.com/google/go-cmp/cmp"
    19  )
    20  
    21  func TestSplitKeys(t *testing.T) {
    22  	tests := []struct {
    23  		input string
    24  		want  []string
    25  	}{
    26  		{
    27  			input: "foo.bar.baz",
    28  			want:  []string{"foo", "bar", "baz"},
    29  		},
    30  		{
    31  			input: "foo",
    32  			want:  []string{"foo"},
    33  		},
    34  		{
    35  			input: "",
    36  			want:  []string{""},
    37  		},
    38  		{
    39  			input: "foo\\.bar",
    40  			want:  []string{"foo.bar"},
    41  		},
    42  		{
    43  			input: "foo\\\\.bar",
    44  			want:  []string{"foo\\", "bar"},
    45  		},
    46  		{
    47  			input: "foo\\",
    48  			want:  []string{"foo\\"},
    49  		},
    50  		{
    51  			input: "foo.",
    52  			want:  []string{"foo", ""},
    53  		},
    54  	}
    55  
    56  	for _, tt := range tests {
    57  		t.Run(tt.input, func(t *testing.T) {
    58  			got := SplitKeys(tt.input)
    59  			if d := cmp.Diff(tt.want, got); d != "" {
    60  				t.Errorf("unexpected keys (-want, +got): %s", d)
    61  			}
    62  		})
    63  	}
    64  }
    65  

View as plain text