Datasets:
File size: 4,835 Bytes
c6efd2c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
import regex as re
from validator import compiled_regex as crex
def test_ws():
spaces = [" ",
" ",
"\n", # ! is this wanted?
" "]
for space in spaces:
match = crex.ws.fullmatch(space)
if match:
assert True
else:
assert False
def test_twows():
spaces_true = [" ",
"\n\n", # ! is this wanted?
" "]
spaces_false = [" ",
"\n", # ! is this wanted?
" "]
for space in spaces_true:
match = crex.ws2.fullmatch(space)
if match:
assert True
else:
assert False
for space in spaces_false:
match = crex.ws2.fullmatch(space)
if match:
assert False
else:
assert True
def test_integer():
match = crex.wordid.fullmatch('10')
if match:
assert True
else:
assert False
match = crex.wordid.fullmatch('01')
if match:
assert False
else:
assert True
def test_naturalnumber():
match = crex.head.fullmatch('0')
if match:
assert True
else:
assert False
match = crex.head.fullmatch('10')
if match:
assert True
else:
assert False
match = crex.head.fullmatch('01')
if match:
assert False
else:
assert True
def test_range():
ranges_true = ["1-2", "9-10", "15-16"]
ranges_false = ["0-1", "1-0", "10-", "-10"]
for range in ranges_true:
match = crex.mwtid.fullmatch(range)
if match:
assert True
else:
assert False
for range in ranges_false:
match = crex.mwtid.fullmatch(range)
if match:
assert False
else:
assert True
def test_decimal():
decimal_true = ["0.1", "1.1", "3.10"]
decimal_false = ["1.0", "1.", ".1", "1.01"]
for decimal in decimal_true:
match = crex.enodeid.fullmatch(decimal)
if match:
assert True
else:
assert False
for decimal in decimal_false:
match = crex.enodeid.fullmatch(decimal)
if match:
assert False
else:
assert True
def test_decimalwithzero():
decimal_true = ["0", "0.1", "1.1", "3.10"]
decimal_false = ["1.0", "1.", ".1", "1.01"]
for decimal in decimal_true:
match = crex.ehead.fullmatch(decimal)
if match:
assert True
else:
assert False
for decimal in decimal_false:
match = crex.ehead.fullmatch(decimal)
if match:
assert False
else:
assert True
def general_test_metadata(regex_name, meta_str, expected):
obj = getattr(crex, regex_name)
match = obj.fullmatch(meta_str)
if (match and expected) or (match is None and not expected):
assert True
else:
assert False
def test_newdoc():
general_test_metadata("newdoc", "# newdoc", True)
general_test_metadata("newdoc", "# newdoc newdoc_name", True) # ! is this wanted?
general_test_metadata("newdoc", "# newdoc = newdoc_name", False) # ! is this wanted?
general_test_metadata("newdoc", "# newdoc newdoc_name ", False)
def test_newpar():
general_test_metadata("newpar", "# newpar", True)
general_test_metadata("newpar", "# newpar newpar_name", True) # ! is this wanted?
general_test_metadata("newpar", "# newpar = newpar_name", False) # ! is this wanted?
general_test_metadata("newpar", "# newpar newpar_name ", False)
def test_sentid():
general_test_metadata("sentid", "# sent_id", False)
general_test_metadata("sentid", "# sent_id id_sentence", False)
general_test_metadata("sentid", "# sent_id = new sent id", False)
general_test_metadata("sentid", "# sent_id = new_sent_id", True)
general_test_metadata("sentid", "# sent_id = 9", True)
def test_text():
general_test_metadata("text", "# text", False)
general_test_metadata("text", "# text Mary had a little lamb", False)
general_test_metadata("text", "# text = Mary had a little lamb", True)
general_test_metadata("text", "# text = Mary had a little lamb ", False) # ! isn't this too strict? Maybe we could to allow trailing whitespaces
def test_uppercasestring():
strings_true = ["ABC",
"A"]
strings_false = ["abc",
"Abc",
""]
for string in strings_true:
match = crex.upos.fullmatch(string)
if match:
assert True
else:
assert False
for string in strings_false:
match = crex.upos.fullmatch(string)
if match:
assert False
else:
assert True
def test_featval():
strings_true = ["Feat=Val",
"Feat=1,2",
"Feat=Val1",
"Feat[x]=Value"]
strings_false = ["Feat=val",
"feat=Val",
"Feat",
""]
for string in strings_true:
match = crex.featval.fullmatch(string)
if match:
assert True
else:
assert False
for string in strings_false:
match = crex.featval.fullmatch(string)
if match:
assert False
else:
assert True
def test_deprel():
strings_true = ["nmod",
"nmod:poss",
"nmod:p"]
strings_false = [":poss",
"nmod:1",
""]
for string in strings_true:
match = crex.deprel.fullmatch(string)
if match:
assert True
else:
assert False
for string in strings_false:
match = crex.deprel.fullmatch(string)
if match:
assert False
else:
assert True |