Skip to content
Browse files

added style tests

  • Loading branch information...
1 parent 6e74959 commit cecba03c6b071389327e08c15f4933cc3773f121 @inukshuk inukshuk committed
Showing with 233 additions and 0 deletions.
  1. +89 −0 spec/dependent_styles_spec.rb
  2. +84 −0 spec/independent_styles_spec.rb
  3. +19 −0 spec/repository_spec.rb
  4. +41 −0 spec/spec_helper.rb
View
89 spec/dependent_styles_spec.rb
@@ -0,0 +1,89 @@
+Dependents.each_pair do |id, (filename, path, style)|
+
+ describe "dependent style #{id}" do
+
+ it "is a valid CSL 1.0 style" do
+ CSL.validate(path).should == []
+ end
+
+ it "has a conventional file name" do
+ filename.should match(/^[a-z\d]+(-[a-z\d]+)*\.csl$/)
+ end
+
+ it "was successfully parsed" do
+ style.should be_a(CSL::Style)
+ end
+
+ unless style.nil?
+ it "is dependent" do
+ style.should be_dependent
+ end
+
+ it "has an info element" do
+ style.should have_info
+ end
+
+ it "does not have any rendering elements" do
+ style.should_not have_macro
+ style.should_not have_citation
+ style.should_not have_bibliography
+ end
+
+ it "the self-link (if present) is a valid style repository link" do
+ if style.has_self_link?
+ style.self_link.should == "http://www.zotero.org/styles/#{id}"
+ end
+ end
+
+ it "the self-link (if present) matches the style id" do
+ if style.has_self_link?
+ style.id.should == style.self_link
+ end
+ end
+
+ it "does not have a template-link" do
+ style.should_not have_template_link
+ end
+
+ it "has an id" do
+ style.should have_id
+ end
+
+ it "the id is a valid style repository link" do
+ style.id.should == "http://www.zotero.org/styles/#{id}"
+ end
+
+ it "has and info/rights element" do
+ style.info.should have_rights
+ end
+
+ it "is licensed under a CC BY-SA license" do
+ style.info.rights.to_s.strip.should ==
+ 'This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/'
+ end
+
+ it "its independent-parent link points to an existing style" do
+ link = style.independent_parent_link
+
+ link.should match(%r{http://www.zotero.org/styles/([a-z-]+)})
+ Independents.should have_key(link[/[^\/]+$/])
+ end
+
+ it "has at least one info/category" do
+ style.info.should have_categories
+ end
+
+ it "has a citation-format" do
+ style.citation_format.should_not be_nil
+ end
+
+ it "has the same citation-format as its independent-parent" do
+ parent = style.independent_parent_link[/[^\/]+$/]
+ parent = Independents[parent][-1]
+
+ style.citation_format.should == parent.citation_format
+ end
+
+ end
+ end
+end
View
84 spec/independent_styles_spec.rb
@@ -0,0 +1,84 @@
+Independents.each_pair do |id, (filename, path, style)|
+
+ describe "independent style #{id}" do
+
+ it "is a valid CSL 1.0 style" do
+ CSL.validate(path).should == []
+ end
+
+ it "has a conventional file name" do
+ filename.should match(/^[a-z\d]+(-[a-z\d]+)*\.csl$/)
+ end
+
+ it "was successfully parsed" do
+ style.should be_a(CSL::Style)
+ end
+
+ unless style.nil?
+ it "is independent" do
+ style.should be_independent
+ end
+
+ it "has an info element" do
+ style.should have_info
+ end
+
+ it "has a self-link" do
+ style.should have_self_link
+ end
+
+ it "has an id" do
+ style.info.should have_id
+ end
+
+ it "the self-link is a valid style repository link" do
+ style.self_link.should == "http://www.zotero.org/styles/#{id}"
+ end
+
+ it "the self-link matches the style id" do
+ style.id.should == style.self_link
+ end
+
+ it "has and info/rights element" do
+ style.info.should have_rights
+ end
+
+ it "is licensed under a CC BY-SA license" do
+ style.info.rights.to_s.strip.should ==
+ 'This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/'
+ end
+
+ it "its template-link (if present) points to an existing independent style" do
+ if style.has_template_link?
+ link = style.template_link
+
+ link.should match(%r{http://www.zotero.org/styles/([a-z-]+)})
+ Independents.should have_key(link[/[^\/]+$/])
+ end
+ end
+
+ unless %w{ all bibtex blank national-archives-of-australia }.include?(id)
+ it "has at least one info/category" do
+ style.info.should have_categories
+ end
+
+ it "has a citation-format" do
+ style.citation_format.should_not be_nil
+ end
+
+ it "its citation-format is valid" do
+ style.citation_format.to_s.should match(/^author(-date)?|numeric|label|note/)
+ end
+ end
+
+ it "defines all macros that are referenced by text or key nodes" do
+ style.descendants!.each do |node|
+ if node.matches?(/^key|text$/, :macro => /./)
+ style.macros.should have_key(node[:macro])
+ end
+ end
+ end
+ end
+
+ end
+end
View
19 spec/repository_spec.rb
@@ -0,0 +1,19 @@
+describe "The CSL Style Repository" do
+
+ it "contains independent styles" do
+ Independents.should_not be_empty
+ end
+
+ it "contains dependent styles" do
+ Dependents.should_not be_empty
+ end
+
+ it "does not contain any duplicate file names" do
+ (Independents.keys & Dependents.keys).should be_empty
+ end
+
+ # it "contains no duplicate ISSNs" do
+ # ISSN.select { |k,v| v.length > 1 }.should == []
+ # end
+
+end
View
41 spec/spec_helper.rb
@@ -0,0 +1,41 @@
+require 'csl'
+
+STYLE_ROOT = File.expand_path('../..', __FILE__)
+
+ISSN = Hash.new { |h,k| h[k] = [] }
+
+def load_style(path)
+ filename = File.basename(path)
+ id = filename[0..-5]
+
+ begin
+ style = CSL::Style.load(path)
+ rescue
+ # failed to parse the style. we'll report the error later
+ end
+
+ begin
+ ISSN[style.info.issn.to_s] << id if style.info.has_issn?
+ rescue
+ warn "Failed to extract ISSN of style #{id}"
+ end
+
+ [id, [filename, path, style]]
+end
+
+
+print "\nLoading dependent styles"
+
+Dependents = Hash[Dir[File.join(STYLE_ROOT, 'dependent', '*.csl')].each_with_index.map { |path, i|
+ print '.' if i % 100 == 0
+ load_style(path)
+}]
+
+print "\nLoading independent styles"
+
+Independents = Hash[Dir[File.join(STYLE_ROOT, '*.csl')].each_with_index.map { |path, i|
+ print '.' if i % 100 == 0
+ load_style(path)
+}]
+
+puts

0 comments on commit cecba03

Please sign in to comment.
Something went wrong with that request. Please try again.