<commit_before>/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* Notation.vala
 *
 * Copyright (C) 2016  <NAME> <<EMAIL>>
 * Copyright (C) 2016  <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      <NAME> <<EMAIL>>
 *      <NAME> <<EMAIL>>
 */

using GXml;

class GElementXPathTest : GXmlTest  {
  public static void add_tests () {
    Test.add_func ("/gxml/gelement/xpath", () => {
      var document = new GDocument.from_uri ("http://www.w3schools.com/xsl/books.xml");
      var object = document.evaluate ("/bookstore/book/title");
      assert (object.object_type == XPathObjectType.NODESET);
      var array = object.nodeset.to_array();
      assert (array.length == 4);
      assert (array[0].node_value == "Everyday Italian");
      assert (array[1].node_value == "Harry Potter");
      assert (array[2].node_value == "XQuery Kick Start");
      assert (array[3].node_value == "Learning XML");
      object = document.evaluate ("/bookstore/book[1]/title");
      assert (object.object_type == XPathObjectType.NODESET);
      array = object.nodeset.to_array();
      assert (array.length == 1);
      assert (array[0].node_value == "Everyday Italian");
      object = document.evaluate ("/bookstore/book/price[text()]");
      assert (object.object_type == XPathObjectType.NODESET);
      array = object.nodeset.to_array();
      assert (array.length == 4);
      assert (array[0].node_value == "30.00");
      assert (array[1].node_value == "29.99");
      assert (array[2].node_value == "49.99");
      assert (array[3].node_value == "39.95");
      object = document.evaluate ("/bookstore/book[price>35]/price");
      assert (object.object_type == XPathObjectType.NODESET);
      array = object.nodeset.to_array();
      assert (array.length == 2);
      assert (array[0].node_value == "49.99");
      assert (array[1].node_value == "39.95");
		});
	}
}<commit_msg>Fixed Unit Tests for GDocument and XPath implementation<commit_after>/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* Notation.vala
 *
 * Copyright (C) 2016  <NAME> <<EMAIL>>
 * Copyright (C) 2016  <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      <NAME> <<EMAIL>>
 *      <NAME> <<EMAIL>>
 */

using GXml;

class GElementXPathTest : GXmlTest  {
  // Taken from:
  const string BOOKS = """<bookstore><book category="COOKING"><title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author><year>2005</year><price>30.00</price></book><book category="CHILDREN"><title lang="en">Harry Potter</title><author><NAME></author><year>2005</year><price>29.99</price></book><book category="WEB"><title lang="en">XQuery Kick Start</title><author><NAME></author><author><NAME></author><author><NAME></author><author><NAME></author><author><NAME></author><year>2003</year><price>49.99</price></book><book category="WEB"><title lang="en">Learning XML</title><author><NAME></author><year>2003</year><price>39.95</price></book></bookstore>""";
  public static void add_tests () {
    Test.add_func ("/gxml/gelement/xpath", () => {
      try {
      Document document = null;
      var rf = GLib.File.new_for_uri ("http://www.w3schools.com/xsl/books.xml");
      if (rf.query_exists ()) {
        document = new GDocument.from_uri ("http://www.w3schools.com/xsl/books.xml");
      } else
        document = new GDocument.from_string (BOOKS);
      assert (document != null);
      var object = (document as XPathContext).evaluate ("/bookstore/book/title");
      assert (object.object_type == XPathObjectType.NODESET);
      var array = object.nodeset.to_array();
      assert (array.length == 4);
      assert (array[0].node_value == "Everyday Italian");
      assert (array[1].node_value == "<NAME>");
      assert (array[2].node_value == "XQuery Kick Start");
      assert (array[3].node_value == "Learning XML");
      object = (document as XPathContext).evaluate ("/bookstore/book[1]/title");
      assert (object.object_type == XPathObjectType.NODESET);
      array = object.nodeset.to_array();
      assert (array.length == 1);
      assert (array[0].node_value == "Everyday Italian");
      object = (document as XPathContext).evaluate ("/bookstore/book/price[text()]");
      assert (object.object_type == XPathObjectType.NODESET);
      array = object.nodeset.to_array();
      assert (array.length == 4);
      assert (array[0].node_value == "30.00");
      assert (array[1].node_value == "29.99");
      assert (array[2].node_value == "49.99");
      assert (array[3].node_value == "39.95");
      object = (document as XPathContext).evaluate ("/bookstore/book[price>35]/price");
      assert (object.object_type == XPathObjectType.NODESET);
      array = object.nodeset.to_array();
      assert (array.length == 2);
      assert (array[0].node_value == "49.99");
      assert (array[1].node_value == "39.95");
      } catch (GLib.Error e) {
        GLib.message ("ERROR: "+e.message);
        assert_not_reached ();
      }
		});
	}
}
{'fraction_non_alphanumeric': 0.15944100365253294, 'fraction_numerical': 0.022709226615848815, 'mean_word_length': 3.5538684020245843, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 5, 'xml': 5}, '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': '5296155', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1919, 'n_words': 515}