Skip to content

Commit

Permalink
[master] unique-ptr move test (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Mar 23, 2016
1 parent 0f5a783 commit a153cb0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/unique-ptr.dt
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ Expands to a `UniquePtr` definition over the relevant type.
@return-type (p T)
|#
(def get
(fn extern (p (uq T)) ((mloc (UniquePtr (uq T))))
(@: mloc pointer)))
(fn extern (p (uq T)) ((mloc (ref (UniquePtr (uq T)))))
(@:@ mloc pointer)))

#|
@fn @
Expand Down
28 changes: 28 additions & 0 deletions t/015up/002up-move.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/perl

use warnings;
use strict;
$ENV{"DALE_TEST_ARGS"} ||= "";
my $test_dir = $ENV{"DALE_TEST_DIR"} || ".";
$ENV{PATH} .= ":.";

use Data::Dumper;
use Test::More tests => 3;

my @res = `dalec $ENV{"DALE_TEST_ARGS"} $test_dir/t/src/up-move.dt -o up-move `;
is_deeply(\@res, [], 'No compilation errors');
@res = `./up-move`;
is($?, 0, 'Program executed successfully');

chomp for @res;

is_deeply(\@res, [
'100 0 0',
'0 100 0',
'0 0 100',
],
'Got correct results');

`rm up-move`;

1;
26 changes: 26 additions & 0 deletions t/src/up-move.dt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(import cstdio)
(import macros)
(import unique-ptr)

(std.concepts.instantiate UniquePtr int)

(def main
(fn extern-c int (void)
(let ((myptr (UniquePtr int))
(myptr2 (UniquePtr int))
(myptr3 (UniquePtr int))
(myint \ (malloc' 1 int)))
(setf myint 100)
(init myptr myint)
(printf "%d %d %d\n" (@ myptr)
(cast (get myptr2) intptr)
(cast (get myptr3) intptr))
(setv myptr2 (move myptr))
(printf "%d %d %d\n" (cast (get myptr) intptr)
(@ myptr2)
(cast (get myptr3) intptr))
(setv myptr3 (move myptr2))
(printf "%d %d %d\n" (cast (get myptr) intptr)
(cast (get myptr2) intptr)
(@ myptr3))
0)))

0 comments on commit a153cb0

Please sign in to comment.