| 1 | // Copyright 2016 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package stringsetscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/ |
| 6 | |
| 7 | import "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 8 | |
| 9 | func TestStringSetscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/TestStringSet().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 10 | testCases := [][]string{ |
| 11 | {""}, |
| 12 | {"∫"}, |
| 13 | {"a", "b", "c"}, |
| 14 | {"", "a", "bb", "ccc"}, |
| 15 | {" ", "aaa", "bb", "c"}, |
| 16 | } |
| 17 | test := func(tc int, b *Builderscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#) { |
| 18 | set := b.Setscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#Set().() |
| 19 | if set.Lenscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Set#Len().() != len(testCases[tc]) { |
| 20 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d:Len() = %d; want %d", tc, set.Lenscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Set#Len().(), len(testCases[tc])) |
| 21 | } |
| 22 | for i, s := range testCases[tc] { |
| 23 | if x := b.Indexscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#Index().(s); x != i { |
| 24 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d:Index(%q) = %d; want %d", tc, s, x, i) |
| 25 | } |
| 26 | if p := Searchscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Search().(&set, s); p != i { |
| 27 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d:Search(%q) = %d; want %d", tc, s, p, i) |
| 28 | } |
| 29 | if set.Elemscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Set#Elem().(i) != s { |
| 30 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d:Elem(%d) = %s; want %s", tc, i, set.Elemscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Set#Elem().(i), s) |
| 31 | } |
| 32 | } |
| 33 | if p := Searchscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Search().(&set, "apple"); p != -1 { |
| 34 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(`%d:Search("apple") = %d; want -1`, tc, p) |
| 35 | } |
| 36 | } |
| 37 | for i, tc := range testCases { |
| 38 | b := NewBuilderscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/NewBuilder().() |
| 39 | for _, s := range tc { |
| 40 | b.Addscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#Add().(s) |
| 41 | } |
| 42 | b.Addscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#Add().(tc...) |
| 43 | test(i, b) |
| 44 | } |
| 45 | for i, tc := range testCases { |
| 46 | b := NewBuilderscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/NewBuilder().() |
| 47 | b.Addscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#Add().(tc...) |
| 48 | for _, s := range tc { |
| 49 | b.Addscip-go gomod golang.org/x/text . `golang.org/x/text/internal/stringset`/Builder#Add().(s) |
| 50 | } |
| 51 | test(i, b) |
| 52 | } |
| 53 | } |