summaryrefslogtreecommitdiff
path: root/src/compat/option_test.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-10-13 13:16:34 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-10-13 14:03:46 -0700
commit780a0d771edbe21dcfa3405163ffbdf7f7fa4604 (patch)
treeac202254d015d2a2a28ab5bca60c3f5474d168ba /src/compat/option_test.cpp
parenta5e0fe8204a8b3299507a645f3479e9ead6c6110 (diff)
downloadtmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.tar.gz
tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.tar.bz2
tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.tar.xz
tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.zip
Convert container lookups to use Option<Borrowed<T>>
Diffstat (limited to 'src/compat/option_test.cpp')
-rw-r--r--src/compat/option_test.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/compat/option_test.cpp b/src/compat/option_test.cpp
index d99eda9..b963a29 100644
--- a/src/compat/option_test.cpp
+++ b/src/compat/option_test.cpp
@@ -255,6 +255,43 @@ TEST(Option, map)
}
}
+TEST(Option, member)
+{
+ struct Foo
+ {
+ int bar = 404;
+ };
+
+ Option<Foo> vng = None;
+ EXPECT_EQ(vng.pmd_get(&Foo::bar).copy_or(42), 42);
+ Option<Foo> vsg = Some(Foo());
+ EXPECT_EQ(vsg.pmd_get(&Foo::bar).copy_or(42), 404);
+
+ Option<Foo> vns = None;
+ vns.pmd_set(&Foo::bar, 42);
+ EXPECT_EQ(vns.copy_or(Foo()).bar, 404);
+ Option<Foo> vss = Some(Foo());
+ vss.pmd_set(&Foo::bar, 42);
+ EXPECT_EQ(vss.copy_or(Foo()).bar, 42);
+
+ Foo foo, alt;
+
+ Option<P<Foo>> png = None;
+ EXPECT_EQ(png.pmd_pget(&Foo::bar).copy_or(42), 42);
+ Option<P<Foo>> psg = Some(borrow(foo));
+ EXPECT_EQ(psg.pmd_pget(&Foo::bar).copy_or(42), 404);
+
+ Option<P<Foo>> pns = None;
+ pns.pmd_pset(&Foo::bar, 42);
+ EXPECT_EQ(pns.copy_or(borrow(alt))->bar, 404);
+ EXPECT_EQ(foo.bar, 404);
+ Option<P<Foo>> pss = Some(borrow(foo));
+ pss.pmd_pset(&Foo::bar, 42);
+ EXPECT_EQ(pss.copy_or(borrow(alt))->bar, 42);
+ EXPECT_EQ(foo.bar, 42);
+ EXPECT_EQ(alt.bar, 404);
+}
+
#if __cplusplus >= 201300 // c++14 as given by gcc 4.9
# define DECLTYPE_AUTO decltype(auto)
#else