aboutsummaryrefslogtreecommitdiff
path: root/tests/test_multibindings_bind_interface.py
diff options
context:
space:
mode:
authorMarco Poletti <poletti.marco@gmail.com>2017-07-30 12:09:06 +0100
committerMarco Poletti <poletti.marco@gmail.com>2017-07-30 13:25:03 +0100
commitc84c7dea4871e0c8a24d68f3a12277cf80587e2a (patch)
treefb74adc3111e6d8caafc5d626bc83272cd475122 /tests/test_multibindings_bind_interface.py
parentb95efcce188e5d56e7e58670cca6b22e09f714da (diff)
downloadgoogle-fruit-c84c7dea4871e0c8a24d68f3a12277cf80587e2a.tar.gz
Allow Component, NormalizedComponent, Injector and Provider to specify that they only require/provide a const T (instead of requiring/providing a T). This is in preparation for allowing const bindings.
Diffstat (limited to 'tests/test_multibindings_bind_interface.py')
-rwxr-xr-xtests/test_multibindings_bind_interface.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_multibindings_bind_interface.py b/tests/test_multibindings_bind_interface.py
index b53a763..af3c2f8 100755
--- a/tests/test_multibindings_bind_interface.py
+++ b/tests/test_multibindings_bind_interface.py
@@ -64,6 +64,68 @@ def test_add_interface_multibinding_success(XAnnot, XImplAnnot):
source,
locals())
+@pytest.mark.parametrize('XAnnot,XImplAnnot,ConstXImplAnnot', [
+ ('X', 'XImpl', 'const XImpl'),
+ ('X', 'fruit::Annotated<Annotation2, XImpl>', 'fruit::Annotated<Annotation2, const XImpl>'),
+])
+def test_add_interface_multibinding_const_target_error_install_first(XAnnot, XImplAnnot, ConstXImplAnnot):
+ source = '''
+ struct X {
+ virtual int foo() = 0;
+ };
+
+ struct XImpl : public X {
+ int foo() override {
+ return 5;
+ }
+ };
+
+ fruit::Component<ConstXImplAnnot> getXImplComponent();
+
+ fruit::Component<> getComponent() {
+ return fruit::createComponent()
+ .install(getXImplComponent)
+ .addMultibinding<XAnnot, XImplAnnot>();
+ }
+ '''
+ expect_compile_error(
+ 'NonConstBindingRequiredButConstBindingProvidedError<XImplAnnot>',
+ 'The type T was provided as constant, however one of the constructors/providers/factories in this component',
+ COMMON_DEFINITIONS,
+ source,
+ locals())
+
+@pytest.mark.parametrize('XAnnot,XImplAnnot,ConstXImplAnnot', [
+ ('X', 'XImpl', 'const XImpl'),
+ ('X', 'fruit::Annotated<Annotation2, XImpl>', 'fruit::Annotated<Annotation2, const XImpl>'),
+])
+def test_add_interface_multibinding_const_target_error_binding_first(XAnnot, XImplAnnot, ConstXImplAnnot):
+ source = '''
+ struct X {
+ virtual int foo() = 0;
+ };
+
+ struct XImpl : public X {
+ int foo() override {
+ return 5;
+ }
+ };
+
+ fruit::Component<ConstXImplAnnot> getXImplComponent();
+
+ fruit::Component<> getComponent() {
+ return fruit::createComponent()
+ .addMultibinding<XAnnot, XImplAnnot>()
+ .install(getXImplComponent);
+ }
+ '''
+ expect_compile_error(
+ 'NonConstBindingRequiredButConstBindingProvidedError<XImplAnnot>',
+ 'The type T was provided as constant, however one of the constructors/providers/factories in this component',
+ COMMON_DEFINITIONS,
+ source,
+ locals())
+
@pytest.mark.parametrize('XAnnot,intAnnot', [
('X', 'int'),
('fruit::Annotated<Annotation1, X>', 'fruit::Annotated<Annotation2, int>'),