-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add base_is_optional to check the evaluation order of attribut…
…e values Signed-off-by: Jean Privat <[email protected]>
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import core::kernel | ||
|
||
fun foo(i: Int): Int | ||
do | ||
'f'.output | ||
i.output | ||
return i | ||
end | ||
|
||
class A | ||
# needed on the new | ||
var i: Int | ||
|
||
# initialized by the allocation | ||
var j: Int = foo(2) | ||
|
||
# optional in the new, default value evaluated if `null` is given | ||
var k: Int = foo(3) is optional | ||
|
||
# the `init` will initialize it | ||
var l: Int is noautoinit | ||
init do l = foo(4) | ||
|
||
# initialized if needed on the first `read` | ||
var m: Int = foo(5) is lazy | ||
|
||
fun set | ||
do | ||
i = 10 | ||
j = 20 | ||
k = 30 | ||
l = 40 | ||
m = 50 | ||
end | ||
|
||
fun test | ||
do | ||
#alt1#set | ||
i.output | ||
j.output | ||
k.output | ||
l.output | ||
m.output | ||
'\n'.output | ||
end | ||
end | ||
|
||
var a | ||
a = new A(foo(100)) | ||
a.test | ||
a = new A(foo(100), null) | ||
a.test | ||
a = new A(foo(100), foo(300)) | ||
a.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
f2 | ||
f100 | ||
f3 | ||
f4 | ||
100 | ||
2 | ||
3 | ||
4 | ||
f5 | ||
5 | ||
|
||
f2 | ||
f100 | ||
f3 | ||
f4 | ||
100 | ||
2 | ||
3 | ||
4 | ||
f5 | ||
5 | ||
|
||
f2 | ||
f100 | ||
f300 | ||
f4 | ||
100 | ||
2 | ||
300 | ||
4 | ||
f5 | ||
5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
f2 | ||
f100 | ||
f3 | ||
f4 | ||
10 | ||
20 | ||
30 | ||
40 | ||
50 | ||
|
||
f2 | ||
f100 | ||
f3 | ||
f4 | ||
10 | ||
20 | ||
30 | ||
40 | ||
50 | ||
|
||
f2 | ||
f100 | ||
f300 | ||
f4 | ||
10 | ||
20 | ||
30 | ||
40 | ||
50 | ||
|