name: "Parameter transformation"
cases:
  - name: "Parameter case transformation"
    stdin: |
      var="hElLo WoRlD"
      echo "${var@U}"
      echo "${var@u}"
      echo "${var@L}"

      var=("hElLo WoRlD")
      echo "${var@U}"
      echo "${var@u}"
      echo "${var@L}"
      echo "${var[*]@U}"
      echo "${var[*]@u}"
      echo "${var[*]@L}"
      echo "${var[@]@U}"
      echo "${var[@]@u}"
      echo "${var[@]@L}"

  - name: "Parameter quote transformations - Q"
    stdin: |
      var='""'
      echo "\${var@Q}: ${var@Q}"

      var="Hello"
      echo "\${var@Q}: ${var@Q}"

      var="Hello, world!"
      echo "\${var@Q}: ${var@Q}"

      var="a 'b c' d"
      echo "\${var@Q}: ${var@Q}"

      declare -a arr1=(a b c)
      echo "\${arr1@Q}: ${arr1@Q}"

      declare -A arr2=(["a"]=1 ["b"]=2)
      echo "\${arr2@Q}: ${arr2@Q}"

  - name: "Parameter quote transformations - K"
    known_failure: true # TODO(expansion): needs triage and debugging
    stdin: |
      var='""'
      echo "\${var@K}: ${var@K}"

      var="Hello"
      echo "\${var@K}: ${var@K}"

      var="Hello, world!"
      echo "\${var@K}: ${var@K}"

      var="a 'b c' d"
      echo "\${var@K}: ${var@K}"

      declare -a arr1=(a b c)
      echo "\${arr1@K}: ${arr1@K}"
      echo "\${arr1[1]@K}: ${arr1[1]@K}"
      echo "\${arr1[@]@K}: ${arr1[@]@K}"
      echo "\${arr1[*]@K}: ${arr1[*]@K}"

      declare -A arr2=(["a"]=1 ["b"]=2)
      echo "\${arr2@K}: ${arr2@K}"
      echo "\${arr2[b]@K}: ${arr2[b]@K}"
      echo "\${arr2[@]@K}: ${arr2[@]@K}"
      echo "\${arr2[*]@K}: ${arr2[*]@K}"

  - name: "Parameter quote transformations - k"
    min_oracle_version: 5.2
    stdin: |
      var='""'
      echo "\${var@k}: ${var@k}"

      var="Hello"
      echo "\${var@k}: ${var@k}"

      var="Hello, world!"
      echo "\${var@k}: ${var@k}"

      declare -a arr1=(a b c)
      echo "\${arr1@k}: ${arr1@k}"

      declare -A arr2=(["a"]=1 ["b"]=2)
      echo "\${arr2@k}: ${arr2@k}"

  - name: "Parameter transformations: expand escapes"
    stdin: |
      var="a\n\"b"
      echo "\${var@E}: ${var@E}"

  - name: "Parameter transformation: assignment"
    stdin: |
      var="hello"
      echo "\${var@A}: ${var@A}"

      declare -ia arr=(1 2 3)
      echo "\${arr@A}: ${arr@A}"
      echo "\${arr[1]@A}: ${arr[1]@A}"
      echo "\${arr[@]@A}: ${arr[@]@A}"
      echo "\${arr[*]@A}: ${arr[*]@A}"

      declare -A arr2=(["a"]=b)
      echo "\${arr2@A}: ${arr2@A}"
      echo "\${arr2[@]@A}: ${arr2[@]@A}"
      echo "\${arr2[*]@A}: ${arr2[*]@A}"

  - name: "Parameter transformation: attributes"
    stdin: |
      var="hello"
      echo "\${var@a}: ${var@a}"

      declare -ia arr=(1 2 3)
      echo "\${arr@a}: ${arr@a}"

      ref="arr"
      echo "\${!ref@a}: ${!ref@a}"

  - name: "Parameter transformation @a through nameref"
    known_failure: true
    stdin: |
      declare -i target=42
      declare -n ref=target
      echo "ref @a: ${ref@a}"
      echo "target @a: ${target@a}"

  - name: "Parameter transformation @Q through nameref"
    known_failure: true
    stdin: |
      target="hello world"
      declare -n ref=target
      echo "ref @Q: ${ref@Q}"

  - name: "Parameter transformation @A through nameref"
    known_failure: true
    stdin: |
      target="hello"
      declare -n ref=target
      echo "ref @A: ${ref@A}"
      echo "target @A: ${target@A}"
