# # $Id: delete.t,v 1.3 2003/12/02 12:12:16 foxr Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # # Test new functionality of ConfigFileEditor::delete # use strict; use Test; use ConfigFileEdit; # # Tests we plan are: # Delete a line from the middle of the test file # with a pile of consistency test. # Delete a line from the end of the test file # with a pile of consistency tests. # NOTE: deleting from the beginning is the same as # from the middle. # BEGIN {plan tests => 8} # # Test deletion of middle element. # - Use the test file test2config.cfg # - Delete the line with key line2 # - Total number of lines should go down by 1. # - line1 - index should not change. # - last - index should go down by 1. sub TestDeleteMiddle { my $editor = ConfigFileEdit->new("test2config.cfg", 0); my $linecount = $editor->LineCount(); my $hashref = $editor->{KeyToLines}; my $initiallast = $hashref->{"last"}; $editor->DeleteLine("line2"); ok($editor->LineCount(), $linecount-1); $hashref = $editor->{KeyToLines}; ok($hashref->{"line1"}, 0); ok($hashref->{"last"}, $initiallast-1); my $deleted = $editor->Find("line2"); if(!defined($deleted)) { ok(1); } else { ok(0); } } # # Test deletion of last element: # - Use the test file test2config.cfg # - Delete the line with key "last" (last line). # - # lines should go down by 1. # - line1 index should not change. # - line2 index should not change. sub TestDeleteEnd { my $editor = ConfigFileEdit->new("test2config.cfg", 0); my $linecount = $editor->LineCount(); my $hashref = $editor->{KeyToLines}; my $line1idx = $hashref->{"line1"}; my $line2idx = $hashref->{"line2"}; $editor->DeleteLine("last"); ok($editor->LineCount(), $linecount-1); $hashref = $editor->{KeyToLines}; # Hash may change due to reindex!! ok($hashref->{"line1"}, $line1idx); ok($hashref->{"line2"}, $line2idx); my $deleted = $editor->Find("last"); if(!defined($deleted)) { ok(1); } else { ok(0); } } TestDeleteMiddle; TestDeleteEnd;