# Path: test/common.py
# def generate_route_func(name):
#     def f(x):
#         return x
# 
#     f.__name__ = name
#     return f


import pytest
import tornado.testing
import rw.routing
import rw.scope
from .common import generate_route_func


def test_converter_default():
    assert (3, 'foo') == rw.routing.converter_default('foo')
    assert (3, 'foo') == rw.routing.converter_default('foo/bar')


def test_convert_int():
    assert rw.routing.converter_int('123') == (3, 123)
    assert rw.routing.converter_int('4321Hello World') == (4, 4321)
    assert rw.routing.converter_int('-1431') == (5, -1431)
    with pytest.raises(rw.routing.NoMatchError):
        rw.routing.converter_int('foo')


def test_convert_uint():
    assert rw.routing.converter_uint('123') == (3, 123)
    assert rw.routing.converter_uint('4321Hello World') == (4, 4321)

    with pytest.raises(rw.routing.NoMatchError):
        assert rw.routing.converter_uint('-1431') == (5, -1431)


def test_submodules():
    rt0 = rw.routing.RoutingTable('root')
    rt0.add_route('get', '/', 0, generate_route_func('index'))
    rt1 = rw.routing.RoutingTable('sub')
    rt1.add_route('get', '/', 1, generate_route_func('index'))
    rt2 = rw.routing.RoutingTable('subsub')
    rt2.add_route('get', '/', 2, generate_route_func('index'))

# Path: test/common.py
# def generate_route_func(name):
#     def f(x):
#         return x
# 
#     f.__name__ = name
#     return f


# Path: test/test_routing.py
import pytest
import tornado.testing
import rw.routing
import rw.scope
from .common import generate_route_func



def test_converter_default():
    assert (3, 'foo') == rw.routing.converter_default('foo')
    assert (3, 'foo') == rw.routing.converter_default('foo/bar')


def test_convert_int():
    assert rw.routing.converter_int('123') == (3, 123)
    assert rw.routing.converter_int('4321Hello World') == (4, 4321)
    assert rw.routing.converter_int('-1431') == (5, -1431)
    with pytest.raises(rw.routing.NoMatchError):
        rw.routing.converter_int('foo')


def test_convert_uint():
    assert rw.routing.converter_uint('123') == (3, 123)
    assert rw.routing.converter_uint('4321Hello World') == (4, 4321)

    with pytest.raises(rw.routing.NoMatchError):
        assert rw.routing.converter_uint('-1431') == (5, -1431)


def test_submodules():
    rt0 = rw.routing.RoutingTable('root')
    rt0.add_route('get', '/', 0, generate_route_func('index'))
    rt1 = rw.routing.RoutingTable('sub')
    rt1.add_route('get', '/', 1, generate_route_func('index'))
    rt2 = rw.routing.RoutingTable('subsub')
    rt2.add_route('get', '/', 2, generate_route_func('index'))

    rt2.add_route('get', '/fun', 2, generate_route_func('fun'))