Permalink
Browse files

added test for version

  • Loading branch information...
1 parent a5fda8a commit c3a59ac07a23aa015cd6ca84bf0a7ab57604c233 @dimus dimus committed Mar 14, 2013
Showing with 33 additions and 18 deletions.
  1. +5 −2 lib/biodiversity/parser.rb
  2. +28 −16 spec/parser/scientific_name.spec.rb
@@ -101,7 +101,8 @@ def parse_process(name)
# @family = /^\s*[A-Z][a-z]\+viridae|viroidae/i
# @subfamily = /^\s*[A-Z][a-z]\+virinae|viroinae/i
# @genus = /^\s*[A-Z][a-z]\+virus|viroid/i
-# @species = /^\s*[A-z0-9u0391-u03C9\[\] ]\+virus|phage|viroid|satellite|prion[A-z0-9u0391-u03C9\[\] ]\+/i
+# @species = /^\s*[A-z0-9u0391-u03C9\[\] ]\+virus|phage|
+# viroid|satellite|prion[A-z0-9u0391-u03C9\[\] ]\+/ix
# @parsed = nil
# end
# end
@@ -167,7 +168,9 @@ def initialize(opts = {})
def virus?(a_string)
!!(a_string.match(/\sICTV\s*$/) ||
- a_string.match(/\b(virus|viruses|phage|phages|viroid|viroids|satellite|satellites|prion|prions)\b/i) ||
+ a_string.match(/\b(virus|viruses|
+ phage|phages|viroid|viroids|
+ satellite|satellites|prion|prions)\b/ix) ||
a_string.match(/[A-Z]?[a-z]+virus\b/))
end
@@ -9,27 +9,32 @@
set_parser(ScientificNameParser.new)
end
+ it 'should return version number' do
+ ScientificNameParser.version.should =~ /^\d+\.\d+\.\d+/
+ end
+
it 'should ScientificNameParser::fix_case' do
- names = [
- ["QUERCUS ALBA", "Quercus alba"],
- ["QUERCUS (QUERCUS) ALBA", "Quercus (Quercus) alba"],
+ names = [
+ ["QUERCUS ALBA", "Quercus alba"],
+ ["QUERCUS (QUERCUS) ALBA", "Quercus (Quercus) alba"],
["QÜERCUS", "Qüercus"],
["PARDOSA MOéSTA", "Pardosa moésta"],
]
names.each do |name, capitalization|
ScientificNameParser::fix_case(name).should == capitalization
end
end
-
+
it 'should generate standardized json' do
read_test_file do |y|
JSON.load(json(y[:name])).should == JSON.load(y[:jsn]) unless y[:comment]
end
end
-
+
# it 'should generate new test_file' do
- # new_test = open(File.expand_path(dir + "../../spec/parser/test_data_new.txt"),'w')
+ # new_test = open(File.expand_path(dir +
+ # "../../spec/parser/test_data_new.txt"),'w')
# read_test_file do |y|
# if y[:comment]
# new_test.write y[:comment]
@@ -40,10 +45,12 @@
# end
# end
# end
-
+
it 'should generate reasonable output if parser failed' do
sn = 'ddd sljlkj 3223452432'
- json(sn).should == '{"scientificName":{"parsed":false,"parser_version":"test_version","verbatim":"ddd sljlkj 3223452432"}}' end
+ json(sn).should == '{"scientificName":{"parsed":false,' +
+ '"parser_version":"test_version","verbatim":"ddd sljlkj 3223452432"}}'
+ end
it "should show version when the flag :show_version set to true" do
parse('Homo sapiens')[:scientificName][:parser_version].should_not be_nil
@@ -58,32 +65,36 @@
end
end
-describe "ScientificNameParser with ranked canonicals" do
+describe "ScientificNameParser with ranked canonicals" do
before(:all) do
@parser = ScientificNameParser.new(canonical_with_rank: true)
end
it 'should not influence output for uninomials and binomials' do
data = [
['Ekbainacanthus Yakowlew 1902','Ekbainacanthus'],
- ['Ekboarmia sagnesi herrerai Exposito 2007', 'Ekboarmia sagnesi herrerai'],
+ ['Ekboarmia sagnesi herrerai Exposito 2007',
+ 'Ekboarmia sagnesi herrerai'],
['Ekboarmia holli Oberthür', 'Ekboarmia holli']]
- data.each do |d|
+ data.each do |d|
parsed = @parser.parse(d[0])[:scientificName][:canonical]
parsed.should == d[1]
end
end
it 'should preserve rank for ranked multinomials' do
data = [
- ['Cola cordifolia var. puberula A. Chev.', 'Cola cordifolia var. puberula'],
- ['Abies homolepis forma umbilicata (Mayr) Schelle', 'Abies homolepis forma umbilicata'],
- ['Quercus ilex ssp. ballota (Desf.) Samp', 'Quercus ilex ssp. ballota']
+ ['Cola cordifolia var. puberula A. Chev.',
+ 'Cola cordifolia var. puberula'],
+ ['Abies homolepis forma umbilicata (Mayr) Schelle',
+ 'Abies homolepis forma umbilicata'],
+ ['Quercus ilex ssp. ballota (Desf.) Samp',
+ 'Quercus ilex ssp. ballota']
]
data.each do |d|
parsed = @parser.parse(d[0])[:scientificName][:canonical]
- parsed.should == d[1]
+ parsed.should == d[1]
end
end
@@ -115,7 +126,8 @@
res.keys.size.should == names.size
end
- it "should have parsed name in native ruby format and in returned as a hash with name as a key and parsed data as value" do
+ it "should have parsed name in native ruby format and in returned as \
+ a hash with name as a key and parsed data as value" do
names = []
read_test_file { |n| names << (n[:name]) if n[:name] }
names.uniq!

0 comments on commit c3a59ac

Please sign in to comment.