def test_regexp(): var = Variable(name='simple', value=Regexp('^/.*')) assert_false(var.depends) assert_true(var.regexp) assert_true(var.can_startswith('/')) assert_false(var.can_startswith('a')) assert_true(var.can_contain('a')) assert_false(var.can_contain('\n')) assert_true(var.must_contain('/')) assert_false(var.must_contain('a')) assert_true(var.must_startswith('/')) assert_false(var.must_startswith('a'))
def test_regexp_boundary(): var = Variable(name='simple', value=Regexp('.*'), boundary=Regexp('/[a-z]', strict=True)) assert_false(var.depends) assert_true(var.regexp) assert_true(var.can_startswith('/')) assert_false(var.can_startswith('a')) assert_false(var.can_contain('/')) assert_true(var.can_contain('a')) assert_false(var.can_contain('0')) assert_false(var.can_contain('\n')) assert_true(var.must_contain('/')) assert_false(var.must_contain('a')) assert_true(var.must_startswith('/')) assert_false(var.must_startswith('a'))
def test_script(): get_context().add_var('foo', Variable(name='foo', value=Regexp('.*'))) var = Variable(name='simple', value='/$foo') assert_true(var.depends) assert_false(var.regexp) assert_false(var.can_startswith('/')) assert_false(var.can_startswith('a')) assert_true(var.can_contain('/')) assert_true(var.can_contain('a')) assert_false(var.can_contain('\n')) assert_true(var.must_contain('/')) assert_false(var.must_contain('a')) assert_true(var.must_startswith('/')) assert_false(var.must_startswith('a'))
def test_script_boundary(): get_context().add_var('foo', Variable(name='foo', value=Regexp('.*'), boundary=Regexp('[a-z]', strict=True))) var = Variable(name='simple', value='/$foo', boundary=Regexp('[/a-z0-9]', strict=True)) assert_true(var.depends) assert_false(var.regexp) assert_false(var.can_startswith('/')) assert_false(var.can_startswith('a')) assert_false(var.can_contain('/')) assert_true(var.can_contain('a')) assert_false(var.can_contain('\n')) assert_false(var.can_contain('0')) assert_true(var.must_contain('/')) assert_false(var.must_contain('a')) assert_true(var.must_startswith('/')) assert_false(var.must_startswith('a'))
def test_literal(): var = Variable(name='simple', value='$uri', have_script=False) assert_false(var.depends) assert_false(var.regexp) assert_equals(var.value, '$uri') assert_false(var.can_startswith('$')) assert_false(var.can_contain('i')) assert_true(var.must_contain('$')) assert_true(var.must_contain('u')) assert_false(var.must_contain('a')) assert_true(var.must_startswith('$')) assert_false(var.must_startswith('u'))