Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_syntax.nit
1 #! /usr/bin/env nitc
2
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Test case for syntax highlighters.
18 #
19 # Also test spell-checking and comment recognition.
20 #
21 # TODO: Fix the annotations so the module actually compiles.
22 #
23 # SEE: [Nit](http://nitlanguage.org)
24 # XXX: Dummy task
25 module test_syntax is
26 new_annotation new_annotation
27
28 conditional
29
30 deprecated
31 fixed
32 lazy
33 noinit
34 readonly
35 writable
36 optional
37 autoinit
38 noautoinit
39 lateinit
40 nosuper
41 old_style_init
42 abstract
43 intern
44 extern
45 no_warning("fictive-module")
46 generated
47
48 pkgconfig("a libray from outer space")
49 cflags ""
50 ldflags "-framework Foundation"
51 light_ffi
52
53 platform "space-time"
54 end
55
56 import core::kernel
57 intrude import core::abstract_collection
58
59 in "C" `{
60 #include <stdio.h>
61 `}
62
63 in "ObjC Header" `{
64 #import <Foundation/Foundation.h>
65 `}
66
67 abstract class Blurry[ELEM_ENT: nullable Object]
68 super core::kernel::Object
69
70 type KIND: Char
71
72 init do
73 foo = 21
74 end
75
76 new do return new Concrete[Bool]
77
78 # Stromgol says "Dou, dou, dou…"
79 var stromgol: String = "Dou, dou, dou…"
80
81 fun isset_stromgol: Bool do return isset _stromgol
82
83 var foo: Int is writable, noinit
84
85 fun noop do end
86
87 protected fun shield(x, y: Int) do return 42 * x - y
88
89 private fun secret
90 do
91 end
92
93 public fun redundant(hello: Float) do
94 if hello.to_i.to_c == 'z' then
95 do
96 var z = "hello = {hello}"
97 abort
98 catch
99 output_value hello
100 end
101 else if true and not false or hello <= hello implies true then
102 assert (123.digit_count(10) <=> 3) == 0
103 var decimal = -2442.42e24
104 var hexadecimal = 0xCAFE_BABE
105 var octal = 0o007
106 var binary = 0B1010
107 var byte = (0XBEEFu8).as(not null)
108 var long_string = """
109 \{
110 print "Hello {{{"#" + (octal * hexadecimal).to_s}}}"
111 \}}}
112 """
113 var long_string2 = '''
114 """print "Hello {{{"#" + (octal * hexadecimal).to_s}}}"
115 '''
116 else
117 while false do end
118 for i in [0..1[ do
119 hello += 0
120 continue
121 end
122 loop
123 break
124 end label sticker
125 with y = self.stromgol do
126 end
127 end
128 end
129
130 fun is_ghost: Bool is abstract
131 end
132
133 class Concrete
134 super Blurry
135
136 auto_inspect
137
138 fun answer do return once 42
139
140 redef fun is_ghost do return false
141
142 var camelCase: nullable Char = null
143 end
144
145 extern class CString `{ char * `}
146
147 fun c_foo is extern import CString.to_s, Object.output `{
148 if (0) {
149 Object_output(CString_to_s(self));
150 }
151 `}
152
153 fun cpp_foo import Object.output in "C++" `{
154 if (true) {
155 char *s = dynamic_cast<char *>(self);
156 }
157 `}
158
159 fun java_foo in "Java" `{
160 if (!System.out instanceof java.io.PrintStream) {
161 throw new ClassCastException();
162 }
163 `}
164
165 fun ojbc_foo in "ObjC" `{
166 @autoreleasepool {
167 NSLog(@"Hello World!");
168 }
169 `}
170 end
171
172 interface Protocol end
173 enum Integral end
174 universal Galaxy end
175
176 subset Limited
177 isa do return false
178 end
179
180 fun output_value(value: Object) do value.output
181
182 var x = 42
183 assert x isa Int
184 __debug__ type Int: x