From 90f966cb8649840bc05f5d77219867593eb7fe94 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Thu, 20 Jun 2024 19:29:35 -0700 Subject: [PATCH] add unit test 01-Basic/253-scope-cleanup --- src/test/01-Basic/253-scope-cleanup.ck | 41 +++++++++++++++++++++++++ src/test/01-Basic/253-scope-cleanup.txt | 9 ++++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/01-Basic/253-scope-cleanup.ck create mode 100644 src/test/01-Basic/253-scope-cleanup.txt diff --git a/src/test/01-Basic/253-scope-cleanup.ck b/src/test/01-Basic/253-scope-cleanup.ck new file mode 100644 index 000000000..3ce41a1e3 --- /dev/null +++ b/src/test/01-Basic/253-scope-cleanup.ck @@ -0,0 +1,41 @@ +// (non-control structure) local scope Object cleanup +// 1.5.2.5 (ge) added + +// a class +class Foo +{ + int val; + + fun @construct( int x ) + { x => val; } + + fun @destruct() + { <<< "destructor:", val >>>; } +} + +// control structure scope +if( true ) +{ + // nested scope + { + Foo foo(-1); + <<< 1, "" >>>; + + // nested nested scope + { + Foo bar(-2); + <<< 2, "" >>>; + } + <<< 3, "" >>>; + + } + <<< 4, "" >>>; + +} +<<< 5, "" >>>; + +// top-level scope +{ + Foo foo(0); +} +<<< 6, "" >>>; diff --git a/src/test/01-Basic/253-scope-cleanup.txt b/src/test/01-Basic/253-scope-cleanup.txt new file mode 100644 index 000000000..784c13e65 --- /dev/null +++ b/src/test/01-Basic/253-scope-cleanup.txt @@ -0,0 +1,9 @@ +1 +2 +destructor: -2 +3 +destructor: -1 +4 +5 +destructor: 0 +6