Merge remote-tracking branch 'upstream/master' into init_auto
[nit.git] / tests / contracts_static.nit
similarity index 60%
rename from tests/test_ropes_buffer_add_overflow.nit
rename to tests/contracts_static.nit
index b2592a1..8b90ac8 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Checks that `RopeBuffer.add` does not makes the internal buffer overflow.
-#
-# Note: In order to help repoducibility, this test read an private attribute of
-# the buffer.
-module test_ropes_buffer_add_overflow
+# Test the resolution of contract when the static mpropdef does not have contract and the dynamic has one
+
+class MyClass
+       fun foo(x: Int)
+       do
+               x = 0
+       end
+end
 
-import core
-intrude import core::text::ropes
+class MySubClass
+       super MyClass
 
-var buffer = new RopeBuffer
+       redef fun foo(x)
+       is
+               ensure(x > 10)
+       do
+               if x < 10 then print "Error"
+       end
+end
 
-buffer.append("x" * maxlen)
-buffer.add 'y'
-assert buffer.rpos <= maxlen else print "{buffer.rpos} > {maxlen}"
+var first = new MyClass
+first.foo(1) # No contract on the mpropdef
+var second: MyClass = new MySubClass
+second.foo(2) #Fail