Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "gtest/gtest.h"
#include "test/providers/provider_test_utils.h"
 
#ifdef __APPLE__
#include <TargetConditionals.h>
#if TARGET_OS_IOS
#define ORT_IOS
#endif
#endif
 
namespace onnxruntime {
namespace test {
 
namespace str_normalizer_test {
constexpr const char* domain = kOnnxDomain;
const int opset_ver = 10;
 
#ifdef _MSC_VER
const std::string test_locale("en-US");
#else
const std::string test_locale("en_US.UTF-8");
#endif
 
static void InitTestAttr(OpTester& test, const std::string& case_change_action,
                         bool is_case_sensitive,
                         const std::vector<std::string>& stopwords,
                         const std::string& locale) {
  if (!case_change_action.empty()) {
    test.AddAttribute("case_change_action", case_change_action);
  }
  test.AddAttribute("is_case_sensitive", int64_t{is_case_sensitive});
  if (!stopwords.empty()) {
    test.AddAttribute("stopwords", stopwords);
  }
  if (!locale.empty()) {
    test.AddAttribute("locale", locale);
  }
}
}  // namespace str_normalizer_test
 
using namespace str_normalizer_test;
 
TEST(ContribOpTest, StringNormalizerSensitiveNoCase) {
  // - casesensitive approach
  // - no stopwords.
  // - No change case action, expecting default to take over
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "", true, {}, test_locale);
  std::vector<int64_t> dims{4};
  std::vector<std::string> input = {std::string("monday"), std::string("tuesday"),
                                    std::string("wednesday"), std::string("thursday")};
  test.AddInput<std::string>("T", dims, input);
  std::vector<std::string> output(input);  // do the same for now
  test.AddOutput<std::string>("Y", dims, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerSensitiveFilterOutNoCase) {
  // - casesensitive approach
  // - filter out monday
  // - No change case action
 
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {"monday"}, test_locale);
  std::vector<int64_t> dims{4};
  std::vector<std::string> input = {std::string("monday"), std::string("tuesday"),
                                    std::string("wednesday"), std::string("thursday")};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {std::string("tuesday"),
                                     std::string("wednesday"), std::string("thursday")};
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
#ifndef ORT_IOS
TEST(ContribOpTest, StringNormalizerSensitiveFilterOutLower) {
  // - casesensitive approach
  // - filter out monday
  // - LOWER should produce the same output as they are all lower.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "LOWER", true, {"monday"}, test_locale);
  std::vector<int64_t> dims{4};
  std::vector<std::string> input = {std::string("monday"), std::string("tuesday"),
                                    std::string("wednesday"), std::string("thursday")};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {std::string("tuesday"),
                                     std::string("wednesday"), std::string("thursday")};
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerSensitiveFilterOutUpper) {
  // - casesensitive approach
  // - filter out monday
  // - UPPER should produce the same output as they are all lower.
 
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {"monday"}, test_locale);
  std::vector<int64_t> dims{4};
  std::vector<std::string> input = {std::string("monday"), std::string("tuesday"),
                                    std::string("wednesday"), std::string("thursday")};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {std::string("TUESDAY"),
                                     std::string("WEDNESDAY"), std::string("THURSDAY")};
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerSensitiveFilterOutUpperWithLocale) {
  // - case-SENSITIVE approach en_US locale
  // - we test the behavior of a mix of english, french, german, russian and chinese
  //   with en_US locale
  // - filter out monday
  // - UPPER should produce the same output as they are all lower.
 
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {"monday"}, test_locale);
  std::vector<int64_t> dims{7};
  std::vector<std::string> input = {"monday",
                                    "tuesday",
                                    "Besançon",
                                    "École élémentaire",
                                    "Понедельник",
                                    "mit freundlichen grüßen",
                                    "中文"};
  test.AddInput<std::string>("T", dims, input);
 
  // en_US results (default)
  std::vector<std::string> output = {"TUESDAY",
                                     // It does upper case cecedille, accented E
                                     "BESANÇON",
                                     "ÉCOLE ÉLÉMENTAIRE",
                                     // No issues with Cyrllic
                                     "ПОНЕДЕЛЬНИК",
  // Works with german umlaut but fails
  // with german Eszett. Reason being, capital case for Eszett
  // was introduced only recently into encodings
  // and some platforms produce it, but others do not
#ifdef __wasm__
                                     "MIT FREUNDLICHEN GRÜẞEN",
#else
                                     "MIT FREUNDLICHEN GRÜßEN",
#endif
                                     // Chinese do not have cases
                                     "中文"};
  test.AddOutput<std::string>("Y", {6}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveFilterOutUpperWithLocale) {
  // - case-INSENSITIVE approach en_US locale
  // - we test the behavior of a mix of english, french, german, russian and chinese
  //   with en_US locale
  // - filter out monday
  // - UPPER should produce the same output as they are all lower.
 
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", false, {"monday"}, test_locale);
  std::vector<int64_t> dims{7};
  std::vector<std::string> input = {"monday",
                                    "tuesday",
                                    "Besançon",
                                    "École élémentaire",
                                    "Понедельник",
                                    "mit freundlichen grüßen",
                                    "中文"};
  test.AddInput<std::string>("T", dims, input);
 
  // en_US results (default)
  std::vector<std::string> output = {"TUESDAY",
                                     // It does upper case cecedille, and accented E
                                     "BESANÇON",
                                     "ÉCOLE ÉLÉMENTAIRE",
                                     // No issues with Cyrllic
                                     "ПОНЕДЕЛЬНИК",
  // Works with german umlaut but fails
  // with german Eszett (ß). Reason being, capital case for Eszett
  // was introduced only recently into encodings
  // and some platforms produce it, but others do not
#ifdef __wasm__
                                     "MIT FREUNDLICHEN GRÜẞEN",
#else
                                     "MIT FREUNDLICHEN GRÜßEN",
#endif
 
                                     // Chinese do not have cases
                                     "中文"};
  test.AddOutput<std::string>("Y", {6}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerSensitiveFilterOutUpperEmptyCase) {
  // Empty output case
  // - casesensitive approach
  // - filter out monday
  // - UPPER should produce the same output as they are all lower.
 
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {"monday"}, test_locale);
  std::vector<int64_t> dims{2};
  std::vector<std::string> input = {"monday", "monday"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output{""};  // One empty string
  test.AddOutput<std::string>("Y", {1}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerSensitiveFilterOutUpperSameOutput) {
  // Empty output case
  // - casesensitive approach
  // - filter out monday
  // - UPPER should produce the same output as they are all lower.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {"monday"}, "");
  std::vector<int64_t> dims{1, 2};
  std::vector<std::string> input = {std::string("monday"),
                                    std::string("monday")};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output{""};  // One empty string
  test.AddOutput<std::string>("Y", {1, 1}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
#endif
 
// ============================================================
// Additional tests for coverage gaps
// ============================================================
 
#ifndef ORT_IOS
TEST(ContribOpTest, StringNormalizerDefaultIsCaseSensitiveIsFalse) {
  // Omit is_case_sensitive and rely on the schema default of false.
  OpTester test("StringNormalizer", opset_ver, domain);
  test.AddAttribute("stopwords", std::vector<std::string>{"monday"});
  std::vector<int64_t> dims{3};
  std::vector<std::string> input = {"Monday", "Tuesday", "Wednesday"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"Tuesday", "Wednesday"};
  test.AddOutput<std::string>("Y", {2}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveFilterOutLower) {
  // Case-insensitive filtering + LOWER case change.
  // This exercises the can_reuse_wide fast path (compare_caseaction_ == LOWER == case_change_action_).
  // Tests French (accented), German (umlaut/eszett), Russian, Chinese.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "LOWER", false, {"Понедельник", "Besançon"}, test_locale);
  std::vector<int64_t> dims{6};
  std::vector<std::string> input = {"ПОНЕДЕЛЬНИК",  // matches "Понедельник" case-insensitively
                                    "BESANÇON",     // matches "Besançon" case-insensitively
                                    "École élémentaire",
                                    "mit freundlichen grüßen",
                                    "中文",
                                    "Tuesday"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"école élémentaire",
                                     "mit freundlichen grüßen",  // ß stays ß when lowercased
                                     "中文",                     // Chinese has no case
                                     "tuesday"};
  test.AddOutput<std::string>("Y", {4}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveFilterOutNone) {
  // Case-insensitive filtering + NO case change.
  // Strings matching stopwords are removed; survivors keep original case.
  // Tests that Cyrillic and accented Latin stopwords match case-insensitively.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", false, {"понедельник", "école élémentaire"}, test_locale);
  std::vector<int64_t> dims{5};
  std::vector<std::string> input = {"Понедельник",        // matches "понедельник"
                                    "École Élémentaire",  // matches "école élémentaire"
                                    "Besançon",
                                    "中文",
                                    "Thursday"};
  test.AddInput<std::string>("T", dims, input);
 
  // Filtered strings are removed; survivors keep original case
  std::vector<std::string> output = {"Besançon", "中文", "Thursday"};
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveNoStopwordsLower) {
  // Case-insensitive, no stopwords, LOWER case change.
  // Exercises output_no_filtering path with multilingual input.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "LOWER", false, {}, test_locale);
  std::vector<int64_t> dims{5};
  std::vector<std::string> input = {"BESANÇON",
                                    "ÉCOLE ÉLÉMENTAIRE",
                                    "ПОНЕДЕЛЬНИК",
                                    "MIT FREUNDLICHEN GRÜßEN",
                                    "中文"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"besançon",
                                     "école élémentaire",
                                     "понедельник",
                                     "mit freundlichen grüßen",
                                     "中文"};
  test.AddOutput<std::string>("Y", {5}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveFilterUpperMultilingual) {
  // Case-insensitive filtering + UPPER case change (case_change != compare_caseaction_).
  // Exercises the output_filtered_with_wide fallback (cannot reuse cached lowercase wide forms).
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", false, {"besançon", "中文"}, test_locale);
  std::vector<int64_t> dims{5};
  std::vector<std::string> input = {"Besançon",  // matches "besançon"
                                    "École élémentaire",
                                    "Понедельник",
                                    "mit freundlichen grüßen",
                                    "中文"};  // matches "中文" (no case, exact match)
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"ÉCOLE ÉLÉMENTAIRE",
                                     "ПОНЕДЕЛЬНИК",
  // Eszett behavior differs by platform
#ifdef __wasm__
                                     "MIT FREUNDLICHEN GRÜẞEN"
#else
                                     "MIT FREUNDLICHEN GRÜßEN"
#endif
  };
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerEmptyStringInInput) {
  // Input contains empty strings — should not crash or produce invalid output.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {}, test_locale);
  std::vector<int64_t> dims{3};
  std::vector<std::string> input = {"hello", "", "world"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"HELLO", "", "WORLD"};
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerSingleElement) {
  // Single-element input tensor with multi-byte UTF-8.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "LOWER", true, {}, test_locale);
  std::vector<int64_t> dims{1};
  std::vector<std::string> input = {"ÉCOLE"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"école"};
  test.AddOutput<std::string>("Y", {1}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveAllFilteredOutMultilingual) {
  // Case-insensitive: all strings match stopwords → output is [1] with empty string.
  // Uses Cyrillic and Chinese stopwords.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", false, {"понедельник", "中文", "grüßen"}, test_locale);
  std::vector<int64_t> dims{3};
  std::vector<std::string> input = {"ПОНЕДЕЛЬНИК", "中文", "Grüßen"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output{""};
  test.AddOutput<std::string>("Y", {1}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveMixedCaseStopwords) {
  // Stopwords given in mixed case with accented characters should still match.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", false, {"ПОНЕДЕЛЬНИК", "École Élémentaire"}, test_locale);
  std::vector<int64_t> dims{4};
  std::vector<std::string> input = {"понедельник",        // matches "ПОНЕДЕЛЬНИК"
                                    "école élémentaire",  // matches "École Élémentaire"
                                    "Besançon",
                                    "中文"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"Besançon", "中文"};
  test.AddOutput<std::string>("Y", {2}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizer2DInputWithFilteringMultilingual) {
  // 2D shape [1, C] with filtering using multilingual input.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "LOWER", true, {"Понедельник"}, test_locale);
  std::vector<int64_t> dims{1, 4};
  std::vector<std::string> input = {"Понедельник", "BESANÇON", "中文", "ÉCOLE"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"besançon", "中文", "école"};
  test.AddOutput<std::string>("Y", {1, 3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
#endif
 
TEST(ContribOpTest, StringNormalizer2DInputAllFilteredOut) {
  // 2D shape [1, C] with all filtered → output shape [1, 1] with empty string.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {"中文", "Понедельник"}, test_locale);
  std::vector<int64_t> dims{1, 2};
  std::vector<std::string> input = {"中文", "Понедельник"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output{""};
  test.AddOutput<std::string>("Y", {1, 1}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInvalidDimensions3D) {
  // Input with 3 dimensions -> bypass shape metadata so the kernel validation path runs.
  OpTester test("StringNormalizer", opset_ver, domain);
  test.AddShapeToTensorData(false);
  InitTestAttr(test, "NONE", true, {}, test_locale);
  std::vector<int64_t> dims{1, 1, 2};
  std::vector<std::string> input = {"hello", "world"};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", {1, 1, 2}, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Input dimensions are either[C > 0] or [1][C > 0] allowed");
}
 
TEST(ContribOpTest, StringNormalizerInvalidDimensions2DFirstNotOne) {
  // 2D input with first dim != 1 -> bypass shape metadata so the kernel validation path runs.
  OpTester test("StringNormalizer", opset_ver, domain);
  test.AddShapeToTensorData(false);
  InitTestAttr(test, "NONE", true, {}, test_locale);
  std::vector<int64_t> dims{2, 2};
  std::vector<std::string> input = {"a", "b", "c", "d"};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", {2, 2}, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Input dimensions are either[C > 0] or [1][C > 0] allowed");
}
 
TEST(ContribOpTest, StringNormalizerEmpty1DInputRejectedForCompatibility) {
  // Preserve current ORT behavior for empty 1D input.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {}, test_locale);
  std::vector<int64_t> dims{0};
  std::vector<std::string> input{};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", {0}, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Single dimension value must be greater than 0");
}
 
TEST(ContribOpTest, StringNormalizerEmpty2DInputRejectedForCompatibility) {
  // Preserve current ORT behavior for empty [1, 0] input.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {}, test_locale);
  std::vector<int64_t> dims{1, 0};
  std::vector<std::string> input{};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", {1, 0}, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Input dimensions are either[C > 0] or [1][C > 0] allowed");
}
 
TEST(ContribOpTest, StringNormalizerInvalidCaseChangeAction) {
  // Invalid case_change_action should be rejected during kernel construction.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "TITLE", true, {}, test_locale);
  std::vector<int64_t> dims{1};
  std::vector<std::string> input{"hello"};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", dims, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "attribute case_change_action has invalid value");
}
 
TEST(ContribOpTest, StringNormalizerInvalidLocale) {
  // Invalid locale should be rejected when locale-sensitive processing is required
  // on platforms that validate locale names. On wasm, locale construction accepts
  // arbitrary names, so this path succeeds and UPPER still applies.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {}, "ort_invalid_locale_for_test");
  std::vector<int64_t> dims{1};
  std::vector<std::string> input{"hello"};
  test.AddInput<std::string>("T", dims, input);
#ifdef __wasm__
  test.AddOutput<std::string>("Y", dims, std::vector<std::string>{"HELLO"});
  test.Run(OpTester::ExpectResult::kExpectSuccess);
#else
  test.AddOutput<std::string>("Y", dims, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Failed to construct locale with name:");
#endif
}
 
TEST(ContribOpTest, StringNormalizerInvalidLocaleIgnoredWhenUnused) {
  // Invalid locale should not matter when the runtime stays on the UTF-8 passthrough fast path.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", false, {}, "ort_invalid_locale_for_test");
  std::vector<int64_t> dims{1};
  std::vector<std::string> input{"hello"};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", dims, input);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerPassthroughRejectsInvalidUtf8) {
  // Byte-only passthrough path should still validate UTF-8 input.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {}, test_locale);
  std::vector<int64_t> dims{1};
  std::vector<std::string> input{std::string("\xF0\x28\x8C\x28", 4)};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", dims, input);
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Input strings must be valid UTF-8");
}
 
TEST(ContribOpTest, StringNormalizerSensitiveFilteringRejectsInvalidUtf8) {
  // Case-sensitive filtering path should validate UTF-8 even when no wchar conversion is needed.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {"keep"}, test_locale);
  std::vector<int64_t> dims{2};
  std::vector<std::string> input{"keep", std::string("\xF0\x28\x8C\x28", 4)};
  test.AddInput<std::string>("T", dims, input);
  test.AddOutput<std::string>("Y", {1}, std::vector<std::string>{std::string("\xF0\x28\x8C\x28", 4)});
  test.Run(OpTester::ExpectResult::kExpectFailure,
           "Input strings must be valid UTF-8");
}
 
#ifndef ORT_IOS
TEST(ContribOpTest, StringNormalizerGermanEszettLower) {
  // German Eszett (ß) lowercasing: ß should remain ß.
  // This tests the converter and case logic with the problematic German character.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "LOWER", true, {}, test_locale);
  std::vector<int64_t> dims{2};
  std::vector<std::string> input = {"GRÜßEN", "STRAßE"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"grüßen", "straße"};
  test.AddOutput<std::string>("Y", {2}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerInsensitiveGermanEszettFilter) {
  // Case-insensitive filtering with German Eszett in stopwords.
  // "grüßen" lowercased stays "grüßen", should match stopword "grüßen".
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", false, {"grüßen"}, test_locale);
  std::vector<int64_t> dims{3};
  std::vector<std::string> input = {"Grüßen", "Straße", "中文"};
  test.AddInput<std::string>("T", dims, input);
 
  // "Grüßen" lowercased → "grüßen" → matches stopword
  std::vector<std::string> output = {"Straße", "中文"};
  test.AddOutput<std::string>("Y", {2}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
TEST(ContribOpTest, StringNormalizerCyrillicCaseChange) {
  // Full Cyrillic case conversion test.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "UPPER", true, {}, test_locale);
  std::vector<int64_t> dims{3};
  std::vector<std::string> input = {"понедельник", "Вторник", "среда"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"ПОНЕДЕЛЬНИК", "ВТОРНИК", "СРЕДА"};
  test.AddOutput<std::string>("Y", {3}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
#endif
 
TEST(ContribOpTest, StringNormalizerNoStopwordsNoCaseChange) {
  // No stopwords, NONE case change → pure passthrough (fast path).
  // Tests with multilingual content to ensure passthrough preserves bytes exactly.
  OpTester test("StringNormalizer", opset_ver, domain);
  InitTestAttr(test, "NONE", true, {}, test_locale);
  std::vector<int64_t> dims{4};
  std::vector<std::string> input = {"Besançon", "Понедельник", "中文", "grüßen"};
  test.AddInput<std::string>("T", dims, input);
 
  std::vector<std::string> output = {"Besançon", "Понедельник", "中文", "grüßen"};
  test.AddOutput<std::string>("Y", {4}, output);
  test.Run(OpTester::ExpectResult::kExpectSuccess);
}
 
}  // namespace test
}  // namespace onnxruntime