|
849 | 849 | end |
850 | 850 | end |
851 | 851 |
|
| 852 | + describe "#qname" do |
| 853 | + it "#qname" do |
| 854 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname).to eql [:rdfs, nil] |
| 855 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname).to eql [:rdfs, :label] |
| 856 | + expect(RDF::RDFS.label.qname).to eql [:rdfs, :label] |
| 857 | + end |
| 858 | + |
| 859 | + it "#qname with empty prefixes" do |
| 860 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname(prefixes: {})).to be_nil |
| 861 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname(prefixes: {})).to be_nil |
| 862 | + expect(RDF::RDFS.label.qname(prefixes: {})).to be_nil |
| 863 | + end |
| 864 | + |
| 865 | + it "#qname with explicit prefixes" do |
| 866 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql [:rdfs, :""] |
| 867 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql [:rdfs, :label] |
| 868 | + expect(RDF::RDFS.label.qname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql [:rdfs, :label] |
| 869 | + end |
| 870 | + end |
| 871 | + |
| 872 | + describe "#pname" do |
| 873 | + it "#pname" do |
| 874 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').pname).to eql 'rdfs:' |
| 875 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').pname).to eql 'rdfs:label' |
| 876 | + expect(RDF::RDFS.label.pname).to eql 'rdfs:label' |
| 877 | + end |
| 878 | + |
| 879 | + it "#pname with empty prefixes" do |
| 880 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').pname(prefixes: {})).to eq 'http://www.w3.org/2000/01/rdf-schema#' |
| 881 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').pname(prefixes: {})).to eq 'http://www.w3.org/2000/01/rdf-schema#label' |
| 882 | + expect(RDF::RDFS.label.pname(prefixes: {})).to eq 'http://www.w3.org/2000/01/rdf-schema#label' |
| 883 | + end |
| 884 | + |
| 885 | + it "#pname with explicit prefixes" do |
| 886 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').pname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql 'rdfs:' |
| 887 | + expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').pname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql 'rdfs:label' |
| 888 | + expect(RDF::RDFS.label.pname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql 'rdfs:label' |
| 889 | + end |
| 890 | + |
| 891 | + context "escapes" do |
| 892 | + { |
| 893 | + "http://example.org/c-" => 'ex:c\-', |
| 894 | + "http://example.org/c!" => 'ex:c\!', |
| 895 | + "http://example.org/c$" => 'ex:c\$', |
| 896 | + "http://example.org/c&" => 'ex:c\&', |
| 897 | + "http://example.org/c'" => "ex:c\\'", |
| 898 | + "http://example.org/c()" => 'ex:c\(\)', |
| 899 | + "http://example.org/c*+" => 'ex:c\*\+', |
| 900 | + "http://example.org/c;=" => 'ex:c\;\=', |
| 901 | + "http://example.org/c/#" => 'ex:c\/\#', |
| 902 | + "http://example.org/c@_" => 'ex:c\@\_', |
| 903 | + "http://example.org/c:d?" => 'ex:c:d\?', |
| 904 | + "http://example.org/c~z." => 'ex:c\~z\.', |
| 905 | + }.each do |orig, result| |
| 906 | + it "#{orig} => #{result}" do |
| 907 | + uri = RDF::URI(orig) |
| 908 | + pname = uri.pname(prefixes: {ex: "http://example.org/"}) |
| 909 | + expect(uri).to be_valid |
| 910 | + expect(pname).to eql result |
| 911 | + end |
| 912 | + end |
| 913 | + end |
| 914 | + end |
| 915 | + |
852 | 916 | context "Examples" do |
853 | 917 | it "Creating a URI reference (1)" do |
854 | 918 | expect(RDF::URI.new("https://rubygems.org/gems/rdf")).to be_a_uri |
|
956 | 1020 | expect(RDF::URI('http://example.org/path/').parent).to eql RDF::URI('http://example.org/') |
957 | 1021 | end |
958 | 1022 |
|
959 | | - it "#qname" do |
960 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname).to eql [:rdfs, nil] |
961 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname).to eql [:rdfs, :label] |
962 | | - expect(RDF::RDFS.label.qname).to eql [:rdfs, :label] |
963 | | - end |
964 | | - |
965 | | - it "#qname with empty prefixes" do |
966 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname(prefixes: {})).to be_nil |
967 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname(prefixes: {})).to be_nil |
968 | | - expect(RDF::RDFS.label.qname(prefixes: {})).to be_nil |
969 | | - end |
970 | | - |
971 | | - it "#qname with explicit prefixes" do |
972 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql [:rdfs, :""] |
973 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql [:rdfs, :label] |
974 | | - expect(RDF::RDFS.label.qname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql [:rdfs, :label] |
975 | | - end |
976 | | - |
977 | | - it "#pname" do |
978 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').pname).to eql 'rdfs:' |
979 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').pname).to eql 'rdfs:label' |
980 | | - expect(RDF::RDFS.label.pname).to eql 'rdfs:label' |
981 | | - end |
982 | | - |
983 | | - it "#pname with empty prefixes" do |
984 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').pname(prefixes: {})).to eq 'http://www.w3.org/2000/01/rdf-schema#' |
985 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').pname(prefixes: {})).to eq 'http://www.w3.org/2000/01/rdf-schema#label' |
986 | | - expect(RDF::RDFS.label.pname(prefixes: {})).to eq 'http://www.w3.org/2000/01/rdf-schema#label' |
987 | | - end |
988 | | - |
989 | | - it "#pname with explicit prefixes" do |
990 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#').pname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql 'rdfs:' |
991 | | - expect(RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').pname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql 'rdfs:label' |
992 | | - expect(RDF::RDFS.label.pname(prefixes: {rdfs: 'http://www.w3.org/2000/01/rdf-schema#'})).to eql 'rdfs:label' |
993 | | - end |
994 | | - |
995 | 1023 | it "#start_with?" do |
996 | 1024 | expect(RDF::URI('http://example.org/')).to be_start_with('http') |
997 | 1025 | expect(RDF::URI('http://example.org/')).not_to be_start_with('ftp') |
|
0 commit comments