|
| 1 | +from selfie_lib import CompoundLens, Snapshot |
| 2 | + |
| 3 | + |
| 4 | +def test_replace_all(): |
| 5 | + replace_all = CompoundLens().replace_all("e", "E") |
| 6 | + assert ( |
| 7 | + repr(replace_all(Snapshot.of("subject").plus_facet("key", "value"))) |
| 8 | + == """Snapshot.of('subjEct') |
| 9 | + .plus_facet('key', 'valuE')""" |
| 10 | + ) |
| 11 | + |
| 12 | + |
| 13 | +def test_replace_all_regex(): |
| 14 | + replace_all_regex = CompoundLens().replace_all_regex(r"(\w+)", r"\1!") |
| 15 | + assert ( |
| 16 | + repr( |
| 17 | + replace_all_regex( |
| 18 | + Snapshot.of("this is subject").plus_facet("key", "this is facet") |
| 19 | + ) |
| 20 | + ) |
| 21 | + == """Snapshot.of('this! is! subject!') |
| 22 | + .plus_facet('key', 'this! is! facet!')""" |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +def test_set_facet_from(): |
| 27 | + set_facet_from = CompoundLens().set_facet_from("uppercase", "", lambda s: s.upper()) |
| 28 | + assert ( |
| 29 | + repr(set_facet_from(Snapshot.of("subject"))) |
| 30 | + == """Snapshot.of('subject') |
| 31 | + .plus_facet('uppercase', 'SUBJECT')""" |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +def test_mutate_facet(): |
| 36 | + mutate_facet = CompoundLens().mutate_facet("key", lambda s: s.upper()) |
| 37 | + assert ( |
| 38 | + repr(mutate_facet(Snapshot.of("subject").plus_facet("key", "facet"))) |
| 39 | + == """Snapshot.of('subject') |
| 40 | + .plus_facet('key', 'FACET')""" |
| 41 | + ) |
0 commit comments