Commit e1c45c63 authored by Jojo Boulix's avatar Jojo Boulix
Browse files

Use locale settings to sort names in exported files. Closes #806.

parent bb080e89
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -315,6 +315,7 @@ sub compare {
            no warnings;
            $key_r = $a <=> $b;
        } else {
            use locale;
            $key_r = $a cmp $b;
        }
        $key_r = -$key_r if ( $mode =~ /r/ );
+13 −1
Original line number Diff line number Diff line
@@ -1027,11 +1027,13 @@ sub check_export {
        if ( !defined($copy) && !defined($name) ) {
            $self->trace( "[E] CSV: "
                  . translate_column_title('copie') . ' or '
                  . translate_column_title('name')
                  . translate_column_title('nom')
                  . " columns not found" );
            $self->failed(1);
        }
        my $irow = 0;
        while ( my $row = $c->getline($fh) ) {
            $irow++;
            for my $t (@csv) {
                my $goodrow = '';
                if ( $t->{-copy} && $t->{-copy} eq $row->[$copy] ) {
@@ -1040,6 +1042,9 @@ sub check_export {
                if ( $t->{-name} && $t->{-name} eq $row->[$name] ) {
                    $goodrow = 'name ' . $t->{-name};
                }
                if ( $t->{-irow} && $t->{-irow} == $irow ) {
                    $goodrow = 'irow ' . $t->{-irow};
                }
                if (   $goodrow
                    && $t->{-question}
                    && defined( $heads{ $t->{-question} } )
@@ -1060,6 +1065,13 @@ sub check_export {
                        "score for $goodrow Q=" . $t->{-question} );
                    $t->{checked} = 1;
                }
                if (   $goodrow
                    && $t->{-aname} )
                {
                    $self->test( $row->[ $name ],
                        $t->{-aname}, "name for $goodrow" );
                    $t->{checked} = 1;
                }
            }
        }
        close $fh;
+3 −3
Original line number Diff line number Diff line
id,name
001,name 1
002,name 2
003,name 3
001,GUILLEVIC
002,GUÉRIN
003,GÜAC
+20 −0
Original line number Diff line number Diff line
@@ -18,6 +18,17 @@
# along with Auto-Multiple-Choice.  If not, see
# <http://www.gnu.org/licenses/>.

use utf8;

# Use and propagate French LANG to test sorting of accentuated strings

use POSIX qw(:locale_h);

for my $lc (qw/ LC_ALL LC_COLLATE LC_MESSAGES LANG /) {
    setlocale( &$lc, "fr_FR.UTF-8" ) if($lc ne 'LANG');
    $ENV{$lc} = "fr_FR.UTF-8";
}

require "./AMC/Test.pm";

AMC::Test->new(
@@ -28,9 +39,18 @@ AMC::Test->new(
    code            => '<preassoc>',
    check_assoc     => { 2 => '002' },
    perfect_copy    => [],
    export_columns  => 'student.copy,student.name',
    export_full_csv => [

        # Test sorting…
        { -irow => 1, -aname => 'GÜAC' },
        { -irow => 2, -aname => 'GUÉRIN' },
        { -irow => 3, -aname => 'GUILLEVIC' },

        # Test checked boxes
        { -copy => 2, -question => 'bq1', -abc => 'B' },
        { -copy => 2, -question => 'bq2', -abc => '0B' },

    ],
)->default_process;