Skip to content
Browse files

Add explicit tests for accessing data members of const objects

  • Loading branch information...
1 parent 101225a commit d44de49fb1e34e146442a527193b656ee059aafb @lefticus lefticus committed
Showing with 14 additions and 0 deletions.
  1. +3 −0 src/test_module.cpp
  2. +11 −0 unittests/member_variable_access.chai
3 src/test_module.cpp
@@ -11,6 +11,8 @@ class TestBaseType
virtual ~TestBaseType() {}
virtual int func() { return 0; }
+ const TestBaseType &constMe() const { return *this; }
int val;
const int const_val;
@@ -84,6 +86,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
m->add(chaiscript::user_type<TestEnum>(), "TestEnum");
m->add(chaiscript::fun(&to_int), "to_int");
+ m->add(chaiscript::fun(&TestBaseType::constMe), "constMe");
return m;
11 unittests/member_variable_access.chai
@@ -0,0 +1,11 @@

Where did this "test_module" get added with this name? I tried searching the code on where this gets defined but couldn't find it. Do I have to 'load module' for the StackOverflow question? [1]


@lefticus ChaiScript member

No, you don't have to use it for your code to work, it's just a loadable module that I use for some of the unit tests.

Looking at your problem on stackoverflow, it appears as if you are doing:


instead of:


Looking closer at it, I believe the problem is that you are using "::" in your typenames. "::" is used when defining methods on a class and has never been tested as part of a name.

Thanks for the response. I am not invoking the variable as Ogre::Vector2.x but as v.x, where v is an instance of Ogre::Vector3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+var t0 = TestBaseType()
+t0.val = 13
+assert_equal(15, t0.const_val)
+assert_equal(13, t0.val)
+assert_equal(15, t0.constMe().const_val)
+assert_equal(13, t0.constMe().val)

0 comments on commit d44de49

Please sign in to comment.
Something went wrong with that request. Please try again.