From 24b3da5d0f334b468cdd9f14340db884ec1b7590 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sun, 26 Jul 2015 21:10:50 -0400 Subject: [PATCH] Updated test.cul. --- language/samples/test.cul | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/language/samples/test.cul b/language/samples/test.cul index 22872c2..84dc814 100644 --- a/language/samples/test.cul +++ b/language/samples/test.cul @@ -111,6 +111,30 @@ test_object_factory = fn () { assert(calc.sub(1) == 10) } +test_class = fn () { + // TODO: support 'prototype' property + Car = { + new: fn(miles_per_run) { + mut total_miles = 0 + + { + run: fn (times) { + total_miles = total_miles + miles_per_run * times + }, + total: fn () { + total_miles + } + } + } + } + + car = Car.new(5) + car.run(1) + car.run(2) + + assert(car.total() == 15) +} + test_sum = fn () { mut i = 1 mut ret = 0 @@ -150,6 +174,7 @@ test_array() test_function() test_object() test_object_factory() +test_class() test_sum() test_fib() test_interpolated_string()