Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_generate_all_localization_files.rb « test - github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 42208e10ea9cf9c9af2c2a2bef2f4415119b09cc (plain)
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
require 'command_test'

class TestGenerateAllLocalizationFiles < CommandTest
  def new_runner(create_folders, twine_file = nil, options = {})
    default_options = {}
    default_options[:output_path] = @output_dir
    default_options[:format] = 'apple'
    default_options[:create_folders] = create_folders

    options = default_options.merge options

    unless twine_file
      twine_file = build_twine_file 'en', 'es' do
        add_section 'Section' do
          add_definition key: 'value'
        end
      end
    end

    Twine::Runner.new(options, twine_file)
  end

  class TestFormatterSelection < TestGenerateAllLocalizationFiles
    def setup
      super
      Dir.mkdir File.join @output_dir, 'values-en'

      # both Android and Tizen can handle folders containing `values-en`
      android_formatter = prepare_mock_formatter(Twine::Formatters::Android)
      tizen_formatter = prepare_mock_formatter(Twine::Formatters::Tizen, false)
    end

    def new_runner(options = {})
      super(true, nil, options)
    end

    def test_returns_error_for_ambiguous_output_path
      assert_raises Twine::Error do
        new_runner(format: nil).generate_all_localization_files
      end
    end

    def test_uses_specified_formatter_to_resolve_ambiguity
      # implicit assert that this call doesn't raise an exception
      new_runner(format: 'android').generate_all_localization_files
    end
  end

  class TestDoNotCreateFolders < TestGenerateAllLocalizationFiles
    def new_runner(twine_file = nil)
      super(false, twine_file)
    end

    def test_fails_if_output_folder_does_not_exist
      assert_raises Twine::Error do
        new_runner.generate_all_localization_files
      end
    end

    def test_does_not_create_language_folders
      Dir.mkdir File.join @output_dir, 'en.lproj'
      new_runner.generate_all_localization_files
      refute File.exists?(File.join(@output_dir, 'es.lproj')), "language folder should not be created"
    end

    def test_prints_empty_file_warnings
      Dir.mkdir File.join @output_dir, 'en.lproj'
      empty_twine_file = build_twine_file('en') {}
      new_runner(empty_twine_file).generate_all_localization_files
      assert_match "Skipping file at path", Twine::stderr.string
    end
  end

  class TestCreateFolders < TestGenerateAllLocalizationFiles
    def new_runner(twine_file = nil)
      super(true, twine_file)
    end

    def test_creates_output_folder
      FileUtils.remove_entry_secure @output_dir
      new_runner.generate_all_localization_files
      assert File.exists? @output_dir
    end

    def test_creates_language_folders
      new_runner.generate_all_localization_files
      assert File.exists?(File.join(@output_dir, 'en.lproj')), "language folder 'en.lproj' should be created"
      assert File.exists?(File.join(@output_dir, 'es.lproj')), "language folder 'es.lproj' should be created"
    end

    def test_prints_empty_file_warnings
      empty_twine_file = build_twine_file('en') {}
      new_runner(empty_twine_file).generate_all_localization_files

      assert_match "Skipping file at path", Twine::stderr.string
    end
  end

  class TestValidate < CommandTest
    def new_runner(validate)
      Dir.mkdir File.join @output_dir, 'values-en'

      options = {}
      options[:output_path] = @output_dir
      options[:format] = 'android'
      options[:validate] = validate

      twine_file = build_twine_file 'en' do
        add_section 'Section' do
          add_definition key: 'value'
          add_definition key: 'value'
        end
      end

      Twine::Runner.new(options, twine_file)
    end

    def test_does_not_validate_twine_file
      prepare_mock_formatter Twine::Formatters::Android

      new_runner(false).generate_all_localization_files
    end

    def test_validates_twine_file_if_validate
      assert_raises Twine::Error do
        new_runner(true).generate_all_localization_files
      end
    end
  end
end