# 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 generate_rule(route):
    return rw.routing.Route(route)


def test_parse_rule():
    assert rw.routing.parse_rule('/asdf/') == [(None, None, '/asdf/')]
    rule = rw.routing.parse_rule('/foo/<name>/bar')
    assert rule[0] == (None, None, '/foo/')
    assert rule[1] == ('str', None, 'name')
    assert rule[2] == (None, None, '/bar')


def test_parse_rule_errors():
    with pytest.raises(ValueError):
        # the argument name "name" is used twice
        list(rw.routing.parse_rule('/<name>/<name>/asd'))

    with pytest.raises(ValueError):
        # missing > after name
        list(rw.routing.parse_rule('/<name/asd'))


def test_rule_compare():
    for rule_0, rule_1 in (
        (generate_rule('/name'), generate_rule('/<something>')),
        (generate_rule('/name'), generate_rule('/na<something>')),
        (generate_rule('/name<something>'), generate_rule('/na<something>')),

# 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 generate_rule(route):
    return rw.routing.Route(route)


def test_parse_rule():
    assert rw.routing.parse_rule('/asdf/') == [(None, None, '/asdf/')]
    rule = rw.routing.parse_rule('/foo/<name>/bar')
    assert rule[0] == (None, None, '/foo/')
    assert rule[1] == ('str', None, 'name')
    assert rule[2] == (None, None, '/bar')


def test_parse_rule_errors():
    with pytest.raises(ValueError):
        # the argument name "name" is used twice
        list(rw.routing.parse_rule('/<name>/<name>/asd'))

    with pytest.raises(ValueError):
        # missing > after name
        list(rw.routing.parse_rule('/<name/asd'))


def test_rule_compare():
    for rule_0, rule_1 in (
        (generate_rule('/name'), generate_rule('/<something>')),
        (generate_rule('/name'), generate_rule('/na<something>')),
        (generate_rule('/name<something>'), generate_rule('/na<something>')),

        (generate_rule('/<something:int>'), generate_rule('/<something>')),