================================================================================
mappings2/mapping2
================================================================================

import "pkl:test"

res1 = new Mapping {
  when (false) { [0] = 0 }
  ["one"] = 1
  ["two"] = 2
}

res2 = new Mapping {
  when (false) { [0] = 0 }
  ["one"] = 1
  ["two"] = this["one"] + 1
}

res3 = new Mapping {
  when (false) { [0] = 0 }
  ["item one"] = 1
  ["two"] = this["item one"] + 1
}

res4 = (res2) {
  when (false) { [0] = 0 }
  ["one"] = 2
}

res5 = new Mapping {
  when (false) { [0] = 0 }
  ["one"] = new Mapping {
    ["a"] = new Mapping {
      when (false) { [0] = 0 }
      ["x"] = 1
    }
    ["b"] = new Mapping {
      when (false) { [0] = 0 }
      ["y"] = 2
    }
  }
  ["two"] = new Mapping {
    when (false) { [0] = 0 }
    ["c"] = new Mapping {
      when (false) { [0] = 0 }
      ["z"] = 3
    }
  }
}
res5a = res5["one"]
res5b = res5["one"]["a"]
res5c = res5["one"]["a"]["x"]
res5d = res5["one"]["b"]
res5e = res5["one"]["b"]["y"]
res5f = res5["two"]
res5g = res5["two"]["c"]
res5h = res5["two"]["c"]["z"]
res5i = test.catch(() -> res5["three"])

res6 = new Mapping {
  when (false) { [0] = 0 }
  ["one"] = List(1, 2, 3)
  ["two"] = this["one"] + List(4, 5, 6)
  ["three"] = 3
}

res7 = (res6) {
  when (false) { [0] = 0 }
  ["one"] = super["one"] + List(4, 5, 6)
  ["three"] = super["three"] * 2
}

res8 = new Mapping {
  when (false) { [0] = 0 }
  default = (key) -> new Dynamic {
    name = key
    age = 42
  }

  ["pigeon"] {}
  ["barn owl"] {}
  ["parrot"] {}
}

res9 = new Mapping {
  when (false) { [0] = 0 }
  default = (key) -> new Dynamic {
    name = key
    age = 42
  }

  ["pigeon"] {}
  ["barn owl"] {}
  ["parrot"] {
    age = 32
  }
}

res10 = (res9) {
  when (false) { [0] = 0 }
  ["parrot"] {}
  ["elf owl"] {}
  ["barn owl"] {
    age = 22
  }
}

res11 = (res1) { when (false) { [0] = 0 } }

--------------------------------------------------------------------------------

(module
  (importClause
    (stringConstant))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (intLiteral))
        (objectEntry
          (slStringLiteral)
          (intLiteral)))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (intLiteral))
        (objectEntry
          (slStringLiteral)
          (binaryExpr
            (subscriptExpr
              (thisExpr)
              (slStringLiteral))
            (intLiteral))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (intLiteral))
        (objectEntry
          (slStringLiteral)
          (binaryExpr
            (subscriptExpr
              (thisExpr)
              (slStringLiteral))
            (intLiteral))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (intLiteral)))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (objectEntry
                (slStringLiteral)
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (whenGenerator
                      (falseLiteral)
                      (objectBody
                        (objectEntry
                          (intLiteral)
                          (intLiteral))))
                    (objectEntry
                      (slStringLiteral)
                      (intLiteral)))))
              (objectEntry
                (slStringLiteral)
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (whenGenerator
                      (falseLiteral)
                      (objectBody
                        (objectEntry
                          (intLiteral)
                          (intLiteral))))
                    (objectEntry
                      (slStringLiteral)
                      (intLiteral))))))))
        (objectEntry
          (slStringLiteral)
          (newExpr
            (type
              (qualifiedIdentifier
                (identifier)))
            (objectBody
              (whenGenerator
                (falseLiteral)
                (objectBody
                  (objectEntry
                    (intLiteral)
                    (intLiteral))))
              (objectEntry
                (slStringLiteral)
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (whenGenerator
                      (falseLiteral)
                      (objectBody
                        (objectEntry
                          (intLiteral)
                          (intLiteral))))
                    (objectEntry
                      (slStringLiteral)
                      (intLiteral)))))))))))
  (classProperty
    (identifier)
    (subscriptExpr
      (variableExpr
        (identifier))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (subscriptExpr
        (variableExpr
          (identifier))
        (slStringLiteral))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (subscriptExpr
        (subscriptExpr
          (variableExpr
            (identifier))
          (slStringLiteral))
        (slStringLiteral))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (subscriptExpr
        (variableExpr
          (identifier))
        (slStringLiteral))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (subscriptExpr
        (subscriptExpr
          (variableExpr
            (identifier))
          (slStringLiteral))
        (slStringLiteral))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (variableExpr
        (identifier))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (subscriptExpr
        (variableExpr
          (identifier))
        (slStringLiteral))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (subscriptExpr
      (subscriptExpr
        (subscriptExpr
          (variableExpr
            (identifier))
          (slStringLiteral))
        (slStringLiteral))
      (slStringLiteral)))
  (classProperty
    (identifier)
    (methodCallExpr
      (variableExpr
        (identifier))
      (identifier)
      (argumentList
        (functionLiteral
          (parameterList)
          (subscriptExpr
            (variableExpr
              (identifier))
            (slStringLiteral))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (methodCallExpr
            (identifier)
            (argumentList
              (intLiteral)
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (binaryExpr
            (subscriptExpr
              (thisExpr)
              (slStringLiteral))
            (methodCallExpr
              (identifier)
              (argumentList
                (intLiteral)
                (intLiteral)
                (intLiteral)))))
        (objectEntry
          (slStringLiteral)
          (intLiteral)))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (binaryExpr
            (subscriptExpr
              (slStringLiteral))
            (methodCallExpr
              (identifier)
              (argumentList
                (intLiteral)
                (intLiteral)
                (intLiteral)))))
        (objectEntry
          (slStringLiteral)
          (binaryExpr
            (subscriptExpr
              (slStringLiteral))
            (intLiteral))))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectProperty
          (identifier)
          (functionLiteral
            (parameterList
              (typedIdentifier
                (identifier)))
            (newExpr
              (type
                (qualifiedIdentifier
                  (identifier)))
              (objectBody
                (objectProperty
                  (identifier)
                  (variableExpr
                    (identifier)))
                (objectProperty
                  (identifier)
                  (intLiteral))))))
        (objectEntry
          (slStringLiteral)
          (objectBody))
        (objectEntry
          (slStringLiteral)
          (objectBody))
        (objectEntry
          (slStringLiteral)
          (objectBody)))))
  (classProperty
    (identifier)
    (newExpr
      (type
        (qualifiedIdentifier
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectProperty
          (identifier)
          (functionLiteral
            (parameterList
              (typedIdentifier
                (identifier)))
            (newExpr
              (type
                (qualifiedIdentifier
                  (identifier)))
              (objectBody
                (objectProperty
                  (identifier)
                  (variableExpr
                    (identifier)))
                (objectProperty
                  (identifier)
                  (intLiteral))))))
        (objectEntry
          (slStringLiteral)
          (objectBody))
        (objectEntry
          (slStringLiteral)
          (objectBody))
        (objectEntry
          (slStringLiteral)
          (objectBody
            (objectProperty
              (identifier)
              (intLiteral)))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))
        (objectEntry
          (slStringLiteral)
          (objectBody))
        (objectEntry
          (slStringLiteral)
          (objectBody))
        (objectEntry
          (slStringLiteral)
          (objectBody
            (objectProperty
              (identifier)
              (intLiteral)))))))
  (classProperty
    (identifier)
    (objectLiteral
      (parenthesizedExpr
        (variableExpr
          (identifier)))
      (objectBody
        (whenGenerator
          (falseLiteral)
          (objectBody
            (objectEntry
              (intLiteral)
              (intLiteral))))))))
