| 1 | /* |
| 2 | Copyright 2015 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package fieldscip-go gomod k8s.io/utils . `k8s.io/utils/field`/ |
| 18 | |
| 19 | import "testingscip-go gomod github.com/golang/go/src go1.23 testing/" |
| 20 | |
| 21 | func TestPathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/TestPath().(t *testingscip-go gomod github.com/golang/go/src go1.23 testing/.Tscip-go gomod github.com/golang/go/src go1.23 testing/T#) { |
| 22 | testCases := []struct { |
| 23 | op func(*Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# |
| 24 | expected string |
| 25 | }{ |
| 26 | { |
| 27 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p }, |
| 28 | "root", |
| 29 | }, |
| 30 | { |
| 31 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Childscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Child().("first") }, |
| 32 | "root.first", |
| 33 | }, |
| 34 | { |
| 35 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Childscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Child().("second") }, |
| 36 | "root.first.second", |
| 37 | }, |
| 38 | { |
| 39 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Indexscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Index().(0) }, |
| 40 | "root.first.second[0]", |
| 41 | }, |
| 42 | { |
| 43 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Childscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Child().("third") }, |
| 44 | "root.first.second[0].third", |
| 45 | }, |
| 46 | { |
| 47 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Indexscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Index().(93) }, |
| 48 | "root.first.second[0].third[93]", |
| 49 | }, |
| 50 | { |
| 51 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.parentscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#parent. }, |
| 52 | "root.first.second[0].third", |
| 53 | }, |
| 54 | { |
| 55 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.parentscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#parent. }, |
| 56 | "root.first.second[0]", |
| 57 | }, |
| 58 | { |
| 59 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Keyscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Key().("key") }, |
| 60 | "root.first.second[0][key]", |
| 61 | }, |
| 62 | } |
| 63 | |
| 64 | root := NewPathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/NewPath().("root") |
| 65 | p := root |
| 66 | for i, tc := range testCases { |
| 67 | p = tc.op(p) |
| 68 | if p.Stringscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#String().() != tc.expected { |
| 69 | t.Errorfscip-go gomod github.com/golang/go/src go1.23 testing/common#Errorf().("[%d] Expected %q, got %q", i, tc.expected, p.Stringscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#String().()) |
| 70 | } |
| 71 | if p.Rootscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Root().() != root { |
| 72 | t.Errorfscip-go gomod github.com/golang/go/src go1.23 testing/common#Errorf().("[%d] Wrong root: %#v", i, p.Rootscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Root().()) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func TestPathMultiArgscip-go gomod k8s.io/utils . `k8s.io/utils/field`/TestPathMultiArg().(t *testingscip-go gomod github.com/golang/go/src go1.23 testing/.Tscip-go gomod github.com/golang/go/src go1.23 testing/T#) { |
| 78 | testCases := []struct { |
| 79 | op func(*Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# |
| 80 | expected string |
| 81 | }{ |
| 82 | { |
| 83 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p }, |
| 84 | "root.first", |
| 85 | }, |
| 86 | { |
| 87 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Childscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Child().("second", "third") }, |
| 88 | "root.first.second.third", |
| 89 | }, |
| 90 | { |
| 91 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.Indexscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Index().(0) }, |
| 92 | "root.first.second.third[0]", |
| 93 | }, |
| 94 | { |
| 95 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.parentscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#parent. }, |
| 96 | "root.first.second.third", |
| 97 | }, |
| 98 | { |
| 99 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.parentscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#parent. }, |
| 100 | "root.first.second", |
| 101 | }, |
| 102 | { |
| 103 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.parentscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#parent. }, |
| 104 | "root.first", |
| 105 | }, |
| 106 | { |
| 107 | func(p *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#) *Pathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path# { return p.parentscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#parent. }, |
| 108 | "root", |
| 109 | }, |
| 110 | } |
| 111 | |
| 112 | root := NewPathscip-go gomod k8s.io/utils . `k8s.io/utils/field`/NewPath().("root", "first") |
| 113 | p := root |
| 114 | for i, tc := range testCases { |
| 115 | p = tc.op(p) |
| 116 | if p.Stringscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#String().() != tc.expected { |
| 117 | t.Errorfscip-go gomod github.com/golang/go/src go1.23 testing/common#Errorf().("[%d] Expected %q, got %q", i, tc.expected, p.Stringscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#String().()) |
| 118 | } |
| 119 | if p.Rootscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Root().() != root.Rootscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Root().() { |
| 120 | t.Errorfscip-go gomod github.com/golang/go/src go1.23 testing/common#Errorf().("[%d] Wrong root: %#v", i, p.Rootscip-go gomod k8s.io/utils . `k8s.io/utils/field`/Path#Root().()) |
| 121 | } |
| 122 | } |
| 123 | } |