Skip to content

Commit

Permalink
Improve Entry spec using example from SimplePoParser
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-murphy committed Jun 22, 2021
1 parent cecd72c commit 7621538
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.yardoc
.ruby-version
.gitignore
.idea/
Gemfile.lock
InstalledFiles
_yardoc
Expand Down
36 changes: 21 additions & 15 deletions spec/poparser/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,38 @@
}.to raise_error(ArgumentError, "Unknown label blah_blah")
end

# TODO: restore this
it 'should show a hash presentation of an entry' do
@entry.msgid = 'string'
@entry.msgstr = 'reshte'
@entry.translator_comment = ['comment', 'second line of comments']
result = {
:translator_comment => ['comment', 'second line of comments'],
:msgid => 'string',
:msgstr => 'reshte'
}
expect(@entry.to_h).to eq(result)
end

it 'should show a hash presentation of a plural string entry' do
@entry = PoParser::Entry.new
@entry.msgid_plural = 'right word'
@entry.msgstr_0 = %w[mot juste]
@entry.msgstr_1 = %w[mots justes]
@entry.translator_comment = ['comment', 'second line of comments']

result = {
:translator_comment => ['comment', 'second line of comments'],
:msgid_plural => 'right word',
:'msgstr[0]' => %w[mot juste],
:'msgstr[1]' => %w[mots justes]
it 'should show a hash representation of a complex entry' do
# Ensure the to_h method is reversible
# From SimplePoParser::Parser - https://github.com/experteer/simple_po_parser/blob/v1.1.5/spec/simple_po_parser/parser_spec.rb#L31
entry_hash = {
:translator_comment => ["translator-comment", ""],
:extracted_comment => "extract",
:reference => ["reference1", "reference2"],
:flag => "flag",
:previous_msgctxt => "previous context",
:previous_msgid => ["", "multiline\\n", "previous messageid"],
:previous_msgid_plural => "previous msgid_plural",
:msgctxt => "Context",
:msgid => "msgid",
:msgid_plural => ["", "multiline msgid_plural\\n", ""],
"msgstr[0]" => "msgstr 0",
"msgstr[1]" => ["", "msgstr 1 multiline 1\\n", "msgstr 1 line 2\\n"],
"msgstr[2]" => "msgstr 2"
}
expect(@entry.to_h).to eq(result)

entry = PoParser::Entry.new(entry_hash)
expect(entry.to_h).to eq(entry_hash)
end

it 'should translate the entry' do
Expand Down

0 comments on commit 7621538

Please sign in to comment.