localizations_utils_test.dart 2.04 KB
Newer Older
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
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../../localization/localizations_utils.dart';

import '../common.dart';

void main() {
  group('generateString', () {
    test('handles simple string', () {
      expect(generateString('abc'), "'abc'");
    });

    test('handles string with quote', () {
      expect(generateString("ab'c"), "'ab\\\'c'");
    });

    test('handles string with double quote', () {
      expect(generateString('ab"c'), "'ab\\\"c'");
    });

    test('handles string with both single and double quote', () {
      expect(generateString('''a'b"c'''), '\'a\\\'b\\"c\'');
    });

    test('handles string with a triple single quote and a double quote', () {
      expect(generateString("""a"b'''c"""), '\'a\\"b\\\'\\\'\\\'c\'');
    });

    test('handles string with a triple double quote and a single quote', () {
      expect(generateString('''a'b"""c'''), '\'a\\\'b\\"\\"\\"c\'');
    });

    test('handles string with both triple single and triple double quote', () {
      expect(generateString('''a\'''b"""c'''), '\'a\\\'\\\'\\\'b\\"\\"\\"c\'');
    });

    test('escapes dollar when escapeDollar is true', () {
40
      expect(generateString(r'ab$c'), "'ab\\\$c'");
41 42 43
    });

    test('handles backslash', () {
44
      expect(generateString(r'ab\c'), r"'ab\\c'");
45 46 47
    });

    test('handles backslash followed by "n" character', () {
48
      expect(generateString(r'ab\nc'), r"'ab\\nc'");
49 50
    });

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    test('supports newline escaping', () {
      expect(generateString('ab\nc'), "'ab\\nc'");
    });

    test('supports form feed escaping', () {
      expect(generateString('ab\fc'), "'ab\\fc'");
    });

    test('supports tab escaping', () {
      expect(generateString('ab\tc'), "'ab\\tc'");
    });

    test('supports carriage return escaping', () {
      expect(generateString('ab\rc'), "'ab\\rc'");
    });

    test('supports backspace escaping', () {
      expect(generateString('ab\bc'), "'ab\\bc'");
69 70 71
    });
  });
}