i18n icon indicating copy to clipboard operation
i18n copied to clipboard

[intl4x] Inconsistent Sorting Results Between dart run and dart test

Open aliyazdi75 opened this issue 1 year ago • 3 comments

I am encountering inconsistent sorting results when using the intl4x package for locale-sensitive string collation. Specifically, the sorting works correctly when running the application with dart run but produces incorrect results when running tests with dart test.

import 'package:intl4x/collation.dart';
import 'package:intl4x/intl4x.dart';
import 'package:test/test.dart';

void main() {
  group('Locale-Aware Sorting Tests', () {
    test('Sorts words correctly with locale-sensitive collation', () {
      intl = Intl(locale: Locale(language: 'en'));

      List<String> words = [
        '#Bright_Future',
        '5-Star Ratings',
        'Águas Claras',
        'Étoile du Nord',
        'Fjord Explorers',
        'Grüner Baum',
        'Infinity & Beyond',
        'Ljósið',
        'Müller’s Bakery',
        'Nørrebro Adventures',
        'Öl & Smörgås',
        'Sunrise 🌅',
        'Ütopia Designs',
        'α-Group',
        'Ωmega Industries',
        'ßharp Solutions',
      ];

      final collation = intl.collation(
        const CollationOptions(
          sensitivity: Sensitivity.base,
          numeric: true,
        ),
      );

      words.sort(collation.compare);

      // Expected sorted output
      final expectedWords = [
        '#Bright_Future',
        '5-Star Ratings',
        'Águas Claras',
        'Étoile du Nord',
        'Fjord Explorers',
        'Grüner Baum',
        'Infinity & Beyond',
        'Ljósið',
        'Müller’s Bakery',
        'Nørrebro Adventures',
        'Öl & Smörgås',
        'Sunrise 🌅',
        'Ütopia Designs',
        'α-Group',
        'ßharp Solutions',
        'Ωmega Industries',
      ];

      expect(words, equals(expectedWords));
    });
  });
}

Output:

dart --enable-experiment=native-assets test
Building package executable... (1.2s)
Built test:test.
00:01 +0 -1: test/main_test.dart: Locale-Aware Sorting Tests Sorts words correctly with locale-sensitive collation [E]                                                     
  Expected: [
              '#Bright_Future',
              '5-Star Ratings',
              'Águas Claras',
              'Étoile du Nord',
              'Fjord Explorers',
              'Grüner Baum',
              'Infinity & Beyond',
              'Ljósið',
              'Müller’s Bakery',
              'Nørrebro Adventures',
              'Öl & Smörgås',
              'Sunrise 🌅',
              'Ütopia Designs',
              'α-Group',
              'ßharp Solutions',
              'Ωmega Industries'
            ]
    Actual: [
              '#Bright_Future',
              '5-Star Ratings',
              'Fjord Explorers',
              'Grüner Baum',
              'Infinity & Beyond',
              'Ljósið',
              'Müller’s Bakery',
              'Nørrebro Adventures',
              'Sunrise 🌅',
              'Águas Claras',
              'Étoile du Nord',
              'Öl & Smörgås',
              'Ütopia Designs',
              'ßharp Solutions',
              'Ωmega Industries',
              'α-Group'
            ]
     Which: at location [2] is 'Fjord Explorers' instead of 'Águas Claras'
  package:matcher           expect
  test/main_test.dart 66:7  main.<fn>.<fn>

I think the issue is most likely that the native assets are not localized when I run tests.

aliyazdi75 avatar Dec 12 '24 16:12 aliyazdi75

/cc @mosuem

aliyazdi75 avatar Dec 12 '24 16:12 aliyazdi75

First of all, thanks for trying out the package! This is the first issue filed against it, super happy to see it in use.

Not so happy to see a bug :laughing: dart run and dart test should have the same behavior, so this is unexpected. I will look into it.

@dcharkes any idea?

mosuem avatar Dec 13 '24 13:12 mosuem

No hunches. This is using code assets to bundle rust code right? No idea why dart run and dart test would provide different results. This will require a 🤿 to find the 🐛 . 😄

dcharkes avatar Dec 14 '24 10:12 dcharkes