apfel 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ vendor
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ # JetBrains
21
+ .idea
22
+
23
+ # mac
24
+ .DS_Store
25
+ __MACOSX
26
+
27
+ # emacs turds
28
+ (.*/)?\#[^/]*\#$
29
+
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apfel (0.0.4)
4
+ apfel (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- coderay (1.0.8)
10
- diff-lcs (1.1.3)
9
+ coderay (1.0.9)
10
+ diff-lcs (1.2.2)
11
11
  method_source (0.8.1)
12
- pry (0.9.10)
12
+ pry (0.9.12)
13
13
  coderay (~> 1.0.5)
14
14
  method_source (~> 0.8)
15
- slop (~> 3.3.1)
16
- rake (0.9.2.2)
17
- rspec (2.12.0)
18
- rspec-core (~> 2.12.0)
19
- rspec-expectations (~> 2.12.0)
20
- rspec-mocks (~> 2.12.0)
21
- rspec-core (2.12.0)
22
- rspec-expectations (2.12.0)
23
- diff-lcs (~> 1.1.3)
24
- rspec-mocks (2.12.0)
25
- slop (3.3.3)
15
+ slop (~> 3.4)
16
+ rake (10.0.4)
17
+ rspec (2.13.0)
18
+ rspec-core (~> 2.13.0)
19
+ rspec-expectations (~> 2.13.0)
20
+ rspec-mocks (~> 2.13.0)
21
+ rspec-core (2.13.1)
22
+ rspec-expectations (2.13.0)
23
+ diff-lcs (>= 1.1.3, < 2.0)
24
+ rspec-mocks (2.13.1)
25
+ slop (3.4.4)
26
26
 
27
27
  PLATFORMS
28
28
  ruby
data/Rakefile CHANGED
@@ -6,11 +6,6 @@ rescue LoadError
6
6
  end
7
7
  Bundler::GemHelper.install_tasks
8
8
 
9
- require 'rspec/core/rake_task'
10
- RSpec::Core::RakeTask.new do |t|
11
- t.rspec_opts = ["--color", '--order rand']
12
- end
13
-
14
9
  desc "Run all tests and documentation checks"
15
10
  task :qa => [:spec]
16
11
 
@@ -11,6 +11,6 @@ require 'apfel/dot_strings_parser'
11
11
  end
12
12
 
13
13
  def self.read(file)
14
- Reader.read(file)
14
+ Reader.read(file)
15
15
  end
16
16
  end
@@ -4,14 +4,16 @@ module Apfel
4
4
  # Reads in a file and returns an array consisting of each line of input
5
5
  # cleaned of new line characters
6
6
  def self.read(file)
7
- File.open(file, "r") do |f|
8
- content_array=[]
9
- content = f.read
10
- content.each_line do |line|
7
+ File.open(file, 'r') do |f|
8
+ content = f.read.force_encoding('UTF-8')
9
+ # remove the BOM that can be found at char 0 in UTF8 strings files
10
+ if content.chars.first == "\xEF\xBB\xBF".force_encoding('UTF-8')
11
+ content.slice!(0)
12
+ end
13
+ content.each_line.inject([]) do |content_array, line|
11
14
  line.gsub!("\n","")
12
15
  content_array.push(line)
13
16
  end
14
- content_array
15
17
  end
16
18
  end
17
19
  end
@@ -1,3 +1,3 @@
1
1
  module Apfel
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,7 +4,7 @@ require 'apfel/parsed_dot_strings'
4
4
 
5
5
  describe Apfel do
6
6
  describe '::parse_file' do
7
- context 'when given a valid DotStrings file'do
7
+ context 'when given an ASCII DotStrings file'do
8
8
 
9
9
  let(:parsed_file) do
10
10
  Apfel.parse(valid_file)
@@ -13,16 +13,43 @@ describe Apfel do
13
13
  it 'returns a ParsedDotStrings object' do
14
14
  parsed_file.should be_a(Apfel::ParsedDotStrings)
15
15
  end
16
+
17
+ it 'should have the correct keys' do
18
+ parsed_file.keys.should include 'key_number_one'
19
+ parsed_file.keys.should include 'key_number_two'
20
+ parsed_file.keys.should include 'key_number_three'
21
+ end
22
+
23
+ it 'should have the correct values' do
24
+ parsed_file.values.should include 'value number one'
25
+ parsed_file.values.should include 'value number two'
26
+ parsed_file.values.should include 'value number three'
27
+ end
28
+
29
+ describe 'should have the correct comments' do
30
+ it 'should have the correct comment for first' do
31
+ parsed_file.comments(with_keys: false).should include 'This is the first comment'
32
+ end
33
+
34
+ it 'should have the correct comment for second' do
35
+ parsed_file.comments['key_number_two'].should == 'This is a multiline comment'
36
+ end
37
+
38
+
39
+ it 'should have the correct comment for third' do
40
+ parsed_file.comments(with_keys: false).should include 'This is comment number 3'
41
+ end
42
+ end
16
43
  end
17
44
 
18
45
  context 'when given an invalid strings file' do
19
46
  context 'missing a semicolon' do
20
47
 
21
48
  let(:invalid_file_semicolon) do
22
- create_temp_file( <<-EOS
49
+ create_temp_file('ascii', <<-EOS
23
50
  /* This is the first comment */
24
51
  "key_number_one" = "value number one"
25
- EOS
52
+ EOS
26
53
  )
27
54
  end
28
55
 
@@ -35,7 +62,7 @@ describe Apfel do
35
62
 
36
63
  context 'not closed comment' do
37
64
  let(:invalid_file_comment) do
38
- create_temp_file(<<-EOS
65
+ create_temp_file('ascii', <<-EOS
39
66
  /* This is the first comment
40
67
  "key_number_one" = "value number one";
41
68
 
@@ -54,5 +81,108 @@ multiline comment */
54
81
  end
55
82
  end
56
83
  end
84
+
85
+ context 'when given a file in us-ascii encoding'do
86
+
87
+ let(:ascii_file) do
88
+ './spec/fixtures/ascii.strings'
89
+ end
90
+ it 'the file should be ascii' do
91
+
92
+ # use unix file instead of File.open because
93
+ # File.open(file, 'r') <==> File.open(file, 'r:UTF-8')
94
+ file_info = `file -I #{ascii_file}`
95
+ file_info.should include('charset=us-ascii')
96
+ end
97
+
98
+ let(:parsed_file) do
99
+ Apfel.parse(ascii_file)
100
+ end
101
+
102
+ it 'returns a ParsedDotStrings object' do
103
+ parsed_file.should be_a(Apfel::ParsedDotStrings)
104
+ end
105
+
106
+ it 'should have the correct keys' do
107
+ parsed_file.keys[0].should == 'avoided social event'
108
+ parsed_file.keys[1].should == 'binged'
109
+ parsed_file.keys[2].should == 'called a friend'
110
+ end
111
+
112
+ it 'should have the correct values' do
113
+ parsed_file.values[0].should == 'vermieden soziales Ereignis'
114
+ parsed_file.values[1].should == 'gegessen exzessiv'
115
+ parsed_file.values[2].should == 'Telefon ein Freund'
116
+ end
117
+
118
+ describe 'should have the correct comments' do
119
+ it 'should have the correct comment for avoided social event' do
120
+ parsed_file.comments['avoided social event'].should == 'like a hack-a-thon'
121
+ end
122
+
123
+ it 'should have the correct comment for binged' do
124
+ parsed_file.comments['binged'].should == 'one too many lieb kochen'
125
+ end
126
+
127
+ it 'should have the correct comment for called a friend' do
128
+ parsed_file.comments['called a friend'].should == 'or maybe you just skyped'
129
+ end
130
+ end
131
+ end
132
+
133
+ context 'when given a UTF8 .strings file'do
134
+
135
+ let(:utf8_file) do
136
+ './spec/fixtures/utf8.strings'
137
+ end
138
+
139
+ it 'the file should be utf-8' do
140
+ # use unix file instead of File.open because
141
+ # File.open(file, 'r') <==> File.open(file, 'r:UTF-8')
142
+ file_info = `file -I #{utf8_file}`
143
+ file_info.should include('charset=utf-8')
144
+ end
145
+
146
+ it 'the file should have the BOM as the 0 char' do
147
+ File.open(utf8_file, 'r') do |f|
148
+ content = f.read.force_encoding('UTF-8')
149
+ content.chars.first == "\xEF\xBB\xBF".force_encoding('UTF-8')
150
+ end
151
+ end
152
+
153
+ let(:parsed_file) do
154
+ Apfel.parse(utf8_file)
155
+ end
156
+
157
+ it 'returns a ParsedDotStrings object' do
158
+ parsed_file.should be_a(Apfel::ParsedDotStrings)
159
+ end
160
+
161
+ it 'should have the correct keys' do
162
+ parsed_file.keys[0].should == 'anger'
163
+ parsed_file.keys[1].should == 'anxiety'
164
+ parsed_file.keys[2].should == 'boredom'
165
+ end
166
+
167
+ it 'should have the correct values' do
168
+ parsed_file.values[0].should == 'Zorn'
169
+ parsed_file.values[1].should == 'Sorge'
170
+ parsed_file.values[2].should == 'Langeweile'
171
+ end
172
+
173
+ describe 'should have the correct comments' do
174
+ it 'should have the correct comment for anger' do
175
+ parsed_file.comments['anger'].should == 'when the toast falls butter-side down'
176
+ end
177
+
178
+ it 'should have the correct comment for anxiety' do
179
+ parsed_file.comments['anxiety'].should == 'when you realize you left the oven on'
180
+ end
181
+
182
+ it 'should have the correct comment for boredom' do
183
+ parsed_file.comments['boredom'].should == 'ennui'
184
+ end
185
+ end
186
+ end
57
187
  end
58
188
  end
@@ -0,0 +1,9 @@
1
+ /* like a hack-a-thon */
2
+ "avoided social event" = "vermieden soziales Ereignis";
3
+
4
+ /* one too many lieb kochen */
5
+ "binged" = "gegessen exzessiv";
6
+
7
+ /* or maybe you just skyped */
8
+ "called a friend" = "Telefon ein Freund";
9
+
@@ -0,0 +1,8 @@
1
+ /* when the toast falls butter-side down */
2
+ "anger" = "Zorn";
3
+
4
+ /* when you realize you left the oven on */
5
+ "anxiety" = "Sorge";
6
+
7
+ /* ennui */
8
+ "boredom" = "Langeweile";
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'apfel'
3
- require 'parsed_dot_strings'
3
+ require 'apfel/parsed_dot_strings'
4
4
 
5
5
  module Apfel
6
6
  describe ParsedDotStrings do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
- require 'reader'
2
+ require 'apfel/reader'
3
3
 
4
4
  module Apfel
5
5
  describe Reader do
6
6
  describe '#read' do
7
7
  let(:temp_file) do
8
- create_temp_file(<<-EOS
8
+ create_temp_file('ascii', <<-EOS
9
9
  This is a file with some lines.
10
10
  Roses are red, violets are blue.
11
11
  This text is really boring,
@@ -1,13 +1,14 @@
1
1
  require 'tempfile'
2
2
  require 'json'
3
- def create_temp_file(string)
4
- temp_file = Tempfile.new('temp')
3
+
4
+ def create_temp_file(encoding, string)
5
+ temp_file = Tempfile.new([encoding, 'temp'])
5
6
  temp_file << string
6
7
  temp_file.flush
7
8
  end
8
9
 
9
- def valid_file
10
- create_temp_file(<<-EOS
10
+ def valid_file(encoding='ascii')
11
+ create_temp_file(encoding, <<-EOS
11
12
  /* This is the first comment */
12
13
  "key_number_one" = "value number one";
13
14
 
@@ -18,6 +19,6 @@ multiline comment */
18
19
  "key_number_two" = "value number two";
19
20
  /* This is comment number 3 */
20
21
  "key_number_three" = " value number three ";
21
- EOS
22
+ EOS
22
23
  )
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apfel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-01 00:00:00.000000000 Z
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -66,6 +66,7 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - .gitignore
69
70
  - Gemfile
70
71
  - Gemfile.lock
71
72
  - LICENSE
@@ -80,6 +81,8 @@ files:
80
81
  - lib/apfel/reader.rb
81
82
  - lib/apfel/version.rb
82
83
  - spec/apfel_spec.rb
84
+ - spec/fixtures/ascii.strings
85
+ - spec/fixtures/utf8.strings
83
86
  - spec/parsed_dot_strings_spec.rb
84
87
  - spec/reader_spec.rb
85
88
  - spec/spec_helper.rb
@@ -97,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
100
  version: '0'
98
101
  segments:
99
102
  - 0
100
- hash: -2757969226826093779
103
+ hash: 2059895837407952673
101
104
  required_rubygems_version: !ruby/object:Gem::Requirement
102
105
  none: false
103
106
  requirements:
@@ -106,15 +109,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  version: '0'
107
110
  segments:
108
111
  - 0
109
- hash: -2757969226826093779
112
+ hash: 2059895837407952673
110
113
  requirements: []
111
114
  rubyforge_project: apfel
112
- rubygems_version: 1.8.24
115
+ rubygems_version: 1.8.23
113
116
  signing_key:
114
117
  specification_version: 3
115
118
  summary: Simple parser for DotStrings Files
116
119
  test_files:
117
120
  - spec/apfel_spec.rb
121
+ - spec/fixtures/ascii.strings
122
+ - spec/fixtures/utf8.strings
118
123
  - spec/parsed_dot_strings_spec.rb
119
124
  - spec/reader_spec.rb
120
125
  - spec/spec_helper.rb