Skip to content

Instantly share code, notes, and snippets.

@koba04
Created November 6, 2010 17:12
Show Gist options
  • Save koba04/665542 to your computer and use it in GitHub Desktop.
Save koba04/665542 to your computer and use it in GitHub Desktop.
配列にundefなどを追加してみるテスト
#!/usr/bin/env perl
use utf8;
use strict;
use warnings;
use Test::More;
my @list = (1..3);
# 空リストをpushしても追加されない
push @list, ();
is(scalar @list, 3, 'push ()');
# myで宣言しただけの配列は追加されない
my @list2;
push @list, @list2;
is(scalar @list, 3, 'push my @list2');
# undefをpushするとundefが追加される
push @list, undef;
is(scalar @list, 4, 'push undef');
is($list[3], undef, 'list[3] is undef');
# (undef)をpushするとundefが追加される
push @list, (undef);
is(scalar @list, 5, 'push (undef)');
is($list[4], undef, 'list[4] is undef');
done_testing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment