|
1 | 1 | /* |
2 | | - * Copyright 2018 The NATS Authors |
| 2 | + * Copyright 2018-2024 The NATS Authors |
3 | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | * you may not use this file except in compliance with the License. |
5 | 5 | * You may obtain a copy of the License at |
@@ -117,19 +117,18 @@ func TestTagList(t *testing.T) { |
117 | 117 | tags.Add("one") |
118 | 118 |
|
119 | 119 | AssertEquals(true, tags.Contains("one"), t) |
120 | | - AssertEquals(true, tags.Contains("ONE"), t) |
| 120 | + AssertEquals(false, tags.Contains("ONE"), t) |
121 | 121 | AssertEquals("one", tags[0], t) |
122 | 122 |
|
123 | 123 | tags.Add("TWO") |
124 | 124 |
|
125 | | - AssertEquals(true, tags.Contains("two"), t) |
| 125 | + AssertEquals(false, tags.Contains("two"), t) |
126 | 126 | AssertEquals(true, tags.Contains("TWO"), t) |
127 | | - AssertEquals("two", tags[1], t) |
| 127 | + AssertEquals("TWO", tags[1], t) |
128 | 128 |
|
129 | 129 | tags.Remove("ONE") |
130 | | - AssertEquals("two", tags[0], t) |
131 | | - AssertEquals(false, tags.Contains("one"), t) |
132 | | - AssertEquals(false, tags.Contains("ONE"), t) |
| 130 | + AssertEquals("one", tags[0], t) |
| 131 | + AssertEquals(true, tags.Contains("TWO"), t) |
133 | 132 | } |
134 | 133 |
|
135 | 134 | func TestStringList(t *testing.T) { |
@@ -427,3 +426,73 @@ func TestInvalidInfo(t *testing.T) { |
427 | 426 | } |
428 | 427 | } |
429 | 428 | } |
| 429 | + |
| 430 | +func TestTagList_CasePreservingContains(t *testing.T) { |
| 431 | + type test struct { |
| 432 | + v string |
| 433 | + a TagList |
| 434 | + ok bool |
| 435 | + } |
| 436 | + |
| 437 | + tests := []test{ |
| 438 | + {v: "A", a: TagList{}, ok: false}, |
| 439 | + {v: "A", a: TagList{"A"}, ok: true}, |
| 440 | + {v: "a", a: TagList{"A"}, ok: false}, |
| 441 | + {v: "a", a: TagList{"a:hello"}, ok: false}, |
| 442 | + {v: "a:a", a: TagList{"a:c"}, ok: false}, |
| 443 | + } |
| 444 | + |
| 445 | + for idx, test := range tests { |
| 446 | + found := test.a.Contains(test.v) |
| 447 | + if !found && test.ok { |
| 448 | + t.Errorf("[%d] expected to contain %q", idx, test.v) |
| 449 | + } |
| 450 | + } |
| 451 | +} |
| 452 | + |
| 453 | +func TestTagList_Add(t *testing.T) { |
| 454 | + type test struct { |
| 455 | + v string |
| 456 | + a TagList |
| 457 | + shouldBe TagList |
| 458 | + } |
| 459 | + |
| 460 | + tests := []test{ |
| 461 | + {v: "A", a: TagList{}, shouldBe: TagList{"A"}}, |
| 462 | + {v: "A", a: TagList{"A"}, shouldBe: TagList{"A"}}, |
| 463 | + {v: "a", a: TagList{"A"}, shouldBe: TagList{"A", "a"}}, |
| 464 | + {v: "a", a: TagList{"a:hello"}, shouldBe: TagList{"a", "a:hello"}}, |
| 465 | + {v: "a:Hello", a: TagList{"a:hello"}, shouldBe: TagList{"a:hello", "a:Hello"}}, |
| 466 | + {v: "a:a", a: TagList{"a:c"}, shouldBe: TagList{"a:a", "a:c"}}, |
| 467 | + } |
| 468 | + |
| 469 | + for idx, test := range tests { |
| 470 | + test.a.Add(test.v) |
| 471 | + if !test.a.Equals(&test.shouldBe) { |
| 472 | + t.Errorf("[%d] expected lists to be equal: %v", idx, test.a) |
| 473 | + } |
| 474 | + } |
| 475 | +} |
| 476 | + |
| 477 | +func TestTagList_Delete(t *testing.T) { |
| 478 | + type test struct { |
| 479 | + v string |
| 480 | + a TagList |
| 481 | + shouldBe TagList |
| 482 | + } |
| 483 | + |
| 484 | + tests := []test{ |
| 485 | + {v: "A", a: TagList{}, shouldBe: TagList{}}, |
| 486 | + {v: "A", a: TagList{"A"}, shouldBe: TagList{}}, |
| 487 | + {v: "a", a: TagList{"A"}, shouldBe: TagList{"A"}}, |
| 488 | + {v: "a:Hello", a: TagList{"a:hello"}, shouldBe: TagList{"a:hello"}}, |
| 489 | + {v: "a:a", a: TagList{"a:A"}, shouldBe: TagList{"a:A"}}, |
| 490 | + } |
| 491 | + |
| 492 | + for idx, test := range tests { |
| 493 | + test.a.Remove(test.v) |
| 494 | + if !test.a.Equals(&test.shouldBe) { |
| 495 | + t.Errorf("[%d] expected lists to be equal: %v", idx, test.a) |
| 496 | + } |
| 497 | + } |
| 498 | +} |
0 commit comments