Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
convert test to PIR (from Perl)
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Nov 23, 2009
1 parent c32e3ae commit 3d2018c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 135 deletions.
1 change: 0 additions & 1 deletion setup.pir
Expand Up @@ -187,7 +187,6 @@ SOURCES
# tests not yet converted
unlink('t/standalone.t')
unlink('t/shootout.t')
unlink('t/tables.t')
.end

.sub 'clean' :anon
Expand Down
143 changes: 9 additions & 134 deletions t/tables.t
@@ -1,150 +1,25 @@
#! perl
# Copyright (C) 2005-2009, Parrot Foundation.
#! /usr/local/bin/parrot
# Copyright (C) 2009, Parrot Foundation.
# $Id$

=head1 Lua tables

=head2 Synopsis

% perl t/tables.t
% parrot t/tables.t

=head2 Description

See "Programming in Lua", section 2.5 "Tables".
Wrapper for t/lua-TestMore/test_lua51/221-table.t

=cut

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin";

use Parrot::Test tests => 9;
use Test::More;

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
a = {}
k = "x"
a[k] = 10
a[20] = "great"
print(a["x"])
k = 20
print(a[k])
a["x"] = a ["x"] + 1
print(a["x"])
CODE
10
great
11
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
a = {}
a["x"] = 10
b = a
print(b["x"])
b["x"] = 20
print(a["x"])
a = nil
b = nil
CODE
10
20
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
a = {}
for i=1,1000 do a[i] = i*2 end
print(a[9])
a["x"] = 10
print(a["x"])
print(a["y"])
CODE
18
10
nil
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
a = {}
x = "y"
a[x] = 10
print(a[x])
print(a.x)
print(a.y)
CODE
10
nil
10
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
i = 10; j = "10"; k = "+10"
a = {}
a[i] = "one value"
a[j] = "another value"
a[k] = "yet another value"
print(a[j])
print(a[k])
print(a[tonumber(j)])
print(a[tonumber(k)])
CODE
another value
yet another value
one value
one value
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
t = { {"a","b","c"}, 10 }
print(t[2])
print(t[1][3])
t[1][1] = "A"
print(table.concat(t[1],","))
CODE
10
c
A,b,c
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
local t
t = { {"a","b","c"}, 10 }
print(t[2])
print(t[1][3])
t[1][1] = "A"
print(table.concat(t[1],","))
CODE
10
c
A,b,c
OUT

language_output_like( 'lua', <<'CODE', <<'OUT', 'call' );
a = {}
a()
CODE
/attempt to call/
OUT

language_output_is( 'lua', <<'CODE', <<'OUT', '' );
local t
t = { {"a","b","c"}, 10 }
print((t)[2])
print((t[1])[3]);
(t)[1][2] = "B"
(t[1])[3] = "C"
print(table.concat(t[1],","))
CODE
10
c
a,B,C
OUT
.sub 'main'
$I0 = spawnw 'parrot lua.pbc t/lua-TestMore/test_lua51/221-table.t'
.end

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

# vim: expandtab shiftwidth=4 ft=pir:

0 comments on commit 3d2018c

Please sign in to comment.