================================================================================
basic/string
================================================================================

amends "../snippetTest.pkl"

local str1 = "How"
local str2 = "you"
local str3 = "this"

examples {
  ["equality"] {
    "abc" == "abc"
    "abc" == "abd"
  }

  ["inequality"] {
    "abc" != "abc"
    "abc" != "abd"
  }

  ["interpolation"] {
    "\(str1) are \(str2) today? Are \(str2) hungry?"
    "Can \(str2 + " nest \(str3)") for me?"
    "Is \(str1 + str2) a word?"
    "Is \("soma") a word?"
    "Can \(str2 + " nest (((") for me?"
    "Can \(str2 + " nest )))") for me?"
    "Can you \( new Dynamic { x = "nest \( new Dynamic { y = str3 }.y )" }.x ) for me?"
  }

  ["interpolation of different types"] {
    "\(42)"
    "\(1.23)"
    "\("Pigeon")"
    "\(false)"
    "\(1.23.ns)"
    "\(1.23.mb)"
    "\(Pair(1, 2))"
    "\(List(1, 2, 3))"
    "\(Set(1, 2, 3))"
    "\(Map(1, 2, 3, 4))"
    "\(new Listing { 1 2 3 })"
    "\(new Mapping { ["Pigeon"] = 42; ["Barn Owl"] = 21 })"
    "\(new Dynamic { name = "Pigeon"; age = 42 })"
    "\(new Person { name = "Pigeon"; age = 42 })"
    "\(new Person2 { name = "Pigeon"; age = 42 })"
    "\(null)"
    "\(Null(new Person { name = "Pigeon"; age = 42 }))"
  }

  ["escaping"] {
    "\\\"\\("
    "\t\r\n"
    "\u{9}\u{30}\u{100}\u{1000}\u{10000}\u{010000}\u{0010000}\u{00010000}"
  }

  ["subscript"] {
    str3[2]
    module.catch(() -> str3[-1])
    module.catch(() -> str3[4])
  }

  ["dollar sign has no special meaning"] {
    "123$"
    "$123"
    "$&%"
    "$"
  }
}

local class Person { name: String; age: Int }

local class Person2 {
  name: String
  age: Int
  function toString() = "My name is \(name) and I'm \(age) years old."
}

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

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (classProperty
    (modifier)
    (identifier)
    (slStringLiteral))
  (classProperty
    (modifier)
    (identifier)
    (slStringLiteral))
  (classProperty
    (modifier)
    (identifier)
    (slStringLiteral))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (slStringLiteral)
              (slStringLiteral)))
          (objectElement
            (binaryExpr
              (slStringLiteral)
              (slStringLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (slStringLiteral)
              (slStringLiteral)))
          (objectElement
            (binaryExpr
              (slStringLiteral)
              (slStringLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (variableExpr
                  (identifier)))
              (interpolationExpr
                (variableExpr
                  (identifier)))
              (interpolationExpr
                (variableExpr
                  (identifier)))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (binaryExpr
                  (variableExpr
                    (identifier))
                  (slStringLiteral
                    (interpolationExpr
                      (variableExpr
                        (identifier))))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (binaryExpr
                  (variableExpr
                    (identifier))
                  (variableExpr
                    (identifier))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (slStringLiteral))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (binaryExpr
                  (variableExpr
                    (identifier))
                  (slStringLiteral)))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (binaryExpr
                  (variableExpr
                    (identifier))
                  (slStringLiteral)))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (propertyCallExpr
                  (newExpr
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (objectBody
                      (objectProperty
                        (identifier)
                        (slStringLiteral
                          (interpolationExpr
                            (propertyCallExpr
                              (newExpr
                                (type
                                  (qualifiedIdentifier
                                    (identifier)))
                                (objectBody
                                  (objectProperty
                                    (identifier)
                                    (variableExpr
                                      (identifier)))))
                              (identifier)))))))
                  (identifier)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (intLiteral))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (floatLiteral))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (slStringLiteral))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (falseLiteral))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (propertyCallExpr
                  (floatLiteral)
                  (identifier)))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (propertyCallExpr
                  (floatLiteral)
                  (identifier)))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)
                    (intLiteral))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)
                    (intLiteral))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (intLiteral)
                    (intLiteral)
                    (intLiteral)
                    (intLiteral))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (objectElement
                      (intLiteral))
                    (objectElement
                      (intLiteral))
                    (objectElement
                      (intLiteral)))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (objectEntry
                      (slStringLiteral)
                      (intLiteral))
                    (objectEntry
                      (slStringLiteral)
                      (intLiteral)))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (objectProperty
                      (identifier)
                      (slStringLiteral))
                    (objectProperty
                      (identifier)
                      (intLiteral)))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (objectProperty
                      (identifier)
                      (slStringLiteral))
                    (objectProperty
                      (identifier)
                      (intLiteral)))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (newExpr
                  (type
                    (qualifiedIdentifier
                      (identifier)))
                  (objectBody
                    (objectProperty
                      (identifier)
                      (slStringLiteral))
                    (objectProperty
                      (identifier)
                      (intLiteral)))))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (nullLiteral))))
          (objectElement
            (slStringLiteral
              (interpolationExpr
                (methodCallExpr
                  (identifier)
                  (argumentList
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectProperty
                          (identifier)
                          (slStringLiteral))
                        (objectProperty
                          (identifier)
                          (intLiteral)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (slStringLiteral
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)))
          (objectElement
            (slStringLiteral
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)))
          (objectElement
            (slStringLiteral
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)
              (escapeSequence)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (subscriptExpr
              (variableExpr
                (identifier))
              (intLiteral)))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (subscriptExpr
                    (variableExpr
                      (identifier))
                    (unaryExpr
                      (intLiteral)))))))
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (subscriptExpr
                    (variableExpr
                      (identifier))
                    (intLiteral))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (slStringLiteral))
          (objectElement
            (slStringLiteral))
          (objectElement
            (slStringLiteral))
          (objectElement
            (slStringLiteral))))))
  (clazz
    (modifier)
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier)))))
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier)))))))
  (clazz
    (modifier)
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier)))))
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier)))))
      (classMethod
        (methodHeader
          (identifier)
          (parameterList))
        (slStringLiteral
          (interpolationExpr
            (variableExpr
              (identifier)))
          (interpolationExpr
            (variableExpr
              (identifier))))))))
