================================================================================
api/xmlRendererValidation11
================================================================================

amends ".../snippetTest.pkl"

import "pkl:xml"

local function render(value: Any) = new xml.Renderer { xmlVersion = "1.1" }.renderValue(value)

examples {
  ["invalid attribute"] {
    module.catch(() ->
      render((xml.Element("bar")) {
        attributes {
          ["bar baz"] = "biz"
        }
      })
    )
  }
  ["colons are allowed"] {
    render((xml.Element("bar")) {
      attributes {
        ["xs:myTag"] = "my tag value"
      }
    })
  }
  ["escaping attribute values"] {
    render((xml.Element("bar")) {
      attributes {
        ["bar"] = "buz\"><script>maliciousThing();</script>"
      }
    })
  }
  ["invalid element name"] {
    module.catch(() ->
      render(xml.Element("bar>"))
    )
  }
  ["invalid empty element name"] {
    module.catch(() -> render((xml.Element("foo")) {
      name = ""
    }))
  }
  ["invalid empty attribute name"] {
    module.catch(() -> render((xml.Element("div")) {
      attributes {
        [""] = "bar"
      }
    }))
  }
  ["Unicode element name is allowed"] {
    render(xml.Element("😍😎😡"))
  }
  ["Unicode attribute name is allowed"] {
    render((xml.Element("div")) {
      attributes {
        ["😍😎😡"] = "bar"
      }
    })
  }
}

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

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (importClause
    (stringConstant))
  (classMethod
    (methodHeader
      (modifier)
      (identifier)
      (parameterList
        (typedIdentifier
          (identifier)
          (typeAnnotation
            (type
              (qualifiedIdentifier
                (identifier)))))))
    (methodCallExpr
      (newExpr
        (type
          (qualifiedIdentifier
            (identifier)
            (identifier)))
        (objectBody
          (objectProperty
            (identifier)
            (slStringLiteral))))
      (identifier)
      (argumentList
        (variableExpr
          (identifier)))))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (objectLiteral
                        (parenthesizedExpr
                          (methodCallExpr
                            (variableExpr
                              (identifier))
                            (identifier)
                            (argumentList
                              (slStringLiteral))))
                        (objectBody
                          (objectProperty
                            (identifier)
                            (objectBody
                              (objectEntry
                                (slStringLiteral)
                                (slStringLiteral))))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (objectLiteral
                  (parenthesizedExpr
                    (methodCallExpr
                      (variableExpr
                        (identifier))
                      (identifier)
                      (argumentList
                        (slStringLiteral))))
                  (objectBody
                    (objectProperty
                      (identifier)
                      (objectBody
                        (objectEntry
                          (slStringLiteral)
                          (slStringLiteral)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (objectLiteral
                  (parenthesizedExpr
                    (methodCallExpr
                      (variableExpr
                        (identifier))
                      (identifier)
                      (argumentList
                        (slStringLiteral))))
                  (objectBody
                    (objectProperty
                      (identifier)
                      (objectBody
                        (objectEntry
                          (slStringLiteral)
                          (slStringLiteral
                            (escapeSequence))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (methodCallExpr
                        (variableExpr
                          (identifier))
                        (identifier)
                        (argumentList
                          (slStringLiteral)))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (objectLiteral
                        (parenthesizedExpr
                          (methodCallExpr
                            (variableExpr
                              (identifier))
                            (identifier)
                            (argumentList
                              (slStringLiteral))))
                        (objectBody
                          (objectProperty
                            (identifier)
                            (slStringLiteral))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (moduleExpr)
              (identifier)
              (argumentList
                (functionLiteral
                  (parameterList)
                  (methodCallExpr
                    (identifier)
                    (argumentList
                      (objectLiteral
                        (parenthesizedExpr
                          (methodCallExpr
                            (variableExpr
                              (identifier))
                            (identifier)
                            (argumentList
                              (slStringLiteral))))
                        (objectBody
                          (objectProperty
                            (identifier)
                            (objectBody
                              (objectEntry
                                (slStringLiteral)
                                (slStringLiteral))))))))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (methodCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)
                  (argumentList
                    (slStringLiteral))))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (methodCallExpr
              (identifier)
              (argumentList
                (objectLiteral
                  (parenthesizedExpr
                    (methodCallExpr
                      (variableExpr
                        (identifier))
                      (identifier)
                      (argumentList
                        (slStringLiteral))))
                  (objectBody
                    (objectProperty
                      (identifier)
                      (objectBody
                        (objectEntry
                          (slStringLiteral)
                          (slStringLiteral))))))))))))))
