first commit
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
Locales.each_pair do |id, (filename, path, locale)|
|
||||
|
||||
describe "#{id}" do
|
||||
|
||||
it "is a valid CSL 1.0.1 locale" do
|
||||
expect(CSL.validate(path)).to eq([])
|
||||
end
|
||||
|
||||
it "has a conventional file name" do
|
||||
expect(filename).to match(/^locales-[a-z]{2}(-[A-Z]{2})?\.xml$/)
|
||||
end
|
||||
|
||||
it "was successfully parsed" do
|
||||
expect(locale).to be_a(CSL::Locale)
|
||||
end
|
||||
|
||||
unless locale.nil?
|
||||
it "has an info element" do
|
||||
expect(locale).to have_info
|
||||
end
|
||||
|
||||
it "has a language" do
|
||||
expect(locale.language).not_to be_empty
|
||||
end
|
||||
|
||||
it "has a region" do
|
||||
expect(locale.region).not_to be_empty
|
||||
end unless NO_REGIONS.include?(locale.language.to_s)
|
||||
|
||||
it "its language and region match the filename" do
|
||||
expect(locale.to_s).to eq(id[8,5])
|
||||
end
|
||||
|
||||
it "has and info/rights element" do
|
||||
expect(locale.info).to have_rights
|
||||
end
|
||||
|
||||
it "is licensed under a CC BY-SA license" do
|
||||
expect(locale.info).to be_default_license
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
describe "The file \"locales.json\"" do
|
||||
before(:all) do
|
||||
locales_file_path = File.join("#{LOCALE_ROOT}", "locales.json")
|
||||
@locales_file_exists = File.exist?(locales_file_path)
|
||||
|
||||
@locales_file_validates = false
|
||||
begin
|
||||
locales = JSON.parse(File.read(locales_file_path))
|
||||
@locales_file_validates = true
|
||||
rescue JSON::ParserError => e
|
||||
end
|
||||
|
||||
@primary_dialects = {}
|
||||
@language_names = {}
|
||||
|
||||
if @locales_file_validates
|
||||
@primary_dialects = locales["primary-dialects"]
|
||||
@language_names = locales["language-names"]
|
||||
end
|
||||
|
||||
# Store locales of locale files (based on their file names)
|
||||
@locale_file_locales = Dir[File.join(LOCALE_ROOT, 'locales-*.xml')].map { |path|
|
||||
filename = File.basename(path)
|
||||
locale = filename[8..-5]
|
||||
}
|
||||
@locale_file_languages = @locale_file_locales.map { |locale| language = locale[0..1] }
|
||||
@locale_file_languages.uniq!
|
||||
end
|
||||
|
||||
it "must be present" do
|
||||
expect(@locales_file_exists).to be true
|
||||
end
|
||||
|
||||
it "must be valid JSON" do
|
||||
if @locales_file_exists
|
||||
expect(@locales_file_validates).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it "must define a primary dialect for every language (e.g. \"de-DE\" for \"de\")" do
|
||||
expect(@locale_file_languages - @primary_dialects.keys).to eq([])
|
||||
end
|
||||
|
||||
it "must define language names for every locale" do
|
||||
expect(@locale_file_locales - @language_names.keys).to eq([])
|
||||
end
|
||||
|
||||
it "must define two language names for every locale (in the language itself and in English)" do
|
||||
incorrect_entries = @language_names.select { |locale, descriptions| descriptions.length != 2 }
|
||||
expect(incorrect_entries).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
plugins/generic/citationStyleLanguage/lib/vendor/citation-style-language/locales/spec/spec_helper.rb
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
require 'csl'
|
||||
require 'json'
|
||||
|
||||
LOCALE_ROOT = File.expand_path('../..', __FILE__)
|
||||
|
||||
NO_REGIONS = %w{
|
||||
eu ar la
|
||||
}
|
||||
|
||||
def load_locale(path)
|
||||
filename = File.basename(path)
|
||||
id = filename[0..-5]
|
||||
|
||||
begin
|
||||
locale = CSL::Locale.load(path)
|
||||
rescue
|
||||
# failed to parse the locale. we'll report the error later
|
||||
end
|
||||
|
||||
[id, [filename, path, locale]]
|
||||
end
|
||||
|
||||
CSL::Schema.default_license = 'http://creativecommons.org/licenses/by-sa/3.0/'
|
||||
CSL::Schema.default_rights_string =
|
||||
'This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License'
|
||||
|
||||
|
||||
print "\nLoading locales"
|
||||
|
||||
Locales = Hash[Dir[File.join(LOCALE_ROOT, '*.xml')].each_with_index.map { |path, i|
|
||||
print '.' if i % 5 == 0
|
||||
load_locale(path)
|
||||
}]
|
||||
|
||||
puts
|
||||
Reference in New Issue
Block a user