summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2009-06-08 08:13:09 +0200
committerAndreas Rumpf <rumpf_a@web.de>2009-06-08 08:13:09 +0200
commit36818817bd61594ea6d106328bb8df0f5a25cfc4 (patch)
tree58180069c9a32400e7e11ba5bc5c85be2f11f0cc /tests
parent4d4b3b1c04d41868ebb58bd9ccba7b303007e900 (diff)
downloadNim-36818817bd61594ea6d106328bb8df0f5a25cfc4.tar.gz
version0.7.10
Diffstat (limited to 'tests')
-rw-r--r--tests/jsontest.json22
-rw-r--r--tests/tarray2.nim18
-rw-r--r--tests/tcurrncy.nim32
-rw-r--r--tests/tident.nim22
-rw-r--r--tests/titer3.nim7
-rw-r--r--tests/xmltest.html108
6 files changed, 209 insertions, 0 deletions
diff --git a/tests/jsontest.json b/tests/jsontest.json
new file mode 100644
index 000000000..27b5ba1d1
--- /dev/null
+++ b/tests/jsontest.json
@@ -0,0 +1,22 @@
+// Simple JSON test file
+// (c) 2009 Andreas Rumpf
+
+/* a long comment */
+
+{
+  "key1": null,
+  "key2": [
+    {},
+    {   },
+    [],
+    
+    [ /* empty array */ ],
+    
+    -1e10 // another comment
+    
+  
+  ]        ,
+  "key3": false
+}
+
+
diff --git a/tests/tarray2.nim b/tests/tarray2.nim
new file mode 100644
index 000000000..eb0b75692
--- /dev/null
+++ b/tests/tarray2.nim
@@ -0,0 +1,18 @@
+# simple check for one dimensional arrays

+

+type

+  TMyArray = array[0..2, int]

+

+proc mul(a, b: TMyarray): TMyArray =

+  result = a
+  for i in 0..len(a)-1:
+    result[i] = a[i] * b[i]
+
+var
+  x, y, z: TMyArray
+ 
+x = [ 4, 5, 6 ]
+y = x
+echo repr(mul(x, y))
+
+#OUT [16, 25, 36]

diff --git a/tests/tcurrncy.nim b/tests/tcurrncy.nim
new file mode 100644
index 000000000..1d353abd6
--- /dev/null
+++ b/tests/tcurrncy.nim
@@ -0,0 +1,32 @@
+template Additive(typ: typeDesc): stmt =
+  proc `+` *(x, y: typ): typ {.borrow.}
+  proc `-` *(x, y: typ): typ {.borrow.}
+  
+  # unary operators:
+  proc `+` *(x: typ): typ {.borrow.}
+  proc `-` *(x: typ): typ {.borrow.}
+
+template Multiplicative(typ, base: typeDesc): stmt =
+  proc `*` *(x: typ, y: base): typ {.borrow.}
+  proc `*` *(x: base, y: typ): typ {.borrow.}
+  proc `div` *(x: typ, y: base): typ {.borrow.}
+  proc `mod` *(x: typ, y: base): typ {.borrow.}
+
+template Comparable(typ: typeDesc): stmt =
+  proc `<` * (x, y: typ): bool {.borrow.}
+  proc `<=` * (x, y: typ): bool {.borrow.}
+  proc `==` * (x, y: typ): bool {.borrow.}
+
+template DefineCurrency(typ, base: expr): stmt =
+  type
+    typ* = abstract base
+  Additive(typ)
+  Multiplicative(typ, base)
+  Comparable(typ)
+  
+  proc `$` * (t: typ): string {.borrow.}
+
+DefineCurrency(TDollar, int)
+DefineCurrency(TEuro, int)
+echo($( 12.TDollar + 13.TDollar )) #OUT 25
+
diff --git a/tests/tident.nim b/tests/tident.nim
new file mode 100644
index 000000000..1ed9894c6
--- /dev/null
+++ b/tests/tident.nim
@@ -0,0 +1,22 @@
+
+type
+  TIdObj* = object of TObject

+    id*: int                  # unique id; use this for comparisons and not the pointers

+  

+  PIdObj* = ref TIdObj

+  PIdent* = ref TIdent

+  TIdent*{.acyclic.} = object

+    s*: string

+
+proc myNewString(L: int): string {.inline.} =
+  result = newString(L)
+  if result.len == L: echo("Length correct")
+  else: echo("bug")
+  for i in 0..L-1:
+    if result[i] == '\0':
+      echo("Correct")
+    else: 
+      echo("Wrong")
+  
+var s = myNewString(8)
+
diff --git a/tests/titer3.nim b/tests/titer3.nim
new file mode 100644
index 000000000..b42113241
--- /dev/null
+++ b/tests/titer3.nim
@@ -0,0 +1,7 @@
+# yield inside an iterator, but not in a loop:
+iterator iter1(a: openArray[int]): int =
+  yield a[0] #ERROR_MSG 'yield' only allowed in a loop of an iterator
+
+var x = [[1, 2, 3], [4, 5, 6]]
+for y in iter1(x[0]): write(stdout, $y)
+
diff --git a/tests/xmltest.html b/tests/xmltest.html
new file mode 100644
index 000000000..862a91d24
--- /dev/null
+++ b/tests/xmltest.html
@@ -0,0 +1,108 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+
+<head>
+  <title>Nimrod Programming Language</title>
+  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
+  <link rel="stylesheet" type="text/css" href="style/style.css" />
+</head>
+
+<>
+  <div id="main">
+    <div id="links">
+      <!-- **** INSERT LINKS HERE **** -->
+    </div>
+    <div id="logo"><h1>Nimrod Programming Language</h1></div>
+    <div id="content">
+      <div id="menu">
+        <ul>
+  <li><a
+  href="index.html" title = "Nimrod - home"   home</a></li>
+  <!-- error: > missing -->
+  
+  <li><a
+  href="news.html" title = "Nimrod - news">news</></>
+  <li><a
+  href="documentation.html" title = "Nimrod - docs">docs</a></li>
+  <li><a id="selected" 
+  href="download.html" title = "Nimrod - download">download</a></li>
+  <li><a
+  href="community.html" title = "Nimrod - community">community</a></li>
+  <li><a
+  href="question.html" title = "Nimrod - FAQ">FAQ</a></li>
+        </ul>
+      </div>
+      <div id="column1">
+        <div class="sidebaritem">
+          <div class="sbihead">
+            <h1>latest news</h1>
+          </div>
+          <div class="sbicontent">
+            <p><span class="newsdate">2009-01-22</span><br />Forum added!<br /><span class="newsdate">2009-01-07</span><br />Nimrod version 0.7.4 has been released! Get it <a class="reference external" href="./download.html">here</a>.<br /><span class="newsdate">2008-12-12</span><br />Nimrod version 0.7.2 has been released!<br /><span class="newsdate">2008-11-16</span><br />Nimrod version 0.7.0 has been released!<br /><span class="newsdate">2008-08-22</span><br />Nimrod version 0.6.0 has been released!<br /><span class="newsdate">2008-06-22</span><br />This page is finally online!<br /></p>
+
+
+          </div>
+        </div>
+        <div class="sidebaritem">
+          <div class="sbihead">
+            <h1>additional links</h1>
+          </div>
+          <div class="sbilinks">
+            <!-- **** INSERT ADDITIONAL LINKS HERE **** -->
+            <ul>
+             <li><a class="reference" href="http://gcc.gnu.org">GCC</a></li>
+             <li><a class="reference" href="http://llvm.org">LLVM</a></li>
+            </ul>
+          </div>
+        </div>
+      </div>
+      <div id="column2">
+      <blockquote><p>There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. -- Jeremy S. Anderson.</p></blockquote>
+<p>Here you can download the latest version of the Nimrod Compiler. Please choose your platform:</p>
+<ul class="simple"><li>source-based installation: <a class="reference external" href="download/nimrod_0.7.4.zip">download/nimrod_0.7.4.zip</a></li>
+<li>installer for Windows (i386): <a class="reference external" href="download/nimrod_0.7.4.exe">download/nimrod_0.7.4.exe</a> (includes LLVM and everything else you need)</li>
+</ul>
+<p>The source-based installation should work on most UNIX-like systems. Currently, it has been tested on these systems:</p>
+<ul class="simple"><li>Linux: i386, AMD64</li>
+<li>Mac OS X: i386</li>
+<li>FreeBSD: i386</li>
+</ul>
+<h1 id="installation">Installation</h1><h2 id="installation-on-linux-unix">Installation on Linux/UNIX</h2><dl class="docutils"><dt>Note:</dt>
+<dd>A C compiler is required - knowledge of C is not!</dd>
+</dl>
+<p>The GNU C Compiler is fully supported, other compilers may work. The C compiler should be in your <tt class="docutils literal"><span class="pre">$PATH</span></tt> (most likely the case). Note that some few Linux distributions do not ship with a GCC compiler preinstalled - then you have to install it.</p>
+<p>Install Nimrod by downloading the appropriate <tt class="docutils literal"><span class="pre">.zip</span></tt> file and extracting it to a directory of your choice. The Nimrod Compiler will stay in this directory (unless you copy it somewhere else). The compiler does not need write access to its directory anymore, so copying the nimrod folder to <tt class="docutils literal"><span class="pre">/opt</span></tt> does work.</p>
+<p>Then run the following command:<pre>
+sh build.sh</pre>
+</p>
+<p>Unlike other software, Nimrod does not distribute its files over the whole file hierarchy. This has the advantage that you can deinstall it by just deleting its folder. The disadvantage is that you have to add it to your <tt class="docutils literal"><span class="pre">PATH</span></tt> manually. An alternative is to create a symbolic link in <tt class="docutils literal"><span class="pre">/usr/bin</span></tt>:<pre>
+[sudo] ln -s $your_install_dir/bin/nimrod  /usr/bin/nimrod</pre>
+</p>
+<h2 id="installation-on-the-macintosh">Installation on the Macintosh</h2><p>Only MacOS X is supported. Since MacOS X is UNIX based too, it works like the installation on Linux. You need to install Apple's developer's tools for the GNU Compiler Collection though.</p>
+<h2 id="installation-on-windows">Installation on Windows</h2><p>Install Nimrod by downloading and running the <tt class="docutils literal"><span class="pre">nimrod_$version.exe</span></tt> file. As default, the <tt class="docutils literal"><span class="pre">LLVM-GCC</span></tt> compiler is used that is bundled with this installer. You can change the configuration file to use another C compiler.</p>
+<p>Currently, the following C compilers are supported under Windows:</p>
+<ul class="simple"><li><p>Microsoft's Visual C++<br /><a class="reference external" href="http://msdn.microsoft.com/visualc">http://msdn.microsoft.com/visualc</a><br />(You need the SDK too - but not the full one: Essential are only the win32api header files and import libraries.)<br /></p></li>
+<li><p>Gnu C Compiler (the mingw version; the cygwin version has not been tested!)<br /><a class="reference external" href="http://www.mingw.org/download.shtml">http://www.mingw.org/download.shtml</a><br /></p></li>
+<li><p>LLVM with GNU C/C++ frontend<br /><a class="reference external" href="http://llvm.org/releases/download.html#2.2">http://llvm.org/releases/download.html#2.2</a><br /></p></li>
+<li><p>Digital Mars C++<br /><a class="reference external" href="http://www.digitalmars.com/download/freecompiler.html">http://www.digitalmars.com/download/freecompiler.html</a><br /></p></li>
+</ul>
+<p>For better compile times I recommend Digital Mars C++ -- it is easy to install and a small package.</p>
+
+
+<pre>
+  x < 0 && y >= 0
+</pre>
+
+
+      </div>
+    </div>
+    <div id="footer">
+      copyright &copy; 2009 Andreas Rumpf | Last update: 2009-02-10
+      | <a class="reference" href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a>
+      | <a class="reference" href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>
+      | <a class="reference" href="http://www.dcarter.co.uk">design by dcarter</a>
+    </div>
+  </div>
+</body>
+</html>
+