<commit_before># -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2011  <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 version 2.1 as published by the Free Software Foundation.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

module HTTPSchemaTests
  module Utils
    include GroongaHTTPTestUtils

    def setup
      setup_server
    end

    def teardown
      teardown_server
    end

    private
    def create_bookmarks_table
      @bookmarks_table_id = table_create("bookmarks",
                                         :flags => Table::PAT_KEY,
                                         :key_type => "ShortText",
                                         :value_type => "Object",
                                         :default_tokenizer => "")
    end

    def create_bookmark_title_column
      @bookmarks_title_column_id = column_create("bookmarks",
                                                 "title",
                                                 Column::SCALAR,
                                                 "ShortText")
    end

    def assert_table_list(expected)
      response = get(command_path(:table_list, :output_type => output_type))
      expected = expected.collect do |values|
        id, name, flags, domain, range = values
        [id, name, nil, flags, domain, range]
      end
      assert_response_body([[["id", "UInt32"],
                             ["name", "ShortText"],
                             ["path", "ShortText"],
                             ["flags", "ShortText"],
                             ["domain", "ShortText"],
                             ["range", "ShortText"]],
                            *expected],
                           response,
                           :content_type => content_type) do |actual|
        status, result = actual
        header, *values = result
        values = values.collect do |value|
          id, name, path, flags, domain, range = value
          [id, name, nil, flags, domain, range]
        end
        [status, [header, *values]]
      end
    end

    def assert_column_list(expected, options)
      options = options.merge(:output_type => output_type)
      response = get(command_path(:column_list, options))
      expected = expected.collect do |values|
        id, name, type, flags, domain, range, source = values
        [id, name, nil, type, flags, domain, range, source]
      end
      assert_response_body([[["id", "UInt32"],
                             ["name", "ShortText"],
                             ["path", "ShortText"],
                             ["type", "ShortText"],
                             ["flags", "ShortText"],
                             ["domain", "ShortText"],
                             ["range", "ShortText"],
                             ["source", "ShortText"]],
                            *expected],
                           response,
                           :content_type => content_type) do |actual|
        status, result = actual
        header, *values = result
        values = values.collect do |value|
          id, name, path, type, flags, domain, range, source = value
          [id, name, nil, type, flags, domain, range, source]
        end
        [status, [header, *values]]
      end
    end
  end

  include Utils

  def test_table_list_empty
    assert_table_list([])
  end

  def test_table_list_exist
    create_bookmarks_table
    assert_table_list([[@bookmarks_table_id,
                        "bookmarks",
                        "TABLE_PAT_KEY|PERSISTENT",
                        "ShortText",
                        "Object"]])
  end

  def test_table_list_with_invalid_output_type
    omit('now invalid output types are interpreted to json')
    response = get(command_path(:table_list,
                                :output_type => "unknown"))
    assert_response([[Result::UNKNOWN_ERROR, "should be implemented"]],
                    response,
                    :content_type => content_type)
  end

  def test_column_list_empty
    create_bookmarks_table
    assert_column_list([[@bookmarks_table_id,
                         "_key",
                         "",
                         "COLUMN_SCALAR",
                         "bookmarks",
                         "ShortText",
                         []]],
                       :table => "bookmarks")
  end

  def test_column_list_exist<commit_msg>test: remove a duplicated test of grntest<commit_after># -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2011  <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 version 2.1 as published by the Free Software Foundation.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

module HTTPSchemaTests
  module Utils
    include GroongaHTTPTestUtils

    def setup
      setup_server
    end

    def teardown
      teardown_server
    end

    private
    def create_bookmarks_table
      @bookmarks_table_id = table_create("bookmarks",
                                         :flags => Table::PAT_KEY,
                                         :key_type => "ShortText",
                                         :value_type => "Object",
                                         :default_tokenizer => "")
    end

    def create_bookmark_title_column
      @bookmarks_title_column_id = column_create("bookmarks",
                                                 "title",
                                                 Column::SCALAR,
                                                 "ShortText")
    end

    def assert_table_list(expected)
      response = get(command_path(:table_list, :output_type => output_type))
      expected = expected.collect do |values|
        id, name, flags, domain, range = values
        [id, name, nil, flags, domain, range]
      end
      assert_response_body([[["id", "UInt32"],
                             ["name", "ShortText"],
                             ["path", "ShortText"],
                             ["flags", "ShortText"],
                             ["domain", "ShortText"],
                             ["range", "ShortText"]],
                            *expected],
                           response,
                           :content_type => content_type) do |actual|
        status, result = actual
        header, *values = result
        values = values.collect do |value|
          id, name, path, flags, domain, range = value
          [id, name, nil, flags, domain, range]
        end
        [status, [header, *values]]
      end
    end

    def assert_column_list(expected, options)
      options = options.merge(:output_type => output_type)
      response = get(command_path(:column_list, options))
      expected = expected.collect do |values|
        id, name, type, flags, domain, range, source = values
        [id, name, nil, type, flags, domain, range, source]
      end
      assert_response_body([[["id", "UInt32"],
                             ["name", "ShortText"],
                             ["path", "ShortText"],
                             ["type", "ShortText"],
                             ["flags", "ShortText"],
                             ["domain", "ShortText"],
                             ["range", "ShortText"],
                             ["source", "ShortText"]],
                            *expected],
                           response,
                           :content_type => content_type) do |actual|
        status, result = actual
        header, *values = result
        values = values.collect do |value|
          id, name, path, type, flags, domain, range, source = value
          [id, name, nil, type, flags, domain, range, source]
        end
        [status, [header, *values]]
      end
    end
  end

  include Utils

  def test_table_list_empty
    assert_table_list([])
  end

  def test_table_list_with_invalid_output_type
    omit('now invalid output types are interpreted to json')
    response = get(command_path(:table_list,
                                :output_type => "unknown"))
    assert_response([[Result::UNKNOWN_ERROR, "should be implemented"]],
                    response,
                    :content_type => content_type)
  end

  def test_column_list_empty
    create_bookmarks_table
    assert_column_list([[@bookmarks_table_id,
                         "_key",
                         "",
                         "COLUMN_SCALAR",
                         "bookmarks",
                         "ShortText",
                         []]],
                       :table => "bookmarks")
  end

  def test_column_list_exist
{'fraction_non_alphanumeric': 0.09212032892682419, 'fraction_numerical': 0.005412719891745603, 'mean_word_length': 1.5290866017372993, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2745148', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2296, 'n_words': 704}