<commit_before>class TestArbitrary < MiniTest::Unit::TestCase
  def test_match
    hello, love80, love8080 = router {
      add('test').arbitrary(Proc.new{|req, params| req.rack.host == 'hellodooly' })
      add("test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
    }
    assert_route love8080, 'http://lovelove:8080/test'
  end

  def test_less_specific_node
    hello, love80, love8080, general = router {
      add("/test").arbitrary(Proc.new{|req, params| req.rack.host == 'hellodooly' })
      add("/test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("/test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
      add("/test")
    }
    assert_route general,  'http://lovelove:8081/test'
    assert_route hello,    'http://hellodooly:8081/test'
    assert_route love80,   'http://lovelove:80/test'
    assert_route love8080, 'http://lovelove:8080/test'
  end

  def test_match_request
    love80, love8080 = router {
      add("/test").get.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("/test").get.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
    }
    assert_route love80,   'http://lovelove:80/test'
    assert_route love8080, 'http://lovelove:8080/test'
  end

  def test_less_specific_with_request
    love80, love8080, general = router {
      add("test").post.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("test").post.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
      add("test").post
    }
    assert_route love8080, Rack::MockRequest.env_for('http://lovelove:8080/test', :method => :post)
    assert_route love80,   Rack::MockRequest.env_for('http://lovelove:80/test', :method => :post)
    assert_route general,  Rack::MockRequest.env_for('/test', :method => :post)
  end

  def test_pass_params
    r = router {
      add(":test").get.arbitrary(Proc.new{|req, params, dest| params[:test] == 'test' })
    }
    assert_route r, '/test', {:test => 'test'}
  end

  def test_continue
    no, yes = router {
      add('test').arbitrary_with_continue{|req, p| req.continue[false]}
      add('test').arbitrary_with_continue{|req, p| req.continue[true]}
    }
    assert_route yes, '/test'
  end
end<commit_msg>add passing test<commit_after>class TestArbitrary < MiniTest::Unit::TestCase
  def test_match
    hello, love80, love8080 = router {
      add('test').arbitrary(Proc.new{|req, params| req.rack.host == 'hellodooly' })
      add("test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
    }
    assert_route love8080, 'http://lovelove:8080/test'
  end

  def test_less_specific_node
    hello, love80, love8080, general = router {
      add("/test").arbitrary(Proc.new{|req, params| req.rack.host == 'hellodooly' })
      add("/test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("/test").arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
      add("/test")
    }
    assert_route general,  'http://lovelove:8081/test'
    assert_route hello,    'http://hellodooly:8081/test'
    assert_route love80,   'http://lovelove:80/test'
    assert_route love8080, 'http://lovelove:8080/test'
  end

  def test_match_request
    love80, love8080 = router {
      add("/test").get.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("/test").get.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
    }
    assert_route love80,   'http://lovelove:80/test'
    assert_route love8080, 'http://lovelove:8080/test'
  end

  def test_less_specific_with_request
    love80, love8080, general = router {
      add("test").post.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 80}
      add("test").post.arbitrary(Proc.new{|req, params| req.rack.host == 'lovelove' }).arbitrary{|req, params| req.rack.port == 8080}
      add("test").post
    }
    assert_route love8080, Rack::MockRequest.env_for('http://lovelove:8080/test', :method => :post)
    assert_route love80,   Rack::MockRequest.env_for('http://lovelove:80/test', :method => :post)
    assert_route general,  Rack::MockRequest.env_for('/test', :method => :post)
  end

  def test_pass_params
    r = router {
      add(":test").get.arbitrary(Proc.new{|req, params, dest| params[:test] == 'test' })
    }
    assert_route r, '/test', {:test => 'test'}
  end

  def test_passing
    never, route = router {
      add('test').arbitrary(Proc.new{|req, params| throw :pass })
      add("test")
    }
    assert_route route, 'http://lovelove:8080/test'
  end

  def test_continue
    no, yes = router {
      add('test').arbitrary_with_continue{|req, p| req.continue[false]}
      add('test').arbitrary_with_continue{|req, p| req.continue[true]}
    }
    assert_route yes, '/test'
  end
end
{'fraction_non_alphanumeric': 0.17998941238750663, 'fraction_numerical': 0.035997882477501325, 'mean_word_length': 3.848588537211292, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 11, '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': '775301', 'n_tokens_mistral': 2239, 'n_tokens_neox': 1954, 'n_words': 359}