Skip to content

Commit a115b85

Browse files
committed
Add a test for CompoundLens.
1 parent 6bd143a commit a115b85

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)