Skip to content

Commit

Permalink
[master] unique-ptr setf self test (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Mar 24, 2016
1 parent e5d74d1 commit 299a05d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/unique-ptr.dt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ Expands to a `UniquePtr` definition over the relevant type.
(def setf-move-assign
(fn extern bool ((dst (p (UniquePtr (uq T))))
(src (rv-ref (UniquePtr (uq T)))))
(and (p= dst src)
(return))
(if (not (null (@:@ dst pointer)))
(do (free' (core-@:@ dst pointer))
0)
Expand Down
26 changes: 26 additions & 0 deletions t/015up/006up-move-self.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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-self.dt -o up-move-self `;
is_deeply(\@res, [], 'No compilation errors');
@res = `./up-move-self`;
is($?, 0, 'Program executed successfully');

chomp for @res;

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

`rm up-move-self`;

1;
20 changes: 20 additions & 0 deletions t/src/up-move-self.dt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(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)
(setv myptr2 (move myptr))
(setv myptr2 (move myptr2))
(printf "%d %d %d\n" (cast (get myptr) intptr)
(@ myptr2)
(cast (get myptr3) intptr))
0)))

0 comments on commit 299a05d

Please sign in to comment.