def test_parse_question_limits_word_count(num):
    assume(num > 0)
    assume(not isnan(num))
    assume(num < 65535)

    question = {"validations": [
        {
            "name": "under_{0}_words".format(num)
        }
    ]}
    result = parse_question_limits(question)
    assert 'pattern' in result.keys()
    expected = '^(?:\\S+\\s+){0,' + str(num - 1) + '}\\S+$'
    assert result['pattern'] == expected
    matcher = re.compile(result['pattern'])

    # Now test the regex works!
    range_list = range(num)
    generated_str = ' '.join(['a' for x in range_list])
    m = re.search(matcher, generated_str)
    assert m is not None

    # now with one that's too long
    generated_str += ' a a a a'
    m = re.search(matcher, generated_str)
    assert m is None
Exemplo n.º 2
0
def test_parse_question_limits_char_count(num):
    assume(num > 0)
    assume(not isnan(num))

    question = {
        "validations": [{
            "name": "under_character_limit",
            "message": str(num)
        }]
    }
    result = parse_question_limits(question)
    assert 'maxLength' in result.keys()
    assert result['maxLength'] == num
def test_parse_question_limits_char_count(num):
    assume(num > 0)
    assume(not isnan(num))

    question = {"validations": [
        {
            "name": "under_character_limit",
            "message": str(num)
        }
    ]}
    result = parse_question_limits(question)
    assert 'maxLength' in result.keys()
    assert result['maxLength'] == num
Exemplo n.º 4
0
def test_parse_question_limits_word_count_optional(num):
    assume(num > 0)
    assume(not isnan(num))
    assume(num < 65535)

    question = {
        "validations": [{
            "name": "under_{0}_words".format(num)
        }],
        "optional": True
    }
    result = parse_question_limits(question)
    assert 'pattern' in result.keys()
    assert result['pattern'].startswith("^$")

    # test empty condition
    matcher = re.compile(result['pattern'])
    m = re.search(matcher, "")
    assert m is not None
def test_parse_question_limits_word_count_optional(num):
    assume(num > 0)
    assume(not isnan(num))
    assume(num < 65535)

    question = {
        "validations": [
            {
                "name": "under_{0}_words".format(num)
            }
        ],
        "optional": True
    }
    result = parse_question_limits(question)
    assert 'pattern' in result.keys()
    assert result['pattern'].startswith("^$")

    # test empty condition
    matcher = re.compile(result['pattern'])
    m = re.search(matcher, "")
    assert m is not None
Exemplo n.º 6
0
def test_parse_question_limits_word_count(num):
    assume(num > 0)
    assume(not isnan(num))
    assume(num < 65535)

    question = {"validations": [{"name": "under_{0}_words".format(num)}]}
    result = parse_question_limits(question)
    assert 'pattern' in result.keys()
    expected = '^(?:\\S+\\s+){0,' + str(num - 1) + '}\\S+$'
    assert result['pattern'] == expected
    matcher = re.compile(result['pattern'])

    # Now test the regex works!
    range_list = range(num)
    generated_str = ' '.join(['a' for x in range_list])
    m = re.search(matcher, generated_str)
    assert m is not None

    # now with one that's too long
    generated_str += ' a a a a'
    m = re.search(matcher, generated_str)
    assert m is None