Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aliyazdi75 opened this issue Dec 12, 2024 · 3 comments
Open
Labels
package:intl4x type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@aliyazdi75
Copy link

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 aliyazdi75 added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Dec 12, 2024
@aliyazdi75
Copy link
Author

/cc @mosuem

@mosuem
Copy link
Member

mosuem commented Dec 13, 2024

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 😆 dart run and dart test should have the same behavior, so this is unexpected. I will look into it.

@dcharkes any idea?

@dcharkes
Copy link
Contributor

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 🐛 . 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:intl4x type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants