android_string_resources_validator 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb33197c711f35efcbda45b9f63accdda01bb62d
|
4
|
+
data.tar.gz: 75b84c69a50c06c181382c47d42e7296d16e89e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56cfb3ebc3551d4a47862ce49be1b7d40c795f9b41705f4b2715c68396827694504e21e57a24e8999a2dfd3c6037c4dc623daff47a9d637e596d17c54b37712
|
7
|
+
data.tar.gz: 356a1214ad133906edf45c11e67c9f88da57f73217b7d178f35182f816ea8a3472e09d09fd7a8bd104006189644faa55e243da21bfdd60f87c8f77d7c9b7a4e9
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# AndroidStringResourcesValidator
|
2
2
|
|
3
|
-
[](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce)
|
3
|
+
[](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce) [](https://codeclimate.com/github/magplus/android_string_resources_validator) 
|
4
|
+
|
4
5
|
|
5
6
|
Validates an Android strings.xml resource file against the specification at
|
6
7
|
http://developer.android.com/guide/topics/resources/string-resource.html
|
@@ -2,8 +2,8 @@ require "android_string_resources_validator/version"
|
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
4
|
class AndroidStringResourcesValidator
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(xml)
|
6
|
+
@xml = xml
|
7
7
|
end
|
8
8
|
|
9
9
|
def valid?
|
@@ -11,21 +11,29 @@ class AndroidStringResourcesValidator
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def errors
|
14
|
-
strings.map(&:error).compact
|
14
|
+
(strings.map(&:error) << xml_error << document_type_error).compact
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
19
|
attr_reader :string
|
20
20
|
|
21
|
+
def xml_error
|
22
|
+
"Not a valid XML document" unless doc.errors.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def document_type_error
|
26
|
+
"Not a string resource document" unless doc.xpath('/resources').length == 1
|
27
|
+
end
|
28
|
+
|
21
29
|
def strings
|
22
|
-
doc.xpath('
|
30
|
+
doc.xpath('/resources/string').map do |element|
|
23
31
|
ElementString.new(element.text)
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
27
35
|
def doc
|
28
|
-
Nokogiri::XML(@
|
36
|
+
Nokogiri::XML(@xml)
|
29
37
|
end
|
30
38
|
|
31
39
|
class ElementString
|
@@ -37,6 +37,20 @@ describe AndroidStringResourcesValidator do
|
|
37
37
|
assert_valid %q{Special identifiers such as %& and %d are allowed}
|
38
38
|
end
|
39
39
|
|
40
|
+
specify "Requires valid XML" do
|
41
|
+
invalid_xml = strings_xml('whatever').chop
|
42
|
+
validator = AndroidStringResourcesValidator.new(invalid_xml)
|
43
|
+
validator.errors.should == ["Not a valid XML document"]
|
44
|
+
validator.should_not be_valid
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "Requires a string resources document" do
|
48
|
+
unknown_xml = %q{<foo><string name="ciao">I have no idea what XML this is!<resources>Who knows?</resources></string></foo>}
|
49
|
+
validator = AndroidStringResourcesValidator.new(unknown_xml)
|
50
|
+
validator.errors.should == ["Not a string resource document"]
|
51
|
+
validator.should_not be_valid
|
52
|
+
end
|
53
|
+
|
40
54
|
private
|
41
55
|
|
42
56
|
def strings_xml(string)
|