<commit_before>require 'support/helper'

class RoutingTest < MiniTest::Unit::TestCase
  attr_accessor :set_registered
  attr_accessor :fn_calls

  def setup
    @fn_calls = []
  end

  # RouteSet

  def test_fn_is_registered_and_fetchable
    set = RouteSet.new

    fn1 = lambda {}
    fn2 = lambda {}

    set.fn(:foo, &fn1)
    set.fn(:bar, &fn2)

    assert_same fn1, set.fn(:foo)[0]
    assert_same fn2, set.fn(:bar)[0]
  end

  def test_default_route_is_created_and_matched
    set = RouteSet.new

    fn1 = lambda {}
    set.default(fn1)
    assert_route_tuple set.match('/', :get), ["", [], :default, fn1, ""]
  end

  def test_all_routes_are_created_and_matched
    set = RouteSet.new

    fn1 = lambda {}
    fn2 = lambda {}
    fn3 = lambda {}
    fn4 = lambda {}
    
    set.get('get', fn1)
    assert_route_tuple set.match('get', :get), ["get", [], nil, fn1, "get"]

    set.post('post', fn2)
    assert_route_tuple set.match('post', :post), ["post", [], nil, fn1, "post"]

    set.put('put', fn3)
    assert_route_tuple set.match('put', :put), ["put", [], nil, fn1, "put"]

    set.delete('delete', fn4)
    assert_route_tuple set.match('delete', :delete), ["delete", [], nil, fn1, "delete"]
  end

  def test_fn_list_can_be_passed_for_route
    set = RouteSet.new

    fn1 = lambda {}
    set.fn(:foo, &fn1)
    set.get('foo', set.fn(:foo))

    assert_same fn1, set.match('foo', :get)[0][3][0]
  end

  def test_route_can_be_defined_without_fn
    set = RouteSet.new
    set.get('foo')

    assert !set.match('foo', :get).nil?
  end

  def test_single_fn_is_passable_to_route
    set = RouteSet.new<commit_msg>Fix route test<commit_after>require 'support/helper'

class RoutingTest < MiniTest::Unit::TestCase
  attr_accessor :set_registered
  attr_accessor :fn_calls

  def setup
    @fn_calls = []
  end

  # RouteSet

  def test_fn_is_registered_and_fetchable
    set = RouteSet.new

    fn1 = lambda {}
    fn2 = lambda {}

    set.fn(:foo, &fn1)
    set.fn(:bar, &fn2)

    assert_same fn1, set.fn(:foo)[0]
    assert_same fn2, set.fn(:bar)[0]
  end

  def test_default_route_is_created_and_matched
    set = RouteSet.new

    fn1 = lambda {}
    set.default(fn1)
    assert_route_tuple set.match('/', :get), ["", [], :default, fn1, ""]
  end

  def test_all_routes_are_created_and_matched
    set = RouteSet.new

    fn1 = lambda {}
    fn2 = lambda {}
    fn3 = lambda {}
    fn4 = lambda {}
    
    set.get('get', fn1)
    assert_route_tuple set.match('get', :get), ["get", [], nil, fn1, "get"]

    set.post('post', fn2)
    assert_route_tuple set.match('post', :post), ["post", [], nil, fn2, "post"]

    set.put('put', fn3)
    assert_route_tuple set.match('put', :put), ["put", [], nil, fn3, "put"]

    set.delete('delete', fn4)
    assert_route_tuple set.match('delete', :delete), ["delete", [], nil, fn4, "delete"]
  end

  def test_fn_list_can_be_passed_for_route
    set = RouteSet.new

    fn1 = lambda {}
    set.fn(:foo, &fn1)
    set.get('foo', set.fn(:foo))

    assert_same fn1, set.match('foo', :get)[0][3][0]
  end

  def test_route_can_be_defined_without_fn
    set = RouteSet.new
    set.get('foo')

    assert !set.match('foo', :get).nil?
  end

  def test_single_fn_is_passable_to_route
    set = RouteSet.new
{'fraction_non_alphanumeric': 0.15606758832565285, 'fraction_numerical': 0.017818740399385562, 'mean_word_length': 3.3011889035667106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4916695', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1218, 'n_words': 247}