| 206 | |
| 207 | |
| 208 | def test_spans(): |
| 209 | # test the string sections our fields come from |
| 210 | string = "hello world" |
| 211 | r = parse.parse("hello {}", string) |
| 212 | assert r.spans == {0: (6, 11)} |
| 213 | start, end = r.spans[0] |
| 214 | assert string[start:end] == r.fixed[0] |
| 215 | |
| 216 | string = "hello world" |
| 217 | r = parse.parse("hello {:>}", string) |
| 218 | assert r.spans == {0: (10, 15)} |
| 219 | start, end = r.spans[0] |
| 220 | assert string[start:end] == r.fixed[0] |
| 221 | |
| 222 | string = "hello 0x12 world" |
| 223 | r = parse.parse("hello {val:x} world", string) |
| 224 | assert r.spans == {"val": (6, 10)} |
| 225 | start, end = r.spans["val"] |
| 226 | assert string[start:end] == "0x%x" % r.named["val"] |
| 227 | |
| 228 | string = "hello world and other beings" |
| 229 | r = parse.parse("hello {} {name} {} {spam}", string) |
| 230 | assert r.spans == {0: (6, 11), "name": (12, 15), 1: (16, 21), "spam": (22, 28)} |
| 231 | |
| 232 | |
| 233 | def test_numbers(): |