Wiki

root/cobra/trunk/Tests/100-basics/070-is-and-is-not.cobra

Revision 2631, 0.8 KB (checked in by Charles.Esterbrook, 5 months ago)

JVM back-end progress.
credit:hopscc

  • Property svn:eol-style set to native
Line 
1#.require. clr
2namespace Test
3
4    class Test
5
6        def main
7            is shared
8
9            s as String = 'aoeu'
10            assert s is s
11
12            t1 as String = 'ao'
13            t2 as String = 'eu'
14            if s.length==4
15                # the condition forces t to be constructed at runtime
16                t as String = t1 + t2
17            else
18                t as String = ''
19            assert s==t
20            assert not Object.referenceEquals(s, t)
21            assert s is not t
22            assert t is not s
23
24            # for primitives like int, "is" is synonymous with "==" (and "is not" -> "<>")
25            x as int = 5
26            assert 5 is 5  # .warning. value types
27            assert x is 5  # .warning. value types
28            assert 5 is x  # .warning. value types
29            assert x == x  # TODO warning. same variable
30            y as int = 5
31            assert x is y  # .warning. value types
32            assert y is x  # .warning. value types
33            y = 6
34            assert x is not y  # .warning. value types
Note: See TracBrowser for help on using the browser.