package selection_queries

import (
	"strings"
	"testing"
)

func TestSelectionQueriesUseNamedGraphs(t *testing.T) {
	selected := []NodeRef{
		{ID: 1, TermType: "uri", IRI: "http://example.com/A"},
	}

	tests := []struct {
		name  string
		query string
	}{
		{name: "neighbors", query: neighborsQuery(selected, false)},
		{name: "superclasses", query: superclassesQuery(selected, false)},
		{name: "subclasses", query: subclassesQuery(selected, false)},
	}

	for _, tt := range tests {
		if !strings.Contains(tt.query, "SELECT DISTINCT ?s ?p ?o") {
			t.Fatalf("%s query should de-duplicate triples across named graphs:\n%s", tt.name, tt.query)
		}
		if !strings.Contains(tt.query, "GRAPH ?g") {
			t.Fatalf("%s query should read from named graphs:\n%s", tt.name, tt.query)
		}
		if strings.Contains(tt.query, "owl:Class") {
			t.Fatalf("%s query should no longer depend on owl:Class:\n%s", tt.name, tt.query)
		}
	}
}
