|
21 | 21 | import nl.jqno.equalsverifier.EqualsVerifier;
|
22 | 22 | import org.junit.jupiter.api.Assertions;
|
23 | 23 | import org.junit.jupiter.api.Test;
|
| 24 | +import org.junit.jupiter.api.extension.ExtendWith; |
24 | 25 |
|
25 | 26 | import java.util.Arrays;
|
26 | 27 |
|
| 28 | +@ExtendWith(MetafixToDo.Extension.class) |
27 | 29 | public class HashValueTest {
|
28 | 30 |
|
29 | 31 | private static final String FIELD = "field";
|
@@ -383,6 +385,42 @@ public void shouldIterateOverFieldValuePairs() {
|
383 | 385 | );
|
384 | 386 | }
|
385 | 387 |
|
| 388 | + private void shouldFindArray(final String field) { |
| 389 | + final Value.Hash hash = newHash(); |
| 390 | + hash.put(FIELD, Value.newArray(a -> a.add(VALUE))); |
| 391 | + |
| 392 | + Assertions.assertEquals(VALUE, new FixPath(String.join(".", FIELD, field)).findIn(hash)); |
| 393 | + } |
| 394 | + |
| 395 | + @Test |
| 396 | + public void shouldFindArrayIndex() { |
| 397 | + shouldFindArray("1"); |
| 398 | + } |
| 399 | + |
| 400 | + @Test |
| 401 | + @MetafixToDo("Expected String, got Array") |
| 402 | + public void shouldFindArrayWildcard() { |
| 403 | + shouldFindArray("$last"); |
| 404 | + } |
| 405 | + |
| 406 | + private void shouldFindArraySubfield(final String field) { |
| 407 | + final Value.Hash hash = newHash(); |
| 408 | + hash.put(FIELD, Value.newArray(a -> a.add(Value.newHash(h -> h.put(OTHER_FIELD, OTHER_VALUE))))); |
| 409 | + |
| 410 | + Assertions.assertEquals(OTHER_VALUE, new FixPath(String.join(".", FIELD, field, OTHER_FIELD)).findIn(hash)); |
| 411 | + } |
| 412 | + |
| 413 | + @Test |
| 414 | + public void shouldFindArrayIndexSubfield() { |
| 415 | + shouldFindArraySubfield("1"); |
| 416 | + } |
| 417 | + |
| 418 | + @Test |
| 419 | + @MetafixToDo("Expected String, got Array") |
| 420 | + public void shouldFindArrayWildcardSubfield() { |
| 421 | + shouldFindArraySubfield("$last"); |
| 422 | + } |
| 423 | + |
386 | 424 | private Value.Hash newHash() {
|
387 | 425 | return Value.newHash().asHash();
|
388 | 426 | }
|
|
0 commit comments