Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class Serializer {
if (slash >= 0) p = p.slice(slash + 1)
var i = 0
while (i < p.length) {
if (this.prefixchars.indexOf(p[i])) {
if (this.prefixchars.indexOf(p[i]) >= 0) {
i++
} else {
break
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/serializer-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { expect } from "chai";
import { graph, Serializer } from "../../src/index";

describe("Serializer", () => {
describe("can make up prefixes", () => {
const serializer = Serializer(graph());
afterEach(() => {
serializer.prefixes = [];
serializer.namespaces = [];
});

it("with a simple URI", () => {
const prefix = serializer.makeUpPrefix("http://example.org");
expect(prefix).to.equal("exa");
});

it("with a URI with a trailing slash", () => {
const prefix = serializer.makeUpPrefix("http://example.org/");
expect(prefix).to.equal("exa");
});

it("with a URI ending with a #", () => {
const prefix = serializer.makeUpPrefix("http://example.org#");
expect(prefix).to.equal("exa");
});

it("with a URI with multiple slashes", () => {
const prefix = serializer.makeUpPrefix(
"http://www.w3.org/ns/shacl"
);
expect(prefix).to.equal("shacl");
});

it("with a URI with multiple slashes and a #", () => {
const prefix = serializer.makeUpPrefix(
"http://www.w3.org/ns/shacl#"
);
expect(prefix).to.equal("shacl");
});

it("with a URI with multiple slashes and a #/", () => {
const prefix = serializer.makeUpPrefix(
"http://www.w3.org/ns/shacl#/"
);
expect(prefix).to.equal("shacl");
});

it("with a URI starting with 'a'", () => {
const prefix = serializer.makeUpPrefix("http://aschema.org");
expect(prefix).to.equal("asc");
});
});
});