simple_po_parser 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74fd13b4d65428c06cebf73f052271c53fe2403b
4
- data.tar.gz: eca6c142f4c5272f06e66ea9fcc88ce68261cbbc
3
+ metadata.gz: 3b7a33f4b10faa83677bce933ae9a517130e7b69
4
+ data.tar.gz: 3c79c5d7e32c58db9a1556b8681bb52743214b85
5
5
  SHA512:
6
- metadata.gz: 4b41b0f49b24ec840e044471c675662057bff8fb76474e8bf7480b3d1cf44c10cee5c98e3bae9e1336ff49e09d9bcdf5780b2bc0e82498210ed761902c8fd369
7
- data.tar.gz: e1ec0a70f6dbdfb4ad53bc84fb4457c7e61f5e5d4c508f58a8efbc505d19692c647e747d87250f343bbcfbb52884e47f5c8740bb356174b9fe75f031d45a1798
6
+ metadata.gz: 18cd57e0e5fd0d05926eef3c400430fced95ee98201c29b9b61e41d258245f3dd12baefd29a2dc5caefd7ca8ef4979b49a6ca8c9a726432a0f2560b72cbc0987
7
+ data.tar.gz: 35450f6ea2e0e0ab58bedd3458681a66d05fa75eddfa6ad3b9be31b7a65f2621caab70b79859c7a04f3002b503e8390b740f0a8349a13ba5fe824b745d7b9501
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_po_parser (1.1.0)
4
+ simple_po_parser (1.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -14,7 +14,7 @@ module SimplePoParser
14
14
 
15
15
  # parses a single message.
16
16
  def parse_message(message)
17
- Parser.parse(message)
17
+ Parser.new.parse(message)
18
18
  end
19
19
  end
20
20
 
@@ -1,5 +1,5 @@
1
1
  module SimplePoParser
2
- # FastParser directly using Rubys powerful StringScanner (strscan)
2
+ # Fast parser directly using Rubys powerful StringScanner (strscan)
3
3
  #
4
4
  # Important notes about StringScanner.scan:
5
5
  # * scan will return nil if there is no match. Using the regex * (zero or more) quantifier will
@@ -8,10 +8,9 @@ module SimplePoParser
8
8
  # * the start of line anchor ^ is obsolete as scan will only match start of line.
9
9
  # * rubys regex is by default in single-line mode, therefore scan will only match until
10
10
  # the next newline is hit (unless multi-line mode is explicitly enabled)
11
- module Parser
11
+ class Parser
12
12
  require_relative 'error'
13
13
  require 'strscan'
14
- extend self
15
14
 
16
15
  # parse a single message of the PO format.
17
16
  #
@@ -15,7 +15,7 @@ module SimplePoParser
15
15
 
16
16
  private
17
17
  def parse_block(block)
18
- Parser.parse(block)
18
+ Parser.new.parse(block)
19
19
  end
20
20
  end
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module SimplePoParser
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -12,7 +12,7 @@ describe SimplePoParser::Parser do
12
12
  :msgid => "",
13
13
  :msgstr => ["", "Project-Id-Version: simple_po_parser 1\\n", "Report-Msgid-Bugs-To: me\\n"]
14
14
  }
15
- expect(SimplePoParser::Parser.parse(po_header)).to eq(expected_result)
15
+ expect(SimplePoParser::Parser.new.parse(po_header)).to eq(expected_result)
16
16
  end
17
17
 
18
18
  it "parses the simple entry as expected" do
@@ -24,7 +24,7 @@ describe SimplePoParser::Parser do
24
24
  :msgid => "msgid",
25
25
  :msgstr => "translated"
26
26
  }
27
- expect(SimplePoParser::Parser.parse(po_simple_message)).to eq(expected_result)
27
+ expect(SimplePoParser::Parser.new.parse(po_simple_message)).to eq(expected_result)
28
28
  end
29
29
 
30
30
  it "parses the complex entry as expected" do
@@ -43,36 +43,36 @@ describe SimplePoParser::Parser do
43
43
  "msgstr[1]" => ["", "msgstr 1 multiline 1\\n", "msgstr 1 line 2\\n"],
44
44
  "msgstr[2]" => "msgstr 2"
45
45
  }
46
- expect(SimplePoParser::Parser.parse(po_complex_message)).to eq(expected_result)
46
+ expect(SimplePoParser::Parser.new.parse(po_complex_message)).to eq(expected_result)
47
47
  end
48
48
 
49
49
  context "Errors" do
50
50
  it "errors cascade to ParserError" do
51
51
  message = "invalid message"
52
- expect{ SimplePoParser::Parser.parse(message) }.to raise_error(SimplePoParser::ParserError)
52
+ expect{ SimplePoParser::Parser.new.parse(message) }.to raise_error(SimplePoParser::ParserError)
53
53
  end
54
54
 
55
55
  it "raises an error if there is no msgid" do
56
56
  message = "# comment\nmsgctxt \"ctxt\"\nmsgstr \"translation\""
57
- expect{ SimplePoParser::Parser.parse(message) }.
57
+ expect{ SimplePoParser::Parser.new.parse(message) }.
58
58
  to raise_error(SimplePoParser::ParserError, /Message without msgid is not allowed/)
59
59
  end
60
60
 
61
61
  it "raises an error if there is no msgstr in singular message" do
62
62
  message = "# comment\nmsgctxt \"ctxt\"\nmsgid \"msg\""
63
- expect{ SimplePoParser::Parser.parse(message) }.
63
+ expect{ SimplePoParser::Parser.new.parse(message) }.
64
64
  to raise_error(SimplePoParser::ParserError,
65
65
  /Singular message without msgstr is not allowed/)
66
66
  end
67
67
 
68
68
  it "raises an error if there is no msgstr[0] in plural message" do
69
69
  message = "# comment\nmsgid \"id\"\nmsgid_plural \"msg plural\""
70
- expect{ SimplePoParser::Parser.parse(message) }.
70
+ expect{ SimplePoParser::Parser.new.parse(message) }.
71
71
  to raise_error(SimplePoParser::ParserError,
72
72
  /Plural message without msgstr\[0\] is not allowed/)
73
73
 
74
74
  message = "# comment\nmsgid \"id\"\nmsgid_plural \"msg plural\"\nmsgstr[1] \"plural trans\""
75
- expect{ SimplePoParser::Parser.parse(message) }.
75
+ expect{ SimplePoParser::Parser.new.parse(message) }.
76
76
  to raise_error(SimplePoParser::ParserError,
77
77
  /Bad 'msgstr\[index\]' index/)
78
78
  end
@@ -80,33 +80,33 @@ describe SimplePoParser::Parser do
80
80
  context "comments" do
81
81
  it "raises an error on unknown comment types" do
82
82
  message = "#- no such comment type"
83
- expect{ SimplePoParser::Parser.parse(message) }.
83
+ expect{ SimplePoParser::Parser.new.parse(message) }.
84
84
  to raise_error(SimplePoParser::ParserError, /Unknown comment type/)
85
85
  end
86
86
 
87
87
  it "raises an error on unknown previous comment types" do
88
88
  message = "#| msgstr \"no such comment type\""
89
- expect{ SimplePoParser::Parser.parse(message) }.
89
+ expect{ SimplePoParser::Parser.new.parse(message) }.
90
90
  to raise_error(SimplePoParser::ParserError, /Previous comment type .*? unknown/)
91
91
  message = "#| bla "
92
- expect{ SimplePoParser::Parser.parse(message) }.
92
+ expect{ SimplePoParser::Parser.new.parse(message) }.
93
93
  to raise_error(SimplePoParser::ParserError, /Previous comments must start with '#| msg'/)
94
94
  end
95
95
 
96
96
  it "raises an error if any lines are not marked obsolete after the first obsolete line" do
97
97
  message = "# comment\n#~msgid \"hi\"\nmsgstr \"should be obsolete\""
98
- expect{ SimplePoParser::Parser.parse(message) }.
98
+ expect{ SimplePoParser::Parser.new.parse(message) }.
99
99
  to raise_error(SimplePoParser::ParserError,
100
100
  /All lines must be obsolete after the first obsolete line, but got/)
101
101
  end
102
102
 
103
103
  it "raises an error if previous comments are not marked obsolete in obsolete entries" do
104
104
  message = "# comment\n#| msgid \"hi\"\n#~msgid \"hi\"\n#~msgstr \"should be obsolete\""
105
- expect{ SimplePoParser::Parser.parse(message) }.
105
+ expect{ SimplePoParser::Parser.new.parse(message) }.
106
106
  to raise_error(SimplePoParser::ParserError,
107
107
  /Previous comment entries need to be marked obsolete too in obsolete message entries/)
108
108
  message = "# comment\n#| msgctxt \"hi\"\n#~msgid \"hi\"\n#~msgstr \"should be obsolete\""
109
- expect{ SimplePoParser::Parser.parse(message) }.
109
+ expect{ SimplePoParser::Parser.new.parse(message) }.
110
110
  to raise_error(SimplePoParser::ParserError,
111
111
  /Previous comment entries need to be marked obsolete too in obsolete message entries/)
112
112
  end
@@ -115,21 +115,21 @@ describe SimplePoParser::Parser do
115
115
  context "message_line" do
116
116
  it "raises an error if a message_line does not start with a double quote" do
117
117
  message = "msgid No starting double quote\""
118
- expect{ SimplePoParser::Parser.parse(message) }.
118
+ expect{ SimplePoParser::Parser.new.parse(message) }.
119
119
  to raise_error(SimplePoParser::ParserError,
120
120
  /A message text needs to start with the double quote character/)
121
121
  end
122
122
 
123
123
  it "raises an error if a message_line does not end with a double quote" do
124
124
  message = "msgid \"No ending double quote"
125
- expect{ SimplePoParser::Parser.parse(message) }.
125
+ expect{ SimplePoParser::Parser.new.parse(message) }.
126
126
  to raise_error(SimplePoParser::ParserError,
127
127
  /The message text .*? must be finished with the double quote character/)
128
128
  end
129
129
 
130
130
  it "raises an error if there is anything but whitespace after the ending double quote" do
131
131
  message = "msgid \"text\" this shouldn't be here"
132
- expect{ SimplePoParser::Parser.parse(message) }.
132
+ expect{ SimplePoParser::Parser.new.parse(message) }.
133
133
  to raise_error(SimplePoParser::ParserError,
134
134
  /There should be only whitespace until the end of line after the double quote character/)
135
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_po_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis-Florian Herr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler