================================================================================
api/intseq
================================================================================

amends "../snippetTest.pkl"

import "pkl:math"

local id = (it) -> it

examples {
  ["construction"] {
    IntSeq(-3, 2)
    IntSeq(5, 5)
    IntSeq(5, 0)
    IntSeq(0, 0)
    IntSeq(0, 10)
    IntSeq(-10, 0)
  }

  ["construction with step"] {
    IntSeq(-3, 2).step(2)
    IntSeq(2, -3).step(-2)
    IntSeq(2, -3).step(-5)
    IntSeq(2, -3).step(-7)

    // see https://youtrack.jetbrains.com/issue/KT-17176
    // step(math.minInt) does not seem to cause problems for us
    IntSeq(0, 1).step(math.minInt)
    IntSeq(math.maxInt, math.minInt).step(math.minInt)
    IntSeq(math.minInt, math.maxInt).step(math.maxInt)

    module.catch(() -> IntSeq(-3, 2).step(0))
  }

  ["start"] {
    IntSeq(-3, 2).start
    IntSeq(2, -3).start
  }

  ["end"] {
    IntSeq(-3, 2).end
    IntSeq(2, -3).end
  }

  ["step"] {
    IntSeq(-3, 2).step
    IntSeq(-3, 2).step(2).step
    IntSeq(2, -3).step
    IntSeq(2, -3).step(-2).step
  }

  ["fold"] {
    IntSeq(-3, 2).fold(List(), (l, e) -> l.add(e))
    IntSeq(5, 5).fold(List(), (l, e) -> l.add(e))
    IntSeq(5, 0).fold(List(), (l, e) -> l.add(e))
    IntSeq(0, 0).fold(List(), (l, e) -> l.add(e))
    IntSeq(0, 10).fold(List(), (l, e) -> l.add(e))
    IntSeq(-10, 0).fold(List(), (l, e) -> l.add(e))

    IntSeq(-3, 2).step(2).fold(List(), (l, e) -> l.add(e))
    IntSeq(2, -3).step(-2).fold(List(), (l, e) -> l.add(e))
    IntSeq(2, -3).step(-5).fold(List(), (l, e) -> l.add(e))
    IntSeq(2, -3).step(-7).fold(List(), (l, e) -> l.add(e))
  }

  ["map"] {
    IntSeq(-3, 2).map(id)
    IntSeq(5, 5).map(id)
    IntSeq(5, 0).map(id)
    IntSeq(0, 0).map(id)
    IntSeq(0, 10).map(id)
    IntSeq(-10, 0).map(id)

    IntSeq(-3, 2).step(2).map(id)
    IntSeq(2, -3).step(-2).map(id)
    IntSeq(2, -3).step(-5).map(id)
    IntSeq(2, -3).step(-7).map(id)

    // see https://youtrack.jetbrains.com/issue/KT-17176
    // step(math.minInt) does not seem to cause problems for us
    IntSeq(0, 1).step(math.minInt).map(id)
    IntSeq(math.maxInt, math.minInt).step(math.minInt).map(id)
    IntSeq(math.minInt, math.maxInt).step(math.maxInt).map(id)
  }

  ["cannot instantiate"] {
    module.catch(() -> new IntSeq {})
  }

  ["toList"] {
    IntSeq(0, 3).toList() == List(0, 1, 2, 3)
    IntSeq(-3, 2).step(2).toList() == List(-3, -1, 1)
    IntSeq(5, 1).step(-2).toList() == List(5, 3, 1)
  }

  ["toListing"] {
    IntSeq(0, 3).toListing() == new Listing { 0; 1; 2; 3 }
    IntSeq(-3, 2).step(2).toListing() == new Listing { -3; -1; 1 }
    IntSeq(5, 1).step(-2).toListing() == new Listing { 5; 3; 1 }
  }
}

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

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (importClause
    (stringConstant))
  (classProperty
    (modifier)
    (identifier)
    (functionLiteral
      (parameterList
        (typedIdentifier
          (identifier)))
      (variableExpr
        (identifier))))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (unaryExpr
                  (intLiteral))
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (intLiteral)
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (intLiteral)
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (intLiteral)
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (intLiteral)
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (unaryExpr
                  (intLiteral))
                (intLiteral))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)
              (argumentList
                (intLiteral))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (unaryExpr
                  (intLiteral)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (unaryExpr
                  (intLiteral)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (unaryExpr
                  (intLiteral)))))
          (lineComment)
          (lineComment)
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)))
          (objectElement
            (parenthesizedExpr
              (propertyCallExpr
                (variableExpr
                  (identifier))
                (identifier))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))))
              (identifier)
              (argumentList
                (propertyCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))))
              (identifier)
              (argumentList
                (propertyCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (methodCallExpr
                    (methodCallExpr
                      (identifier)
                      (argumentList
                        (unaryExpr
                          (intLiteral))
                        (intLiteral)))
                    (identifier)
                    (argumentList
                      (intLiteral)))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (unaryExpr
                    (intLiteral))))
              (identifier)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (unaryExpr
                    (intLiteral))))
              (identifier)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (unaryExpr
                      (intLiteral))
                    (intLiteral)))
                (identifier)
                (argumentList
                  (intLiteral)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (unaryExpr
                    (intLiteral))))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (unaryExpr
                      (intLiteral))
                    (intLiteral)))
                (identifier)
                (argumentList
                  (intLiteral)))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (methodCallExpr
                  (identifier)
                  (argumentList))
                (functionLiteral
                  (parameterList
                    (typedIdentifier
                      (identifier))
                    (typedIdentifier
                      (identifier)))
                  (methodCallExpr
                    (variableExpr
                      (identifier))
                    (identifier)
                    (argumentList
                      (variableExpr
                        (identifier))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (unaryExpr
                      (intLiteral))
                    (intLiteral)))
                (identifier)
                (argumentList
                  (intLiteral)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (methodCallExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (lineComment)
          (lineComment)
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)))
              (identifier)))
          (objectElement
            (methodCallExpr
              (parenthesizedExpr
                (propertyCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))))
              (identifier)))
          (objectElement
            (methodCallExpr
              (parenthesizedExpr
                (propertyCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))
          (objectElement
            (propertyCallExpr
              (methodCallExpr
                (identifier)
                (argumentList
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))
                  (propertyCallExpr
                    (variableExpr
                      (identifier))
                    (identifier))))
              (identifier)))
          (objectElement
            (methodCallExpr
              (parenthesizedExpr
                (propertyCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)))
              (identifier)
              (argumentList
                (variableExpr
                  (identifier)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (newExpr
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (objectBody))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)))
                (identifier)
                (argumentList))
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)
                  (intLiteral)
                  (intLiteral)))))
          (objectElement
            (binaryExpr
              (methodCallExpr
                (methodCallExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (unaryExpr
                        (intLiteral))
                      (intLiteral)))
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (identifier)
                (argumentList))
              (methodCallExpr
                (identifier)
                (argumentList
                  (unaryExpr
                    (intLiteral))
                  (unaryExpr
                    (intLiteral))
                  (intLiteral)))))
          (objectElement
            (binaryExpr
              (methodCallExpr
                (methodCallExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)))
                  (identifier)
                  (argumentList
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList))
              (methodCallExpr
                (identifier)
                (argumentList
                  (intLiteral)
                  (intLiteral)
                  (intLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (methodCallExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)))
                (identifier)
                (argumentList))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectElement
                    (intLiteral))
                  (objectElement
                    (intLiteral))
                  (objectElement
                    (intLiteral))
                  (objectElement
                    (intLiteral))))))
          (objectElement
            (binaryExpr
              (methodCallExpr
                (methodCallExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (unaryExpr
                        (intLiteral))
                      (intLiteral)))
                  (identifier)
                  (argumentList
                    (intLiteral)))
                (identifier)
                (argumentList))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectElement
                    (binaryExpr
                      (unaryExpr
                        (intLiteral))
                      (intLiteral)))
                  (objectElement
                    (intLiteral))))))
          (objectElement
            (binaryExpr
              (methodCallExpr
                (methodCallExpr
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (intLiteral)
                      (intLiteral)))
                  (identifier)
                  (argumentList
                    (unaryExpr
                      (intLiteral))))
                (identifier)
                (argumentList))
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectElement
                    (intLiteral))
                  (objectElement
                    (intLiteral))
                  (objectElement
                    (intLiteral)))))))))))
