import 'dart:io';

import 'package:flutter_test/flutter_test.dart';

/// Enforces the golden rule "user-facing strings are NEVER hardcoded". Scans
/// lib/ for `Text('literal')` / `Text("literal")` with an alphabetic literal —
/// all UI text must come from slang (`t.…`). Variables like `Text(item.label)`
/// and symbols like `Text('?')` are allowed.
void main() {
  test('no hardcoded Text() string literals in lib/', () {
    final textLiteral = RegExp('''Text\\(\\s*['"][A-Za-z]''');
    final offenders = <String>[];

    for (final entity in Directory('lib').listSync(recursive: true)) {
      if (entity is! File || !entity.path.endsWith('.dart')) continue;
      if (entity.path.contains('/i18n/') || entity.path.endsWith('.g.dart')) {
        continue; // generated / translation sources
      }
      if (textLiteral.hasMatch(entity.readAsStringSync())) {
        offenders.add(entity.path);
      }
    }

    expect(
      offenders,
      isEmpty,
      reason: 'Hardcoded Text() literals found (use t.…): $offenders',
    );
  });
}
