<commit_before>
$: << File.dirname(__FILE__)
require 'test_helper'

class LanguagesTests < PostgreSQLExtensionsTestCase
  def test_create_language
    ARBC.create_language(:foo)
    ARBC.create_language(
      :foo,
      :trusted => true,
      :call_handler => 'plpgsql',
      :validator => 'test()'
    )

    assert_equal([
      %{CREATE PROCEDURAL LANGUAGE "foo";},
      %{CREATE TRUSTED PROCEDURAL LANGUAGE "foo" HANDLER "plpgsql" VALIDATOR test();}
    ], statements)
  end

  def test_drop_language
    ARBC.drop_language(:foo)
    ARBC.drop_language(:foo, :if_exists => true, :cascade => true)

    assert_equal([
      %{DROP PROCEDURAL LANGUAGE "foo";},
      %{DROP PROCEDURAL LANGUAGE IF EXISTS "foo" CASCADE;}
    ], statements)
  end

  def test_alter_language_name
    ARBC.alter_language_name(:foo, :bar)

    assert_equal([
      %{ALTER PROCEDURAL LANGUAGE "foo" RENAME TO "bar";}
    ], statements)
  end

  def test_alter_language_owner
    ARBC.alter_language_owner(:foo, :bar)

    assert_equal([
      %{ALTER PROCEDURAL LANGUAGE "foo" OWNER TO "bar";}
    ], statements)
  end
end<commit_msg>Add some tests for `languages` and `language_exists?`.<commit_after>
$: << File.dirname(__FILE__)
require 'test_helper'

class LanguagesTests < PostgreSQLExtensionsTestCase
  def test_create_language
    ARBC.create_language(:foo)
    ARBC.create_language(
      :foo,
      :trusted => true,
      :call_handler => 'plpgsql',
      :validator => 'test()'
    )

    assert_equal([
      %{CREATE PROCEDURAL LANGUAGE "foo";},
      %{CREATE TRUSTED PROCEDURAL LANGUAGE "foo" HANDLER "plpgsql" VALIDATOR test();}
    ], statements)
  end

  def test_drop_language
    ARBC.drop_language(:foo)
    ARBC.drop_language(:foo, :if_exists => true, :cascade => true)

    assert_equal([
      %{DROP PROCEDURAL LANGUAGE "foo";},
      %{DROP PROCEDURAL LANGUAGE IF EXISTS "foo" CASCADE;}
    ], statements)
  end

  def test_alter_language_name
    ARBC.alter_language_name(:foo, :bar)

    assert_equal([
      %{ALTER PROCEDURAL LANGUAGE "foo" RENAME TO "bar";}
    ], statements)
  end

  def test_alter_language_owner
    ARBC.alter_language_owner(:foo, :bar)

    assert_equal([
      %{ALTER PROCEDURAL LANGUAGE "foo" OWNER TO "bar";}
    ], statements)
  end

  def test_languages
    ARBC.real_execute do
      languages = ARBC.languages

      assert_kind_of(Array, languages)
      assert_includes(languages, "sql")
      assert_includes(languages, "c")
      assert_includes(languages, "internal")
    end
  end

  def test_language_exists
    ARBC.real_execute do
      assert(ARBC.language_exists?("sql"))
      assert(ARBC.language_exists?("c"))
      assert(ARBC.language_exists?("internal"))
    end
  end
end
{'fraction_non_alphanumeric': 0.11618560467665327, 'fraction_numerical': 0.0, 'mean_word_length': 3.4811783960720133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7185998', 'n_tokens_mistral': 996, 'n_tokens_neox': 945, 'n_words': 200}