<commit_before>require 'xml/focus'

require 'nokogiri'

require 'spec_helpers'

describe XML::Focus do
	context "with shallow documents" do
		context "when focuses on simple sequences" do
			before(:all) do
				xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
				first = '@xml:id="e-2.2"'
				last = '@xml:id="e-2.5"'

				@portion = XML::Focus(xml, first, last)
			end

			it "returns all the required elements" do
				expect(@portion).to have_element('//level2[@xml:id = "e-2.2"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.3"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.4"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.5"]')

				expect(@portion.xpath('//level2')).to have(4).elements
			end

			it "preserves the structure" do
				expect(@portion).to have_element_with_id('e-root')
				expect(@portion).to have_element_with_id('e-2')
			end

			it "does not include extra parents" do
				expect(@portion).to have_no_element('//level1[@xml:id = "e-1"]')
				expect(@portion).to have_no_element('//level1[@xml:id = "e-3"]')
			end

			it "does not include extra siblings" do
				expect(@portion).to have_no_element_with_id('e-1.1')
				expect(@portion).to have_no_element_with_id('e-1.2')

				expect(@portion).to have_no_element_with_id('e-2.1')
				expect(@portion).to have_no_element_with_id('e-2.6')

				expect(@portion).to have_no_element_with_id('e-3.1')
				expect(@portion).to have_no_element_with_id('e-3.2')
			end
		end

		context "when focuses on overlapping sequences" do
			before(:all) do
				xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
				first = '@xml:id="e-2.2"'
				last = '@xml:id="e-3.1"'

				@portion = XML::Focus(xml, first, last)
			end

			it "returns all the required elements" do
				expect(@portion).to have_element('//level2[@xml:id = "e-2.2"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.3"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.4"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.5"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.6"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-3.1"]')

				expect(@portion.xpath('//level2')).to have(6).elements
			end

			it "preserves the structure" do
				expect(@portion).to have_element_with_id('e-root')
				expect(@portion).to have_element_with_id('e-2')
				expect(@portion).to have_element_with_id('e-3')
			end

			it "does not include extra parents" do
				expect(@portion).to have_no_element('//level1[@xml:id = "e-1"]')
			end

			it "does not include extra siblings" do
				expect(@portion).to have_no_element_with_id('e-1.1')
				expect(@portion).to have_no_element_with_id('e-1.2')

				expect(@portion).to have_no_element_with_id('e-2.1')

				expect(@portion).to have_no_element_with_id('e-3.2')
			end
		end
	end

	context "with deep documents" do
		before(:all) do
			xml = Nokogiri::XML(open('spec/fixtures/deep.xml'))
			first = '@xml:id="e-2.2"'
			last = '@xml:id="e-3.3.2.2"'

			@portion = XML::Focus(xml, first, last)
		end

		it "returns all the required elements" do
			expect(@portion).to have_element('//level2[@xml:id = "e-2.2"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.3"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.4"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.5"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.6"]')

			expect(@portion).to have_element('//level2[@xml:id = "e-3.1"]')

			expect(@portion).to have_element('//level3[@xml:id = "e-3.1.1"]')
			expect(@portion).to have_element('//level3[@xml:id = "e-3.1.2"]')
			expect(@portion).to have_element('//level3[@xml:id = "e-3.1.3"]')

			expect(@portion).to have_element('//level2[@xml:id = "e-3.2"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-3.3"]')

			expect(@portion).to have_element('//level3[@xml:id = "e-3.3.1"]')
			expect(@portion).to have_element('//level3[@xml:id = "e-3.3.2"]')

			expect(@portion).to have_element('//level4[@xml:id = "e-3.3.2.1"]')
			expect(@portion).to have_element('//level4[@xml:id = "e-3.3.2.2"]')

			expect(@portion.xpath('//level2')).to have(8).elements
			expect(@portion.xpath('//level3')).to have(5).elements
			expect(@portion.xpath('//level4')).to have(2).elements
		end

		it "preserves the structure" do
			expect(@portion).to have_element_with_id('e-root')

			expect(@portion).to have_element_with_id('e-2')
			expect(@portion).to have_element_with_id('e-3')

			expect(@portion).to have_element_with_id('e-3.1')

			expect(@portion).to have_element_with_id('e-3.2')
			expect(@portion).to have_element_with_id('e-3.3')
		end

		it "does not include extra parents" do
			expect(@portion).to have_no_element('//level1[@xml:id = "e-1"]')
			expect(@portion).to have_no_element('//level1[@xml:id = "e-3.4"]')
		end

		it "does not include extra siblings" do
			expect(@portion).to have_no_element_with_id('e-1.1')
			expect(@portion).to have_no_element_with_id('e-1.2')

			expect(@portion).to have_no_element_with_id('e-2.1')

			expect(@portion).to have_no_element_with_id('e-3.3.2.3')
			expect(@portion).to have_no_element_with_id('e-3.3.3')
			expect(@portion).to have_no_element_with_id('e-3.4')
		end
	end
end<commit_msg>Tests for quote escaping<commit_after>require 'xml/focus'

require 'nokogiri'

require 'spec_helpers'

describe XML::Focus do
	context "with shallow documents" do
		context "when focuses on simple sequences" do
			before(:all) do
				xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
				first = '@xml:id="e-2.2"'
				last = '@xml:id="e-2.5"'

				@portion = XML::Focus(xml, first, last)
			end

			it "returns all the required elements" do
				expect(@portion).to have_element('//level2[@xml:id = "e-2.2"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.3"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.4"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.5"]')

				expect(@portion.xpath('//level2')).to have(4).elements
			end

			it "preserves the structure" do
				expect(@portion).to have_element_with_id('e-root')
				expect(@portion).to have_element_with_id('e-2')
			end

			it "does not include extra parents" do
				expect(@portion).to have_no_element('//level1[@xml:id = "e-1"]')
				expect(@portion).to have_no_element('//level1[@xml:id = "e-3"]')
			end

			it "does not include extra siblings" do
				expect(@portion).to have_no_element_with_id('e-1.1')
				expect(@portion).to have_no_element_with_id('e-1.2')

				expect(@portion).to have_no_element_with_id('e-2.1')
				expect(@portion).to have_no_element_with_id('e-2.6')

				expect(@portion).to have_no_element_with_id('e-3.1')
				expect(@portion).to have_no_element_with_id('e-3.2')
			end
		end

		context "when focuses on overlapping sequences" do
			before(:all) do
				xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
				first = '@xml:id="e-2.2"'
				last = '@xml:id="e-3.1"'

				@portion = XML::Focus(xml, first, last)
			end

			it "returns all the required elements" do
				expect(@portion).to have_element('//level2[@xml:id = "e-2.2"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.3"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.4"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.5"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-2.6"]')
				expect(@portion).to have_element('//level2[@xml:id = "e-3.1"]')

				expect(@portion.xpath('//level2')).to have(6).elements
			end

			it "preserves the structure" do
				expect(@portion).to have_element_with_id('e-root')
				expect(@portion).to have_element_with_id('e-2')
				expect(@portion).to have_element_with_id('e-3')
			end

			it "does not include extra parents" do
				expect(@portion).to have_no_element('//level1[@xml:id = "e-1"]')
			end

			it "does not include extra siblings" do
				expect(@portion).to have_no_element_with_id('e-1.1')
				expect(@portion).to have_no_element_with_id('e-1.2')

				expect(@portion).to have_no_element_with_id('e-2.1')

				expect(@portion).to have_no_element_with_id('e-3.2')
			end
		end
	end

	context "with deep documents" do
		before(:all) do
			xml = Nokogiri::XML(open('spec/fixtures/deep.xml'))
			first = '@xml:id="e-2.2"'
			last = '@xml:id="e-3.3.2.2"'

			@portion = XML::Focus(xml, first, last)
		end

		it "returns all the required elements" do
			expect(@portion).to have_element('//level2[@xml:id = "e-2.2"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.3"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.4"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.5"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-2.6"]')

			expect(@portion).to have_element('//level2[@xml:id = "e-3.1"]')

			expect(@portion).to have_element('//level3[@xml:id = "e-3.1.1"]')
			expect(@portion).to have_element('//level3[@xml:id = "e-3.1.2"]')
			expect(@portion).to have_element('//level3[@xml:id = "e-3.1.3"]')

			expect(@portion).to have_element('//level2[@xml:id = "e-3.2"]')
			expect(@portion).to have_element('//level2[@xml:id = "e-3.3"]')

			expect(@portion).to have_element('//level3[@xml:id = "e-3.3.1"]')
			expect(@portion).to have_element('//level3[@xml:id = "e-3.3.2"]')

			expect(@portion).to have_element('//level4[@xml:id = "e-3.3.2.1"]')
			expect(@portion).to have_element('//level4[@xml:id = "e-3.3.2.2"]')

			expect(@portion.xpath('//level2')).to have(8).elements
			expect(@portion.xpath('//level3')).to have(5).elements
			expect(@portion.xpath('//level4')).to have(2).elements
		end

		it "preserves the structure" do
			expect(@portion).to have_element_with_id('e-root')

			expect(@portion).to have_element_with_id('e-2')
			expect(@portion).to have_element_with_id('e-3')

			expect(@portion).to have_element_with_id('e-3.1')

			expect(@portion).to have_element_with_id('e-3.2')
			expect(@portion).to have_element_with_id('e-3.3')
		end

		it "does not include extra parents" do
			expect(@portion).to have_no_element('//level1[@xml:id = "e-1"]')
			expect(@portion).to have_no_element('//level1[@xml:id = "e-3.4"]')
		end

		it "does not include extra siblings" do
			expect(@portion).to have_no_element_with_id('e-1.1')
			expect(@portion).to have_no_element_with_id('e-1.2')

			expect(@portion).to have_no_element_with_id('e-2.1')

			expect(@portion).to have_no_element_with_id('e-3.3.2.3')
			expect(@portion).to have_no_element_with_id('e-3.3.3')
			expect(@portion).to have_no_element_with_id('e-3.4')
		end
	end

	describe "quote support" do
		it "works with double quotes in condition" do
			xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
			first = %q{@xml:id="e-2.2"}
			last = %q{@xml:id="e-2.5"}

			expect { XML::Focus(xml, first, last) }.not_to raise_exception
		end

		it "works with single quotes in condition" do
			pending("Not yet implemented")

			xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
			first = %q{@xml:id='e-2.2'}
			last = %q{@xml:id='e-2.5'}

			expect { XML::Focus(xml, first, last) }.not_to raise_exception
		end

		it "works with mixed quotes in condition" do
			pending("Not yet implemented")

			xml = Nokogiri::XML(open('spec/fixtures/shallow.xml'))
			first = %q{@xml:id="e-2.2" and name()='level2'}
			last = %q{@xml:id="e-2.5"}

			expect { XML::Focus(xml, first, last) }.not_to raise_exception
		end

		it "works with escaped quotes in condition"
	end
end
{'fraction_non_alphanumeric': 0.20152751258462073, 'fraction_numerical': 0.02976913730255164, 'mean_word_length': 4.1167850799289525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 107}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6781318', 'n_tokens_mistral': 5093, 'n_tokens_neox': 4364, 'n_words': 727}