# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

# Substitution converts str to AnsibleUnicode
# -------------------------------------------

- name: String. AnsibleUnicode.
  assert:
    that: result == dtype
    success_msg: '"abc" is {{ dtype }}'
    fail_msg: '"abc" is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    data: "abc"
    result: '{{ data | community.general.reveal_ansible_type }}'
    dtype: 'AnsibleUnicode'

- name: String. AnsibleUnicode alias str.
  assert:
    that: result == dtype
    success_msg: '"abc" is {{ dtype }}'
    fail_msg: '"abc" is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    alias: {"AnsibleUnicode": "str"}
    data: "abc"
    result: '{{ data | community.general.reveal_ansible_type(alias) }}'
    dtype: 'str'

- name: List. All items are AnsibleUnicode.
  assert:
    that: result == dtype
    success_msg: '["a", "b", "c"] is {{ dtype }}'
    fail_msg: '["a", "b", "c"] is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    data: ["a", "b", "c"]
    result: '{{ data | community.general.reveal_ansible_type }}'
    dtype: 'list[AnsibleUnicode]'

- name: Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode.
  assert:
    that: result == dtype
    success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}'
    fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    data: {"a": "foo", "b": "bar", "c": "baz"}
    result: '{{ data | community.general.reveal_ansible_type }}'
    dtype: 'dict[AnsibleUnicode, AnsibleUnicode]'

# No substitution and no alias. Type of strings is str
# ----------------------------------------------------

- name: String
  assert:
    that: result == dtype
    success_msg: '"abc" is {{ dtype }}'
    fail_msg:  '"abc" is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ "abc" | community.general.reveal_ansible_type }}'
    dtype: str

- name: Integer
  assert:
    that: result == dtype
    success_msg: '123 is {{ dtype }}'
    fail_msg:  '123 is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ 123 | community.general.reveal_ansible_type }}'
    dtype: int

- name: Float
  assert:
    that: result == dtype
    success_msg: '123.45 is {{ dtype }}'
    fail_msg:  '123.45 is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ 123.45 | community.general.reveal_ansible_type }}'
    dtype: float

- name: Boolean
  assert:
    that: result == dtype
    success_msg: 'true is {{ dtype }}'
    fail_msg:  'true is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ true | community.general.reveal_ansible_type }}'
    dtype: bool

- name: List. All items are strings.
  assert:
    that: result == dtype
    success_msg: '["a", "b", "c"] is {{ dtype }}'
    fail_msg:  '["a", "b", "c"] is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
    dtype: list[str]

- name: List of dictionaries.
  assert:
    that: result == dtype
    success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}'
    fail_msg:  '[{"a": 1}, {"b": 2}] is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
    dtype: list[dict]

- name: Dictionary. All keys are strings. All values are integers.
  assert:
    that: result == dtype
    success_msg: '{"a": 1} is {{ dtype }}'
    fail_msg:  '{"a": 1} is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
    dtype: dict[str, int]

- name: Dictionary. All keys are strings. All values are integers.
  assert:
    that: result == dtype
    success_msg: '{"a": 1, "b": 2} is {{ dtype }}'
    fail_msg:  '{"a": 1, "b": 2} is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
    dtype: dict[str, int]

# Type of strings is AnsibleUnicode or str
# ----------------------------------------

- name: Dictionary. The keys are integers or strings. All values are strings.
  assert:
    that: result == dtype
    success_msg: 'data is {{ dtype }}'
    fail_msg: 'data is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    alias: {"AnsibleUnicode": "str"}
    data: {1: 'a', 'b': 'b'}
    result: '{{ data | community.general.reveal_ansible_type(alias) }}'
    dtype: dict[int|str, str]

- name: Dictionary. All keys are integers. All values are keys.
  assert:
    that: result == dtype
    success_msg: 'data is {{ dtype }}'
    fail_msg: 'data is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    alias: {"AnsibleUnicode": "str"}
    data: {1: 'a', 2: 'b'}
    result: '{{ data | community.general.reveal_ansible_type(alias) }}'
    dtype: dict[int, str]

- name: Dictionary. All keys are strings. Multiple types values.
  assert:
    that: result == dtype
    success_msg: 'data is {{ dtype }}'
    fail_msg: 'data is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    alias: {"AnsibleUnicode": "str"}
    data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
    result: '{{ data | community.general.reveal_ansible_type(alias) }}'
    dtype: dict[str, bool|dict|float|int|list|str]

- name: List. Multiple types items.
  assert:
    that: result == dtype
    success_msg: 'data is {{ dtype }}'
    fail_msg: 'data is {{ result }}'
    quiet: '{{ quiet_test | d(true) | bool }}'
  vars:
    alias: {"AnsibleUnicode": "str"}
    data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}]
    result: '{{ data | community.general.reveal_ansible_type(alias) }}'
    dtype: list[bool|dict|float|int|list|str]
