================================================================================
basic/is2
================================================================================

amends "../snippetTest.pkl"

facts {
  ["List"] {
    List(1, 2, 3) is List<Int>
    !(List(1, 2, 3) is List<String>)
    !(Set(1, 2, 3) is List<Int>)
  }

  ["Set"] {
    Set(1, 2, 3) is Set<Int>
    !(List(1, 2, 3) is Set<Int>)
    !(Set(1, 2, 3) is Set<String>)
  }

  ["Map"] {
    Map("Pigeon", 42, "Barn Owl", 21) is Map<String, Int>
    !(Map("Pigeon", 42, "Barn Owl", 21) is Map<Int, String>)
  }

  ["Listing"] {
    new Listing { 1; 2; 3 } is Listing<Int>
    !(new Listing { 1; 2; 3 } is Listing<String>)
  }

  ["Mapping"] {
    new Mapping { ["Pigeon"] = 42; ["Barn Owl"] = 21 } is Mapping<String, Int>
    !(new Listing { 1; 2; 3 } is Mapping<Int, String>)
    !(new Mapping { ["Pigeon"] = 42; ["Barn Owl"] = 21 } is Mapping<Int, String>)
  }

  ["union type"] {
    42 is Int|String
    42 is String|Int
    42 is Number|String
    !(42 is String|Duration)

    List(1, 2, 3) is List<String>|List<Int>
    List(1, 2, 3) is List<String|Int>
    !(List(1, 2, 3) is List<String>|Set<Int>)
  }

  ["nullable type"] {
    null is String?
    null is Map<String, Int>?
    !(null is Map<String, Int?>)
  }

  // currently only tests arity
  ["function type"] {
    ((x) -> x) is (Int) -> Int
    ((x) -> x) is (String) -> String
    !(((x, y) -> x) is (Int) -> Int)
  }

  ["string literal type"] {
    "Pigeon" is "Pigeon"|"Barn Owl"
    !("Pigeon" is "Piggy"|"Barn Owl")
  }

  ["constraint"] {
    "abc" is String(length == 3)
    List("a", "b", "c") is List<String(length == 1)>
    "abc" is String(this is String(this is String(length == 3)))
    !("abc" is String(length == 4))
  }
}

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

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (binaryExpr
                (isExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)
                      (intLiteral)))
                  (type
                    (qualifiedIdentifier
                      (identifier))))
                (variableExpr
                  (identifier)))
              (unaryExpr
                (parenthesizedExpr
                  (isExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)
                      (intLiteral)))
                  (type
                    (qualifiedIdentifier
                      (identifier))
                    (typeArgumentList
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (binaryExpr
                (isExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)
                      (intLiteral)))
                  (type
                    (qualifiedIdentifier
                      (identifier))))
                (variableExpr
                  (identifier)))
              (unaryExpr
                (parenthesizedExpr
                  (isExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)
                      (intLiteral)))
                  (type
                    (qualifiedIdentifier
                      (identifier))
                    (typeArgumentList
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (slStringLiteral)
                  (intLiteral)
                  (slStringLiteral)
                  (intLiteral)))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (type
                    (qualifiedIdentifier
                      (identifier)))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (slStringLiteral)
                      (intLiteral)
                      (slStringLiteral)
                      (intLiteral)))
                  (type
                    (qualifiedIdentifier
                      (identifier))
                    (typeArgumentList
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (binaryExpr
                (isExpr
                  (newExpr
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (objectBody
                      (objectElement
                        (intLiteral))
                      (objectElement
                        (intLiteral))
                      (objectElement
                        (intLiteral))))
                  (type
                    (qualifiedIdentifier
                      (identifier))))
                (variableExpr
                  (identifier)))
              (unaryExpr
                (parenthesizedExpr
                  (isExpr
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))
                        (objectElement
                          (intLiteral))))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectEntry
                    (slStringLiteral)
                    (intLiteral))
                  (objectEntry
                    (slStringLiteral)
                    (intLiteral))))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (type
                    (qualifiedIdentifier
                      (identifier)))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (newExpr
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (objectBody
                      (objectElement
                        (intLiteral))
                      (objectElement
                        (intLiteral))
                      (objectElement
                        (intLiteral))))
                  (type
                    (qualifiedIdentifier
                      (identifier))
                    (typeArgumentList
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (newExpr
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (objectBody
                      (objectEntry
                        (slStringLiteral)
                        (intLiteral))
                      (objectEntry
                        (slStringLiteral)
                        (intLiteral))))
                  (type
                    (qualifiedIdentifier
                      (identifier))
                    (typeArgumentList
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (intLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (isExpr
              (intLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (isExpr
              (intLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (intLiteral)
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))))
          (objectElement
            (isExpr
              (binaryExpr
                (binaryExpr
                  (isExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (intLiteral)
                        (intLiteral)
                        (intLiteral)))
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier))
                        (typeArgumentList
                          (type
                            (qualifiedIdentifier
                              (identifier)))))
                      (type
                        (qualifiedIdentifier
                          (identifier)))))
                  (variableExpr
                    (identifier)))
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)
                    (intLiteral))))
              (type
                (qualifiedIdentifier
                  (identifier))
                (typeArgumentList
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)
                      (intLiteral)))
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier)))))
                    (type
                      (qualifiedIdentifier
                        (identifier))
                      (typeArgumentList
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (nullLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (isExpr
              (nullLiteral)
              (type
                (type
                  (qualifiedIdentifier
                    (identifier))
                  (typeArgumentList
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (nullLiteral)
                  (type
                    (qualifiedIdentifier
                      (identifier))
                    (typeArgumentList
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (type
                        (type
                          (qualifiedIdentifier
                            (identifier))))))))))))
      (lineComment)
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (isExpr
                (parenthesizedExpr
                  (functionLiteral
                    (parameterList
                      (typedIdentifier
                        (identifier)))
                    (variableExpr
                      (identifier))))
                (type
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (functionLiteral
                      (parameterList
                        (typedIdentifier
                          (identifier)))
                      (variableExpr
                        (identifier))))))
              (type
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (type
                  (qualifiedIdentifier
                    (identifier))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (parenthesizedExpr
                    (functionLiteral
                      (parameterList
                        (typedIdentifier
                          (identifier))
                        (typedIdentifier
                          (identifier)))
                      (variableExpr
                        (identifier))))
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (slStringLiteral)
              (type
                (type
                  (stringConstant))
                (type
                  (stringConstant)))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (slStringLiteral)
                  (type
                    (type
                      (stringConstant))
                    (type
                      (stringConstant)))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (isExpr
              (slStringLiteral)
              (type
                (qualifiedIdentifier
                  (identifier)))))
          (objectElement
            (parenthesizedExpr
              (binaryExpr
                (variableExpr
                  (identifier))
                (intLiteral))))
          (objectElement
            (isExpr
              (binaryExpr
                (binaryExpr
                  (isExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (slStringLiteral)
                        (slStringLiteral)
                        (slStringLiteral)))
                    (type
                      (qualifiedIdentifier
                        (identifier))))
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (binaryExpr
                        (variableExpr
                          (identifier))
                        (intLiteral)))))
                (slStringLiteral))
              (type
                (qualifiedIdentifier
                  (identifier)))))
          (objectElement
            (parenthesizedExpr
              (isExpr
                (thisExpr)
                (type
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (isExpr
                    (thisExpr)
                    (type
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (binaryExpr
                        (variableExpr
                          (identifier))
                        (intLiteral))))))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (isExpr
                  (slStringLiteral)
                  (type
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (binaryExpr
                      (variableExpr
                        (identifier))
                      (intLiteral))))))))))))
