diff --git a/test/unit/nquads_star_encoder_test.exs b/test/unit/nquads_star_encoder_test.exs new file mode 100644 index 0000000..33cef02 --- /dev/null +++ b/test/unit/nquads_star_encoder_test.exs @@ -0,0 +1,76 @@ +defmodule RDF.Star.NQuads.EncoderTest do + use RDF.Test.Case + + alias RDF.NQuads + + test "quoted triples on subject position" do + assert NQuads.Encoder.encode!(graph_with_annotation()) == + """ + << "Foo" >> . + """ + + assert graph_with_annotation() + |> Graph.change_name(EX.Graph) + |> Dataset.new() + |> NQuads.Encoder.encode!() == + """ + << "Foo" >> . + """ + end + + test "quoted triples on object position" do + assert Graph.new([ + statement(), + {EX.AS, EX.ap(), statement()} + ]) + |> NQuads.Encoder.encode!() == + """ + << "Foo" >> . + "Foo" . + """ + + assert Graph.new( + [ + statement(), + {EX.AS, EX.ap(), statement()} + ], + name: EX.Graph + ) + |> Dataset.new() + |> NQuads.Encoder.encode!() == + """ + << "Foo" >> . + "Foo" . + """ + end + + test "nested quoted triples" do + assert Graph.new([ + { + {{EX.s1(), EX.p1(), EX.o1()}, EX.q1(), {EX.s2(), EX.p2(), EX.o2()}}, + EX.q2(), + {{EX.s3(), EX.p3(), EX.o3()}, EX.q3(), {EX.s4(), EX.p4(), EX.o4()}} + } + ]) + |> NQuads.Encoder.encode!() == + """ + << << >> << >> >> << << >> << >> >> . + """ + + assert Graph.new( + [ + { + {{EX.s1(), EX.p1(), EX.o1()}, EX.q1(), {EX.s2(), EX.p2(), EX.o2()}}, + EX.q2(), + {{EX.s3(), EX.p3(), EX.o3()}, EX.q3(), {EX.s4(), EX.p4(), EX.o4()}} + } + ], + name: EX.Graph + ) + |> Dataset.new() + |> NQuads.Encoder.encode!() == + """ + << << >> << >> >> << << >> << >> >> . + """ + end +end