summaryrefslogtreecommitdiff
path: root/tests/examplefiles
diff options
context:
space:
mode:
Diffstat (limited to 'tests/examplefiles')
-rw-r--r--tests/examplefiles/Error.pmod38
-rw-r--r--tests/examplefiles/FakeFile.pike360
-rw-r--r--tests/examplefiles/example.ma8
-rw-r--r--tests/examplefiles/example.nix80
-rw-r--r--tests/examplefiles/example.stan2
-rw-r--r--tests/examplefiles/function_arrows.coffee11
-rw-r--r--tests/examplefiles/hash_syntax.rb5
-rw-r--r--tests/examplefiles/inet_pton6.dg48
-rw-r--r--tests/examplefiles/livescript-demo.ls2
9 files changed, 530 insertions, 24 deletions
diff --git a/tests/examplefiles/Error.pmod b/tests/examplefiles/Error.pmod
new file mode 100644
index 00000000..808ecb0e
--- /dev/null
+++ b/tests/examplefiles/Error.pmod
@@ -0,0 +1,38 @@
+#pike __REAL_VERSION__
+
+constant Generic = __builtin.GenericError;
+
+constant Index = __builtin.IndexError;
+
+constant BadArgument = __builtin.BadArgumentError;
+
+constant Math = __builtin.MathError;
+
+constant Resource = __builtin.ResourceError;
+
+constant Permission = __builtin.PermissionError;
+
+constant Decode = __builtin.DecodeError;
+
+constant Cpp = __builtin.CppError;
+
+constant Compilation = __builtin.CompilationError;
+
+constant MasterLoad = __builtin.MasterLoadError;
+
+constant ModuleLoad = __builtin.ModuleLoadError;
+
+//! Returns an Error object for any argument it receives. If the
+//! argument already is an Error object or is empty, it does nothing.
+object mkerror(mixed error)
+{
+ if (error == UNDEFINED)
+ return error;
+ if (objectp(error) && error->is_generic_error)
+ return error;
+ if (arrayp(error))
+ return Error.Generic(@error);
+ if (stringp(error))
+ return Error.Generic(error);
+ return Error.Generic(sprintf("%O", error));
+} \ No newline at end of file
diff --git a/tests/examplefiles/FakeFile.pike b/tests/examplefiles/FakeFile.pike
new file mode 100644
index 00000000..48f3ea64
--- /dev/null
+++ b/tests/examplefiles/FakeFile.pike
@@ -0,0 +1,360 @@
+#pike __REAL_VERSION__
+
+//! A string wrapper that pretends to be a @[Stdio.File] object
+//! in addition to some features of a @[Stdio.FILE] object.
+
+
+//! This constant can be used to distinguish a FakeFile object
+//! from a real @[Stdio.File] object.
+constant is_fake_file = 1;
+
+protected string data;
+protected int ptr;
+protected int(0..1) r;
+protected int(0..1) w;
+protected int mtime;
+
+protected function read_cb;
+protected function read_oob_cb;
+protected function write_cb;
+protected function write_oob_cb;
+protected function close_cb;
+
+//! @seealso
+//! @[Stdio.File()->close()]
+int close(void|string direction) {
+ direction = lower_case(direction||"rw");
+ int cr = has_value(direction, "r");
+ int cw = has_value(direction, "w");
+
+ if(cr) {
+ r = 0;
+ }
+
+ if(cw) {
+ w = 0;
+ }
+
+ // FIXME: Close callback
+ return 1;
+}
+
+//! @decl void create(string data, void|string type, void|int pointer)
+//! @seealso
+//! @[Stdio.File()->create()]
+void create(string _data, void|string type, int|void _ptr) {
+ if(!_data) error("No data string given to FakeFile.\n");
+ data = _data;
+ ptr = _ptr;
+ mtime = time();
+ if(type) {
+ type = lower_case(type);
+ if(has_value(type, "r"))
+ r = 1;
+ if(has_value(type, "w"))
+ w = 1;
+ }
+ else
+ r = w = 1;
+}
+
+protected string make_type_str() {
+ string type = "";
+ if(r) type += "r";
+ if(w) type += "w";
+ return type;
+}
+
+//! @seealso
+//! @[Stdio.File()->dup()]
+this_program dup() {
+ return this_program(data, make_type_str(), ptr);
+}
+
+//! Always returns 0.
+//! @seealso
+//! @[Stdio.File()->errno()]
+int errno() { return 0; }
+
+//! Returns size and the creation time of the string.
+Stdio.Stat stat() {
+ Stdio.Stat st = Stdio.Stat();
+ st->size = sizeof(data);
+ st->mtime=st->ctime=mtime;
+ st->atime=time();
+ return st;
+}
+
+//! @seealso
+//! @[Stdio.File()->line_iterator()]
+String.SplitIterator line_iterator(int|void trim) {
+ if(trim)
+ return String.SplitIterator( data-"\r", '\n' );
+ return String.SplitIterator( data, '\n' );
+}
+
+protected mixed id;
+
+//! @seealso
+//! @[Stdio.File()->query_id()]
+mixed query_id() { return id; }
+
+//! @seealso
+//! @[Stdio.File()->set_id()]
+void set_id(mixed _id) { id = _id; }
+
+//! @seealso
+//! @[Stdio.File()->read_function()]
+function(:string) read_function(int nbytes) {
+ return lambda() { return read(nbytes); };
+}
+
+//! @seealso
+//! @[Stdio.File()->peek()]
+int(-1..1) peek(int|float|void timeout) {
+ if(!r) return -1;
+ if(ptr >= sizeof(data)) return 0;
+ return 1;
+}
+
+//! Always returns 0.
+//! @seealso
+//! @[Stdio.File()->query_address()]
+string query_address(void|int(0..1) is_local) { return 0; }
+
+//! @seealso
+//! @[Stdio.File()->read()]
+string read(void|int(0..) len, void|int(0..1) not_all) {
+ if(!r) return 0;
+ if (len < 0) error("Cannot read negative number of characters.\n");
+ int start=ptr;
+ ptr += len;
+ if(zero_type(len) || ptr>sizeof(data))
+ ptr = sizeof(data);
+
+ // FIXME: read callback
+ return data[start..ptr-1];
+}
+
+//! @seealso
+//! @[Stdio.FILE()->gets()]
+string gets() {
+ if(!r) return 0;
+ string ret;
+ sscanf(data,"%*"+(string)ptr+"s%[^\n]",ret);
+ if(ret)
+ {
+ ptr+=sizeof(ret)+1;
+ if(ptr>sizeof(data))
+ {
+ ptr=sizeof(data);
+ if(!sizeof(ret))
+ ret = 0;
+ }
+ }
+
+ // FIXME: read callback
+ return ret;
+}
+
+//! @seealso
+//! @[Stdio.FILE()->getchar()]
+int getchar() {
+ if(!r) return 0;
+ int c;
+ if(catch(c=data[ptr]))
+ c=-1;
+ else
+ ptr++;
+
+ // FIXME: read callback
+ return c;
+}
+
+//! @seealso
+//! @[Stdio.FILE()->unread()]
+void unread(string s) {
+ if(!r) return;
+ if(data[ptr-sizeof(s)..ptr-1]==s)
+ ptr-=sizeof(s);
+ else
+ {
+ data=s+data[ptr..];
+ ptr=0;
+ }
+}
+
+//! @seealso
+//! @[Stdio.File()->seek()]
+int seek(int pos, void|int mult, void|int add) {
+ if(mult)
+ pos = pos*mult+add;
+ if(pos<0)
+ {
+ pos = sizeof(data)+pos;
+ if( pos < 0 )
+ pos = 0;
+ }
+ ptr = pos;
+ if( ptr > strlen( data ) )
+ ptr = strlen(data);
+ return ptr;
+}
+
+//! Always returns 1.
+//! @seealso
+//! @[Stdio.File()->sync()]
+int(1..1) sync() { return 1; }
+
+//! @seealso
+//! @[Stdio.File()->tell()]
+int tell() { return ptr; }
+
+//! @seealso
+//! @[Stdio.File()->truncate()]
+int(0..1) truncate(int length) {
+ data = data[..length-1];
+ return sizeof(data)==length;
+}
+
+//! @seealso
+//! @[Stdio.File()->write()]
+int(-1..) write(string|array(string) str, mixed ... extra) {
+ if(!w) return -1;
+ if(arrayp(str)) str=str*"";
+ if(sizeof(extra)) str=sprintf(str, @extra);
+
+ if(ptr==sizeof(data)) {
+ data += str;
+ ptr = sizeof(data);
+ }
+ else if(sizeof(str)==1)
+ data[ptr++] = str[0];
+ else {
+ data = data[..ptr-1] + str + data[ptr+sizeof(str)..];
+ ptr += sizeof(str);
+ }
+
+ // FIXME: write callback
+ return sizeof(str);
+}
+
+//! @seealso
+//! @[Stdio.File()->set_blocking]
+void set_blocking() {
+ close_cb = 0;
+ read_cb = 0;
+ read_oob_cb = 0;
+ write_cb = 0;
+ write_oob_cb = 0;
+}
+
+//! @seealso
+//! @[Stdio.File()->set_blocking_keep_callbacks]
+void set_blocking_keep_callbacks() { }
+
+//! @seealso
+//! @[Stdio.File()->set_blocking]
+void set_nonblocking(function rcb, function wcb, function ccb,
+ function rocb, function wocb) {
+ read_cb = rcb;
+ write_cb = wcb;
+ close_cb = ccb;
+ read_oob_cb = rocb;
+ write_oob_cb = wocb;
+}
+
+//! @seealso
+//! @[Stdio.File()->set_blocking_keep_callbacks]
+void set_nonblocking_keep_callbacks() { }
+
+
+//! @seealso
+//! @[Stdio.File()->set_close_callback]
+void set_close_callback(function cb) { close_cb = cb; }
+
+//! @seealso
+//! @[Stdio.File()->set_read_callback]
+void set_read_callback(function cb) { read_cb = cb; }
+
+//! @seealso
+//! @[Stdio.File()->set_read_oob_callback]
+void set_read_oob_callback(function cb) { read_oob_cb = cb; }
+
+//! @seealso
+//! @[Stdio.File()->set_write_callback]
+void set_write_callback(function cb) { write_cb = cb; }
+
+//! @seealso
+//! @[Stdio.File()->set_write_oob_callback]
+void set_write_oob_callback(function cb) { write_oob_cb = cb; }
+
+
+//! @seealso
+//! @[Stdio.File()->query_close_callback]
+function query_close_callback() { return close_cb; }
+
+//! @seealso
+//! @[Stdio.File()->query_read_callback]
+function query_read_callback() { return read_cb; }
+
+//! @seealso
+//! @[Stdio.File()->query_read_oob_callback]
+function query_read_oob_callback() { return read_oob_cb; }
+
+//! @seealso
+//! @[Stdio.File()->query_write_callback]
+function query_write_callback() { return write_cb; }
+
+//! @seealso
+//! @[Stdio.File()->query_write_oob_callback]
+function query_write_oob_callback() { return write_oob_cb; }
+
+string _sprintf(int t) {
+ return t=='O' && sprintf("%O(%d,%O)", this_program, sizeof(data),
+ make_type_str());
+}
+
+
+// FakeFile specials.
+
+//! A FakeFile can be casted to a string.
+mixed cast(string to) {
+ switch(to) {
+ case "string": return data;
+ case "object": return this;
+ }
+ error("Can not cast object to %O.\n", to);
+}
+
+//! Sizeof on a FakeFile returns the size of its contents.
+int(0..) _sizeof() {
+ return sizeof(data);
+}
+
+//! @ignore
+
+#define NOPE(X) mixed X (mixed ... args) { error("This is a FakeFile. %s is not available.\n", #X); }
+NOPE(assign);
+NOPE(async_connect);
+NOPE(connect);
+NOPE(connect_unix);
+NOPE(open);
+NOPE(open_socket);
+NOPE(pipe);
+NOPE(tcgetattr);
+NOPE(tcsetattr);
+
+// Stdio.Fd
+NOPE(dup2);
+NOPE(lock); // We could implement this
+NOPE(mode); // We could implement this
+NOPE(proxy); // We could implement this
+NOPE(query_fd);
+NOPE(read_oob);
+NOPE(set_close_on_exec);
+NOPE(set_keepalive);
+NOPE(trylock); // We could implement this
+NOPE(write_oob);
+
+//! @endignore \ No newline at end of file
diff --git a/tests/examplefiles/example.ma b/tests/examplefiles/example.ma
new file mode 100644
index 00000000..a8119ea5
--- /dev/null
+++ b/tests/examplefiles/example.ma
@@ -0,0 +1,8 @@
+1 + 1 (* This is a comment *)
+Global`
+SomeNamespace`Foo
+f[x_, y__, 3, z___] := tsneirsnteintie "fosrt" neisnrteiasrn
+E + 3
+Plus[1,Times[2,3]]
+Map[#1 + #2&, SomePairList]
+Plus[1.,-1,-1.,-1.0,] \ No newline at end of file
diff --git a/tests/examplefiles/example.nix b/tests/examplefiles/example.nix
new file mode 100644
index 00000000..515b686f
--- /dev/null
+++ b/tests/examplefiles/example.nix
@@ -0,0 +1,80 @@
+{ stdenv, fetchurl, fetchgit, openssl, zlib, pcre, libxml2, libxslt, expat
+, rtmp ? false
+, fullWebDAV ? false
+, syslog ? false
+, moreheaders ? false, ...}:
+
+let
+ version = "1.4.4";
+ mainSrc = fetchurl {
+ url = "http://nginx.org/download/nginx-${version}.tar.gz";
+ sha256 = "1f82845mpgmhvm151fhn2cnqjggw9w7cvsqbva9rb320wmc9m63w";
+ };
+
+ rtmp-ext = fetchgit {
+ url = git://github.com/arut/nginx-rtmp-module.git;
+ rev = "1cfb7aeb582789f3b15a03da5b662d1811e2a3f1";
+ sha256 = "03ikfd2l8mzsjwx896l07rdrw5jn7jjfdiyl572yb9jfrnk48fwi";
+ };
+
+ dav-ext = fetchgit {
+ url = git://github.com/arut/nginx-dav-ext-module.git;
+ rev = "54cebc1f21fc13391aae692c6cce672fa7986f9d";
+ sha256 = "1dvpq1fg5rslnl05z8jc39sgnvh3akam9qxfl033akpczq1bh8nq";
+ };
+
+ syslog-ext = fetchgit {
+ url = https://github.com/yaoweibin/nginx_syslog_patch.git;
+ rev = "165affd9741f0e30c4c8225da5e487d33832aca3";
+ sha256 = "14dkkafjnbapp6jnvrjg9ip46j00cr8pqc2g7374z9aj7hrvdvhs";
+ };
+
+ moreheaders-ext = fetchgit {
+ url = https://github.com/agentzh/headers-more-nginx-module.git;
+ rev = "refs/tags/v0.23";
+ sha256 = "12pbjgsxnvcf2ff2i2qdn39q4cm5czlgrng96j8ml4cgxvnbdh39";
+ };
+in
+
+stdenv.mkDerivation rec {
+ name = "nginx-${version}";
+ src = mainSrc;
+
+ buildInputs = [ openssl zlib pcre libxml2 libxslt
+ ] ++ stdenv.lib.optional fullWebDAV expat;
+
+ patches = if syslog then [ "${syslog-ext}/syslog_1.4.0.patch" ] else [];
+
+ configureFlags = [
+ "--with-http_ssl_module"
+ "--with-http_spdy_module"
+ "--with-http_xslt_module"
+ "--with-http_sub_module"
+ "--with-http_dav_module"
+ "--with-http_gzip_static_module"
+ "--with-http_secure_link_module"
+ "--with-ipv6"
+ # Install destination problems
+ # "--with-http_perl_module"
+ ] ++ stdenv.lib.optional rtmp "--add-module=${rtmp-ext}"
+ ++ stdenv.lib.optional fullWebDAV "--add-module=${dav-ext}"
+ ++ stdenv.lib.optional syslog "--add-module=${syslog-ext}"
+ ++ stdenv.lib.optional moreheaders "--add-module=${moreheaders-ext}";
+
+ preConfigure = ''
+ export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${libxml2 }/include/libxml2"
+ '';
+
+ # escape example
+ postInstall = ''
+ mv $out/sbin $out/bin ''' ''${
+ ${ if true then ${ "" } else false }
+ '';
+
+ meta = {
+ description = "A reverse proxy and lightweight webserver";
+ maintainers = [ stdenv.lib.maintainers.raskin];
+ platforms = stdenv.lib.platforms.all;
+ inherit version;
+ };
+}
diff --git a/tests/examplefiles/example.stan b/tests/examplefiles/example.stan
index e936f54a..7eb6fdfc 100644
--- a/tests/examplefiles/example.stan
+++ b/tests/examplefiles/example.stan
@@ -19,6 +19,7 @@ data {
positive_ordered[3] wibble;
corr_matrix[3] grault;
cov_matrix[3] garply;
+ cholesky_factor_cov[3] waldo;
real<lower=-1,upper=1> foo1;
real<lower=0> foo2;
@@ -94,6 +95,7 @@ model {
// lp__ should be highlighted
// normal_log as a function
lp__ <- lp__ + normal_log(plugh, 0, 1);
+ increment_log_prob(normal_log(plugh, 0, 1));
// print statement and string literal
print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~@#$%^&*`'-+={}[].,;: ");
diff --git a/tests/examplefiles/function_arrows.coffee b/tests/examplefiles/function_arrows.coffee
new file mode 100644
index 00000000..cd1ef1e8
--- /dev/null
+++ b/tests/examplefiles/function_arrows.coffee
@@ -0,0 +1,11 @@
+methodA:-> 'A'
+methodB:=> 'B'
+methodC:()=> 'C'
+methodD:()-> 'D'
+methodE:(a,b)-> 'E'
+methodF:(c,d)-> 'F'
+-> 'G'
+=> 'H'
+
+(-> 'I')
+(=> 'J')
diff --git a/tests/examplefiles/hash_syntax.rb b/tests/examplefiles/hash_syntax.rb
new file mode 100644
index 00000000..35b27723
--- /dev/null
+++ b/tests/examplefiles/hash_syntax.rb
@@ -0,0 +1,5 @@
+{ :old_syntax => 'ok' }
+{ 'stings as key' => 'should be ok' }
+{ new_syntax: 'broken until now' }
+{ withoutunderscore: 'should be ok' }
+{ _underscoreinfront: 'might be ok, if I understand the pygments code correct' }
diff --git a/tests/examplefiles/inet_pton6.dg b/tests/examplefiles/inet_pton6.dg
index 4104b3e7..3813d5b8 100644
--- a/tests/examplefiles/inet_pton6.dg
+++ b/tests/examplefiles/inet_pton6.dg
@@ -1,5 +1,5 @@
-re = import!
-sys = import!
+import '/re'
+import '/sys'
# IPv6address = hexpart [ ":" IPv4address ]
@@ -20,7 +20,7 @@ addrv6 = re.compile $ r'(?i)(?:{})(?::{})?$'.format hexpart addrv4
#
# :return: a decimal integer
#
-base_n = (q digits) -> foldl (x y) -> (x * q + y) 0 digits
+base_n = q digits -> foldl (x y -> x * q + y) 0 digits
# Parse a sequence of hexadecimal numbers
@@ -29,7 +29,7 @@ base_n = (q digits) -> foldl (x y) -> (x * q + y) 0 digits
#
# :return: an iterable of Python ints
#
-unhex = q -> q and map p -> (int p 16) (q.split ':')
+unhex = q -> q and map (p -> int p 16) (q.split ':')
# Parse an IPv6 address as specified in RFC 4291.
@@ -39,33 +39,33 @@ unhex = q -> q and map p -> (int p 16) (q.split ':')
# :return: an integer which, written in binary form, points to the same node.
#
inet_pton6 = address ->
- raise $ ValueError 'not a valid IPv6 address' if not (match = addrv6.match address)
+ not (match = addrv6.match address) => raise $ ValueError 'not a valid IPv6 address'
start, end, *ipv4 = match.groups!
is_ipv4 = not $ None in ipv4
shift = (7 - start.count ':' - 2 * is_ipv4) * 16
- raise $ ValueError 'not a valid IPv6 address' if (end is None and shift) or shift < 0
+ (end is None and shift) or shift < 0 => raise $ ValueError 'not a valid IPv6 address'
hexaddr = (base_n 0x10000 (unhex start) << shift) + base_n 0x10000 (unhex $ end or '')
- (hexaddr << 32) + base_n 0x100 (map int ipv4) if is_ipv4 else hexaddr
+ if (is_ipv4 => (hexaddr << 32) + base_n 0x100 (map int ipv4)) (otherwise => hexaddr)
-inet6_type = q -> switch
- not q = 'unspecified'
- q == 1 = 'loopback'
- (q >> 32) == 0x000000000000ffff = 'IPv4-mapped'
- (q >> 64) == 0xfe80000000000000 = 'link-local'
- (q >> 120) != 0x00000000000000ff = 'general unicast'
- (q >> 112) % (1 << 4) == 0x0000000000000000 = 'multicast w/ reserved scope value'
- (q >> 112) % (1 << 4) == 0x000000000000000f = 'multicast w/ reserved scope value'
- (q >> 112) % (1 << 4) == 0x0000000000000001 = 'interface-local multicast'
- (q >> 112) % (1 << 4) == 0x0000000000000004 = 'admin-local multicast'
- (q >> 112) % (1 << 4) == 0x0000000000000005 = 'site-local multicast'
- (q >> 112) % (1 << 4) == 0x0000000000000008 = 'organization-local multicast'
- (q >> 112) % (1 << 4) == 0x000000000000000e = 'global multicast'
- (q >> 112) % (1 << 4) != 0x0000000000000002 = 'multicast w/ unknown scope value'
- (q >> 24) % (1 << 112) == 0x00000000000001ff = 'solicited-node multicast'
- True = 'link-local multicast'
+inet6_type = q -> if
+ q == 0 => 'unspecified'
+ q == 1 => 'loopback'
+ (q >> 32) == 0x000000000000ffff => 'IPv4-mapped'
+ (q >> 64) == 0xfe80000000000000 => 'link-local'
+ (q >> 120) != 0x00000000000000ff => 'general unicast'
+ (q >> 112) % (1 << 4) == 0x0000000000000000 => 'multicast w/ reserved scope value'
+ (q >> 112) % (1 << 4) == 0x000000000000000f => 'multicast w/ reserved scope value'
+ (q >> 112) % (1 << 4) == 0x0000000000000001 => 'interface-local multicast'
+ (q >> 112) % (1 << 4) == 0x0000000000000004 => 'admin-local multicast'
+ (q >> 112) % (1 << 4) == 0x0000000000000005 => 'site-local multicast'
+ (q >> 112) % (1 << 4) == 0x0000000000000008 => 'organization-local multicast'
+ (q >> 112) % (1 << 4) == 0x000000000000000e => 'global multicast'
+ (q >> 112) % (1 << 4) != 0x0000000000000002 => 'multicast w/ unknown scope value'
+ (q >> 24) % (1 << 112) == 0x00000000000001ff => 'solicited-node multicast'
+ otherwise => 'link-local multicast'
-print $ (x -> (inet6_type x, hex x)) $ inet_pton6 $ sys.stdin.read!.strip!
+print $ (x -> inet6_type x, hex x) $ inet_pton6 $ sys.stdin.read!.strip!
diff --git a/tests/examplefiles/livescript-demo.ls b/tests/examplefiles/livescript-demo.ls
index 2ff68c63..16d1894a 100644
--- a/tests/examplefiles/livescript-demo.ls
+++ b/tests/examplefiles/livescript-demo.ls
@@ -9,6 +9,8 @@ underscores_i$d = ->
//regexp2//g
'strings' and "strings" and \strings
+another-word-list = <[ more words ]>
+
[2 til 10]
|> map (* 2)
|> filter (> 5)