Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior of Values matcher #337

Closed
tienvx opened this issue Nov 17, 2023 · 4 comments
Closed

Strange behavior of Values matcher #337

tienvx opened this issue Nov 17, 2023 · 4 comments

Comments

@tienvx
Copy link
Contributor

tienvx commented Nov 17, 2023

This is the description of Values matcher from specification v4:

Match the values in a map, ignoring the keys

But from what I tested, I think it doesn't ignore the keys, and the way it "Match the values in a map" doesn't make sense to me.

@tienvx
Copy link
Contributor Author

tienvx commented Nov 17, 2023

Here are some behaviors on array:

  1. Array
    1. All values present:
      • Consumer: Values(["a", "bb", "ccc"])
      • Provider: ["a", "bb", "ccc"]
      • Result: OK
    2. Missing value at the beginning:
      • Consumer: Values(["a", "bb", "ccc"])

      • Provider: ["bb", "ccc"]

      • Result: NOT OK

      • Output:

          ```
          $.values[1] -> Expected 'ccc' (String) to be equal to 'bb' (String)
          $.values[0] -> Expected 'bb' (String) to be equal to 'a' (String)
          ```
        
      • My comment: output make sense to me

    3. Missing value at the end:
      • Consumer: Values(["a", "bb", "ccc"])
      • Provider: ["a", "bb"]
      • Result: OK
      • My comment: it's weird, I don't understand why it accept missing value (and doesn't accept additional value. Postel's law but in revert?)
    4. Duplicated first value at the end:
      • Consumer: Values(["a", "bb", "ccc"])
      • Provider: ["a", "bb", "ccc", "a", "a", "a"]
      • Result: OK
    5. Duplicated other values at the end:
      • Consumer: Values(["a", "bb", "ccc"])

      • Provider: ["a", "bb", "ccc", "bb", "ccc"]

      • Result: NOT OK

      • Output:

          ```
         $.values[3] -> Expected 'bb' (String) to be equal to 'a' (String)
         $.values[4] -> Expected 'ccc' (String) to be equal to 'a' (String)
          ```
        
      • My comment: output doesn't make sense to me

    6. Additional value at the beginning:
      • Consumer: Values(["a", "bb", "ccc"])

      • Provider: ["dddd", "a", "bb", "ccc"]

      • Result: NOT OK

      • Output:

          ```
          $.values[3] -> Expected 'ccc' (String) to be equal to 'a' (String)
          $.values[0] -> Expected 'dddd' (String) to be equal to 'a' (String)
          $.values[1] -> Expected 'a' (String) to be equal to 'bb' (String)
          $.values[2] -> Expected 'bb' (String) to be equal to 'ccc' (String)
          ```
        
      • My comment: now I understand they way it compare values

    7. Additional value at the end:
      • Consumer: Values(["a", "bb", "ccc"])

      • Provider: ["a", "bb", "ccc", "dddd"]

      • Result: NOT OK

      • Output:

          ```
          $.values[3] -> Expected 'dddd' (String) to be equal to 'a' (String)
          ```
        
    8. Swap values:
      • Consumer: Values(["a", "bb", "ccc"])

      • Provider: ["ccc", "bb", "a"]

      • Result: NOT OK

      • Output:

          ```
         $.values[0] -> Expected 'ccc' (String) to be equal to 'a' (String)
         $.values[2] -> Expected 'a' (String) to be equal to 'ccc' (String)
          ```
        

I can see these rules applied for array:

  1. Starting values must be the same as defined
  2. Missing ending values are OK
  3. Missing starting values are NOT OK though
  4. Additional values are NOT OK
  5. Only the first value is allowed to be duplicated

I expected the behavior like this:

  1. All values must be present
  2. The order of values is not important
  3. Missing values are NOT OK
  4. Additional values are NOT OK
  5. Duplicated values may are OK?

@tienvx
Copy link
Contributor Author

tienvx commented Nov 17, 2023

Here are some behaviors on map:

  1. Map
    1. All values present:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})
      • Provider: {"a": "a", "b": "bb", "c": "ccc"}
      • Result: OK
    2. Missing value #1:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})
      • Provider: {"b": "bb", "c": "ccc"}
      • Result: OK
    3. Missing value #2:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})
      • Provider: {"a": "a", "b": "bb"}
      • Result: OK
    4. Duplicated first value:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})
      • Provider: {"a": "a", "b": "bb", "c": "ccc", "d": "a"}
      • Result: OK
    5. Duplicated other values:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})

      • Provider: {"a": "a", "b": "bb", "c": "ccc", "d": "bb"}

      • Result: NOT OK

      • Output:

          ```
         $.valuesWithKeys.d -> Expected 'bb' (String) to be equal to 'a' (String)
          ```
        
      • My comment: output doesn't make sense to me

    6. Additional value #1:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})

      • Provider: {"d": "dddd", "a": "a", "b": "bb", "c": "ccc"}

      • Result: NOT OK

      • Output:

          ```
          $.valuesWithKeys.d -> Expected 'dddd' (String) to be equal to 'a' (String)
          ```
        
    7. Additional value #2:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})

      • Provider: {"a": "a", "b": "bb", "c": "ccc", "d": "dddd"}

      • Result: NOT OK

      • Output:

          ```
          $.valuesWithKeys.d -> Expected 'dddd' (String) to be equal to 'a' (String)
          ```
        
    8. Updated value:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})

      • Provider: {"a": "a", "b": "b", "c": "cc"}

      • Result: NOT OK

      • Output:

          ```
         $.valuesWithKeys.c -> Expected 'c' (String) to be equal to 'ccc' (String)
         $.valuesWithKeys.b -> Expected 'b' (String) to be equal to 'bb' (String)
          ```
        
    9. Swap value:

      • Consumer: Values({"a": "a", "b": "bb", "c": "ccc"})

      • Provider: {"a": "bb", "b": "ccc", "c": "a"}

      • Result: NOT OK

      • Output:

          ```
         $.valuesWithKeys.c -> Expected 'a' (String) to be equal to 'ccc' (String)
         $.valuesWithKeys.a -> Expected 'bb' (String) to be equal to 'a' (String)
         $.valuesWithKeys.b -> Expected 'ccc' (String) to be equal to 'bb' (String)
          ```
        
      • My comment: key of map is still be used to compare

I can see these rules applied for array:

  1. Keys are used to compare values
  2. Values must be the same as defined
  3. Missing values are OK
  4. Additional values are NOT OK
  5. Only the first value is allowed to be duplicated

I expected the behavior like this:

  1. All values must be present
  2. Keys must be ignored
  3. Missing values are NOT OK
  4. Additional values are NOT OK
  5. Duplicated values may be OK?

@tienvx
Copy link
Contributor Author

tienvx commented Nov 17, 2023

All of these behaviors can be reproduced by updating values and valuesWithKeys under this file

@tienvx
Copy link
Contributor Author

tienvx commented Feb 10, 2024

Closed, as the solution is to deprecate values matcher and replace it with eachValue and eachKey

#365 (comment)

@tienvx tienvx closed this as completed Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant