spec/marc/spec/queries/query_spec.rb in ruby-marc-spec-0.1.0 vs spec/marc/spec/queries/query_spec.rb in ruby-marc-spec-0.1.1
- old
+ new
@@ -23,17 +23,16 @@
def verify_all(examples)
aggregate_failures { examples.each { |query_str, expected| verify_result(query_str, expected) } }
end
- def query_from(query_str)
- parse_tree = parser.parse(query_str)
- xform.apply(parse_tree)
+ def parse_query(query_str)
+ MARC::Spec.parse_query(query_str)
end
def verify_result(query_str, expected)
- query = query_from(query_str)
+ query = parse_query(query_str)
executor = QueryExecutor.new(marc_record, query)
actual = executor.execute
expect(actual).to eq(expected), -> { failure_msg_for(query_str, query, actual, expected) }
end
@@ -60,21 +59,38 @@
'245^1',
'245$a$b',
'245^1{=\\0}',
'245$a{$b=\\t}$c$d'
].each do |query_str|
- query = query_from(query_str)
+ query = parse_query(query_str)
str = query.to_s
expect(str).not_to include('nil')
all_elements = ([query.tag, query.selector] + query.subqueries).compact
all_elements.each do |elem|
expect(str).to include(elem.to_s)
end
end
end
end
+ describe :tag_str do
+ it 'returns the tag' do
+ examples = {
+ '245$a{$b=\\t}$c$d' => '245',
+ '...$a$c' => '...',
+ '008/22{LDR/6=\b}' => '008',
+ '008[0]/3{/0=\a}' => '008[0]'
+ }
+ aggregate_failures do
+ examples.each do |query_str, expected|
+ query = parse_query(query_str)
+ expect(query.tag_str).to eq(expected)
+ end
+ end
+ end
+ end
+
describe :to_s_inspect do
it 'includes all elements' do
# noinspection RubyLiteralArrayInspection
[
'245$a',
@@ -82,10 +98,10 @@
'245^1',
'245$a$b',
'245^1{=\\0}',
'245$a{$b=\\t}$c$d'
].each do |query_str|
- query = query_from(query_str)
+ query = parse_query(query_str)
inspect_str = query.inspect
expect(inspect_str).not_to include('nil')
all_elements = ([query.tag, query.selector] + query.subqueries).compact
all_elements.each do |elem|
expect(inspect_str).to include(elem.inspect)