<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.calcite.test;

import org.apache.calcite.runtime.CalciteException;
import org.apache.calcite.runtime.SqlFunctions;
import org.apache.calcite.runtime.XmlFunctions;
import org.apache.calcite.util.BuiltInMethod;

import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;

import java.util.function.Supplier;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * Unit test for the methods in {@link SqlFunctions} that implement Xml processing functions.
 */
public class SqlXmlFunctionsTest {

  @Test
  public void testExtractValue() {
    assertExtractValue("<a>ccc<b>ddd</b></a>", "/a", is("ccc"));

    String input = "<a>ccc<b>ddd</b></a>";
    String message = "Illegal behavior "
        + "'javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: "
        + "A location path was expected, but the following token was encountered:  #' "
        + "EXTRACTVALUE: document: '" + input + "', xpath expression: '#'";
    CalciteException expected = new CalciteException(message, null);
    assertExtractValueFailed(input, "#", Matchers.expectThrowable(expected));
  }

  private void assertExtractValue(String input, String xpath,
      Matcher<? super String> matcher) {
    String extractMethodDesc =
        BuiltInMethod.EXTRACT_VALUE.getMethodName() + "(" + String.join(", ", input) + ")";
    assertThat(extractMethodDesc, XmlFunctions.extractValue(input, xpath), matcher);
  }<commit_msg>Following [CALCITE-3552] fix style issue<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.calcite.test;

import org.apache.calcite.runtime.CalciteException;
import org.apache.calcite.runtime.SqlFunctions;
import org.apache.calcite.runtime.XmlFunctions;
import org.apache.calcite.util.BuiltInMethod;

import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;

import java.util.function.Supplier;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * Unit test for the methods in {@link SqlFunctions} that implement Xml processing functions.
 */
public class SqlXmlFunctionsTest {

  @Test public void testExtractValue() {
    assertExtractValue("<a>ccc<b>ddd</b></a>", "/a", is("ccc"));

    String input = "<a>ccc<b>ddd</b></a>";
    String message = "Illegal behavior "
        + "'javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: "
        + "A location path was expected, but the following token was encountered:  #' "
        + "EXTRACTVALUE: document: '" + input + "', xpath expression: '#'";
    CalciteException expected = new CalciteException(message, null);
    assertExtractValueFailed(input, "#", Matchers.expectThrowable(expected));
  }

  private void assertExtractValue(String input, String xpath,
      Matcher<? super String> matcher) {
    String extractMethodDesc =
        BuiltInMethod.EXTRACT_VALUE.getMethodName() + "(" + String.join(", ", input) + ")";
    assertThat(extractMethodDesc, XmlFunctions.extractValue(input, xpath), matcher);
  }
{'fraction_non_alphanumeric': 0.10489804498633593, 'fraction_numerical': 0.002522598276224511, 'mean_word_length': 4.443935926773455, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2497250', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1300, 'n_words': 428}