Kaydet (Commit) 5cc1d5ca authored tarafından Tim Retout's avatar Tim Retout

installer::profiles: Test and rewrite sorting_profile

Change-Id: Ie3c9bddcb4760d2fe2195c1ca0de7520e57d705f
üst 665785c0
......@@ -42,40 +42,33 @@ use installer::systemactions;
# Sorting the content of a profile
#######################################################
sub sorting_profile
{
sub sorting_profile {
my ($profilesref) = @_;
my @profile = ();
my @definedsections = ();
my @sections;
my %section_content;
for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
{
for ( my $i = 0; $i < @{$profilesref}; $i++ ) {
my $line = ${$profilesref}[$i];
if ( $line =~ /^\s*(\[.*\])\s*$/ ) # this is a section (every second line)
{
my $section = $1;
# Skip unless this is a section (every second line)
next unless ( $line =~ /^\s*(\[.*\])\s*$/ );
if (! grep {$_ eq $section} @definedsections)
{
my $sectionline = $section . "\n";
push(@definedsections, $section);
push(@profile, $sectionline);
my $section = $1;
my $next_line = ${$profilesref}[$i+1];
for ( my $j = 0; $j <= $#{$profilesref}; $j++ )
{
my $oneline = ${$profilesref}[$j];
installer::remover::remove_leading_and_ending_whitespaces(\$oneline);
if ( $oneline eq $section )
{
my $nextline = ${$profilesref}[$j+1];
push(@profile, $nextline);
}
}
}
if ( ! exists $section_content{$section} ) {
push @sections, $section;
}
push @{ $section_content{$section} }, $next_line;
}
my @profile;
for my $section (@sections) {
push @profile, "$section\n";
push @profile, @{ $section_content{$section} };
}
return \@profile;
......
# Version: MPL 1.1 / GPLv3+ / LGPLv3+
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License or as specified alternatively below. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# Major Contributor(s):
# [ Copyright (C) 2012 Tim Retout <tim@retout.co.uk> (initial developer) ]
#
# All Rights Reserved.
#
# For minor contributions see the git repository.
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
# instead of those above.
use strict;
use warnings;
use Test::More;
use lib '.';
use installer::profiles;
my @input = map { "$_\n" } split "\n", <<'END';
[foo]
1
NOT SEEN
[bar]
3
[foo]
2
[bar]
4
END
my @expected = map { "$_\n" } split "\n", <<'END';
[foo]
1
2
[bar]
3
4
END
my $result = installer::profiles::sorting_profile(\@input);
is_deeply($result, \@expected);
done_testing();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment