|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "spec_helper" |
| 4 | + |
| 5 | +RSpec.describe Tbx::TermNote do |
| 6 | + describe "TYPES constants" do |
| 7 | + it "defines usageStatus type" do |
| 8 | + expect(described_class::TYPES[:usage_status]).to eq("usageStatus") |
| 9 | + end |
| 10 | + |
| 11 | + it "defines termType type" do |
| 12 | + expect(described_class::TYPES[:term_type]).to eq("termType") |
| 13 | + end |
| 14 | + |
| 15 | + it "defines grammaticalGender type" do |
| 16 | + expect(described_class::TYPES[:grammatical_gender]).to eq("grammaticalGender") |
| 17 | + end |
| 18 | + |
| 19 | + it "defines grammaticalNumber type" do |
| 20 | + expect(described_class::TYPES[:grammatical_number]).to eq("grammaticalNumber") |
| 21 | + end |
| 22 | + |
| 23 | + it "defines partOfSpeech type" do |
| 24 | + expect(described_class::TYPES[:part_of_speech]).to eq("partOfSpeech") |
| 25 | + end |
| 26 | + |
| 27 | + it "defines entailedTerm type" do |
| 28 | + expect(described_class::TYPES[:entailed_term]).to eq("entailedTerm") |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + describe ".entailed_term" do |
| 33 | + it "creates a termNote with entailedTerm type and target" do |
| 34 | + note = described_class.entailed_term(target: "c1") |
| 35 | + expect(note.type).to eq("entailedTerm") |
| 36 | + expect(note.target).to eq("c1") |
| 37 | + expect(note.content).to be_nil |
| 38 | + end |
| 39 | + |
| 40 | + it "creates a termNote with content" do |
| 41 | + note = described_class.entailed_term(target: "c2", content: "related term") |
| 42 | + expect(note.type).to eq("entailedTerm") |
| 43 | + expect(note.target).to eq("c2") |
| 44 | + expect(note.content).to eq(["related term"]) |
| 45 | + end |
| 46 | + |
| 47 | + it "serializes to valid XML" do |
| 48 | + note = described_class.entailed_term(target: "c1", content: "term text") |
| 49 | + xml = note.to_xml |
| 50 | + doc = Nokogiri::XML(xml) |
| 51 | + expect(doc.errors).to be_empty |
| 52 | + el = doc.at_xpath("//tbx:termNote", "tbx" => Tbx::Namespace.uri) |
| 53 | + expect(el["type"]).to eq("entailedTerm") |
| 54 | + expect(el["target"]).to eq("c1") |
| 55 | + expect(el.text).to eq("term text") |
| 56 | + end |
| 57 | + |
| 58 | + it "serializes without content" do |
| 59 | + note = described_class.entailed_term(target: "c1") |
| 60 | + xml = note.to_xml |
| 61 | + doc = Nokogiri::XML(xml) |
| 62 | + el = doc.at_xpath("//tbx:termNote", "tbx" => Tbx::Namespace.uri) |
| 63 | + expect(el["type"]).to eq("entailedTerm") |
| 64 | + expect(el["target"]).to eq("c1") |
| 65 | + end |
| 66 | + |
| 67 | + it "round-trips through XML" do |
| 68 | + original = described_class.entailed_term(target: "c3", content: "another term") |
| 69 | + xml = original.to_xml |
| 70 | + parsed = described_class.from_xml(xml) |
| 71 | + expect(parsed.type).to eq("entailedTerm") |
| 72 | + expect(parsed.target).to eq("c3") |
| 73 | + expect(parsed.content.join).to eq("another term") |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + describe "standard termNote creation" do |
| 78 | + it "creates a usageStatus note" do |
| 79 | + note = described_class.new(type: described_class::TYPES[:usage_status], content: ["admittedTerm"]) |
| 80 | + expect(note.type).to eq("usageStatus") |
| 81 | + expect(note.content).to eq(["admittedTerm"]) |
| 82 | + end |
| 83 | + |
| 84 | + it "creates a termType note" do |
| 85 | + note = described_class.new(type: described_class::TYPES[:term_type], content: ["fullForm"]) |
| 86 | + expect(note.type).to eq("termType") |
| 87 | + end |
| 88 | + |
| 89 | + it "creates a grammaticalGender note" do |
| 90 | + note = described_class.new(type: described_class::TYPES[:grammatical_gender], content: ["masculine"]) |
| 91 | + expect(note.type).to eq("grammaticalGender") |
| 92 | + end |
| 93 | + end |
| 94 | +end |
0 commit comments