examples: Add a test case for syntax highlighters
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Wed, 28 Jun 2017 18:20:56 +0000 (14:20 -0400)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Wed, 28 Jun 2017 18:21:12 +0000 (14:21 -0400)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

misc/README.md
tests/sav/test_syntax.res [new file with mode: 0644]
tests/test_syntax.nit [new file with mode: 0644]

index 8d09d74..be3e41e 100644 (file)
@@ -134,3 +134,7 @@ You may want to map the command to a shortcut by adding the following code to `~
 " Map the NitExecute function to Ctrl-F
 map <C-f> :NitExecute<enter>
 ~~~
+
+# Test case for syntax highlighting
+To check the accuracy of language definition files, the module
+`../tests/test_syntax.nit` can be used as a demo.
diff --git a/tests/sav/test_syntax.res b/tests/sav/test_syntax.res
new file mode 100644 (file)
index 0000000..98bfc04
--- /dev/null
@@ -0,0 +1 @@
+test_syntax.nit:48,2--39: Error: dev package for `a libray from outer space` unknown by `pkg-config`, install it with `apt-get`, `brew` or similar.
diff --git a/tests/test_syntax.nit b/tests/test_syntax.nit
new file mode 100644 (file)
index 0000000..42b88d0
--- /dev/null
@@ -0,0 +1,184 @@
+#! /usr/bin/env nitc
+
+# 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.
+
+# Test case for syntax highlighters.
+#
+# Also test spell-checking and comment recognition.
+#
+# TODO: Fix the annotations so the module actually compiles.
+#
+# SEE: [Nit](http://nitlanguage.org)
+# XXX: Dummy task
+module test_syntax is
+       new_annotation new_annotation
+
+       conditional
+
+       deprecated
+       fixed
+       lazy
+       noinit
+       readonly
+       writable
+       optional
+       autoinit
+       noautoinit
+       lateinit
+       nosuper
+       old_style_init
+       abstract
+       intern
+       extern
+       no_warning("fictive-module")
+       generated
+
+       pkgconfig("a libray from outer space")
+       cflags ""
+       ldflags "-framework Foundation"
+       light_ffi
+
+       platform "space-time"
+end
+
+import core::kernel
+intrude import core::abstract_collection
+
+in "C" `{
+       #include <stdio.h>
+`}
+
+in "ObjC Header" `{
+       #import <Foundation/Foundation.h>
+`}
+
+abstract class Blurry[ELEM_ENT: nullable Object]
+       super core::kernel::Object
+
+       type KIND: Char
+
+       init do
+               foo = 21
+       end
+
+       new do return new Concrete[Bool]
+
+       # Stromgol says "Dou, dou, dou…"
+       var stromgol: String = "Dou, dou, dou…"
+
+       fun isset_stromgol: Bool do return isset _stromgol
+
+       var foo: Int is writable, noinit
+
+       fun noop do end
+
+       protected fun shield(x, y: Int) do return 42 * x - y
+
+       private fun secret
+       do
+       end
+
+       public fun redundant(hello: Float) do
+               if hello.to_i.to_c == 'z' then
+                       do
+                               var z = "hello = {hello}"
+                               abort
+                       catch
+                               output_value hello
+                       end
+               else if true and not false or hello <= hello implies true then
+                       assert (123.digit_count(10) <=> 3) == 0
+                       var decimal = -2442.42e24
+                       var hexadecimal = 0xCAFE_BABE
+                       var octal = 0o007
+                       var binary = 0B1010
+                       var byte = (0XBEEFu8).as(not null)
+                       var long_string = """
+                       \{
+                               print "Hello {{{"#" + (octal * hexadecimal).to_s}}}"
+                       \}}}
+                       """
+                       var long_string2 = '''
+                       """print "Hello {{{"#" + (octal * hexadecimal).to_s}}}"
+                       '''
+               else
+                       while false do end
+                       for i in [0..1[ do
+                               hello += 0
+                               continue
+                       end
+                       loop
+                               break
+                       end label sticker
+                       with y = self.stromgol do
+                       end
+               end
+       end
+
+       fun is_ghost: Bool is abstract
+end
+
+class Concrete
+       super Blurry
+
+       auto_inspect
+
+       fun answer do return once 42
+
+       redef fun is_ghost do return false
+
+       var camelCase: nullable Char = null
+end
+
+extern class CString `{ char * `}
+
+       fun c_foo is extern import CString.to_s, Object.output `{
+               if (0) {
+                       Object_output(CString_to_s(self));
+               }
+       `}
+
+       fun cpp_foo import Object.output in "C++" `{
+               if (true) {
+                       char *s = dynamic_cast<char *>(self);
+               }
+       `}
+
+       fun java_foo in "Java" `{
+               if (!System.out instanceof java.io.PrintStream) {
+                       throw new ClassCastException();
+               }
+       `}
+
+       fun ojbc_foo in "ObjC" `{
+               @autoreleasepool {
+                       NSLog(@"Hello World!");
+               }
+       `}
+end
+
+interface Protocol end
+enum Integral end
+universal Galaxy end
+
+subset Limited
+       isa do return false
+end
+
+fun output_value(value: Object) do value.output
+
+var x = 42
+assert x isa Int
+__debug__ type Int: x