Skip to content

Commit

Permalink
refactor: rename handle to seeder (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikjabiri authored Oct 1, 2023
1 parent 006d1e6 commit c342226
Show file tree
Hide file tree
Showing 87 changed files with 596 additions and 546 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ coverage
**/*.dwl
**/*.dwl2
**/*.err
**/*.py
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/document.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`XDocument class > should create dxf document 1`] = `
exports[`Document class > should create dxf document 1`] = `
"0
SECTION
2
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/writer.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`XWriter class > should match snapshot 1`] = `
exports[`Writer class > should match snapshot 1`] = `
"0
SECTION
2
Expand Down
24 changes: 11 additions & 13 deletions __tests__/blocks/block.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Block, BlockRecordEntry, Handle, TagsManager } from "@/index";
import { Block, BlockRecordEntry, Seeder, TagsManager } from "@/index";

describe("Block class", () => {
const handle = new Handle();
const options = { name: "*Model_Space" };
const seeder = new Seeder();
const options = { name: "*Model_Space", seeder };
it("should create an empty block", () => {
const block = new Block(
options,
handle,
new BlockRecordEntry(options, handle)
);
const block = new Block({
...options,
blockRecord: new BlockRecordEntry(options),
});
block.addAppDefined("ACAD_REACTORS");
const mg = new TagsManager();
block.tagify(mg);
Expand All @@ -19,11 +18,10 @@ describe("Block class", () => {
});

it("should create defined application", () => {
const block = new Block(
options,
handle,
new BlockRecordEntry(options, handle)
);
const block = new Block({
...options,
blockRecord: new BlockRecordEntry(options),
});
const reactors = block.addAppDefined("ACAD_REACTORS");
expect(reactors.name).toBe("ACAD_REACTORS");
const test = block.addAppDefined("ACAD_REACTORS");
Expand Down
10 changes: 7 additions & 3 deletions __tests__/blocks/blocks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Blocks, Handle, Tables, TagsManager } from "@/index";
import { Blocks, Seeder, Tables, TagsManager } from "@/index";

describe("Blocks class", () => {
const handle = new Handle();
const seeder = new Seeder();
it("should create a blocks section", () => {
const blocks = new Blocks(new Tables(handle), handle);
const options = { seeder };
const blocks = new Blocks({
...options,
tables: new Tables(options),
});
const mg = new TagsManager();
blocks.tagify(mg);
expect(mg.stringify()).toMatchSnapshot();
Expand Down
6 changes: 3 additions & 3 deletions __tests__/blocks/endblk.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { EndBlk, Handle, TagsManager } from "@/index";
import { EndBlk, Seeder, TagsManager } from "@/index";

describe("EndBlk class", () => {
it("should create an endblk instance", () => {
const block = new EndBlk(new Handle());
const block = new EndBlk({ seeder: new Seeder() });
block.addAppDefined("ACAD_REACTORS");
const mg = new TagsManager();
block.tagify(mg);
expect(mg.stringify()).toMatchSnapshot();
});

it("should create defined application", () => {
const block = new EndBlk(new Handle());
const block = new EndBlk({ seeder: new Seeder() });
const reactors = block.addAppDefined("ACAD_REACTORS");
expect(reactors.name).toBe("ACAD_REACTORS");
const test = block.addAppDefined("ACAD_REACTORS");
Expand Down
2 changes: 1 addition & 1 deletion __tests__/document.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Document, Units } from "@/index";

describe("XDocument class", () => {
describe("Document class", () => {
it("should create dxf document", () => {
const document = new Document();
expect(document.stringify()).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/entities/__snapshots__/line.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`XLine class > should create a line entity 1`] = `
exports[`Line class > should create a line entity 1`] = `
"0
LINE
5
Expand Down
5 changes: 3 additions & 2 deletions __tests__/entities/dimension/arc.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ArcDimension, ArcDimensionOptions } from "@/entities";
import { Handle, TagsManager, point } from "@/utils";
import { Seeder, TagsManager, point } from "@/utils";

describe("ArcDimension class", () => {
it("should create a line entity", () => {
const options: ArcDimensionOptions = {
center: point(),
startPoint: point(10),
endPoint: point(0, 10),
seeder: new Seeder(),
};
const arc = new ArcDimension(options, new Handle());
const arc = new ArcDimension(options);
const mg = new TagsManager();
arc.tagify(mg);
expect(mg.stringify()).toMatchSnapshot();
Expand Down
13 changes: 9 additions & 4 deletions __tests__/entities/entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Blocks, Entities, Handle, Tables, TagsManager } from "@/index";
import { Blocks, Entities, Seeder, Tables, TagsManager } from "@/index";

describe("XEntities class", () => {
const handle = new Handle();
describe("Entities class", () => {
const seeder = new Seeder();
it("should create an empty entities section", () => {
const entities = new Entities(new Blocks(new Tables(handle), handle));
const options = { seeder };
const blocks = new Blocks({
...options,
tables: new Tables(options),
});
const entities = new Entities({ ...options, blocks });
const mg = new TagsManager();
entities.tagify(mg);
expect(mg.stringify()).toBe("0\nSECTION\n2\nENTITIES\n0\nENDSEC");
Expand Down
18 changes: 12 additions & 6 deletions __tests__/entities/entity.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Entity, Handle, TagsManager } from "@/index";
import { Entity, Seeder, TagsManager } from "@/index";

class DummyEntity extends Entity {
override get subClassMarker(): string | undefined {
return;
}

constructor() {
super({ seeder: new Seeder() });
this._type = "LINE";
}

protected override tagifyChild(): void {}
}

describe("Entity class", () => {
it("should have the default values", () => {
const dummy = new DummyEntity("LINE", new Handle());
const dummy = new DummyEntity();
const xdata = dummy.addXData("XDATA_TEST");
xdata.layerName("0");
const mg = new TagsManager();
Expand All @@ -21,7 +27,7 @@ describe("Entity class", () => {
});

it("should return the visibility", () => {
const dummy = new DummyEntity("LINE", new Handle());
const dummy = new DummyEntity();
expect(dummy.visibility).toBeUndefined();
dummy.visible = false;
expect(dummy.visibility).toBe(1);
Expand All @@ -30,7 +36,7 @@ describe("Entity class", () => {
});

it("should return existing defined application", () => {
const dummy = new DummyEntity("LINE", new Handle());
const dummy = new DummyEntity();
const reactors = dummy.addAppDefined("ACAD_REACTORS");
const xdictionary = dummy.addAppDefined("ACAD_XDICTIONARY");
expect(reactors.name).toBe("ACAD_REACTORS");
Expand All @@ -40,13 +46,13 @@ describe("Entity class", () => {
});

it("should create new defined application", () => {
const dummy = new DummyEntity("LINE", new Handle());
const dummy = new DummyEntity();
const test = dummy.addAppDefined("ACAD_TEST");
expect(test.name).toBe("ACAD_TEST");
});

it("should create new XData", () => {
const dummy = new DummyEntity("LINE", new Handle());
const dummy = new DummyEntity();
const xdata = dummy.addXData("XDATA_TEST");
expect(xdata.name).toBe("XDATA_TEST");
const test = dummy.addXData("XDATA_TEST");
Expand Down
52 changes: 23 additions & 29 deletions __tests__/entities/face.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
import { Face, InvisibleEdge } from "@/entities";
import { Handle, TagsManager, point } from "@/utils";
import { Seeder, TagsManager, point } from "@/utils";

describe("Face class", () => {
it("should cover the face entity", () => {
const mg = new TagsManager();
const handle = new Handle();
const face1 = new Face(
{
first: point(),
second: point(10),
third: point(10, 10),
fourth: point(0, 10),
},
handle
);
const seeder = new Seeder();
const face1 = new Face({
first: point(),
second: point(10),
third: point(10, 10),
fourth: point(0, 10),
seeder,
});
face1.tagify(mg);
const face2 = new Face(
{
first: point(0, 0, 10),
second: point(10, 0, 10),
third: point(10, 10, 10),
},
handle
);
const face2 = new Face({
first: point(0, 0, 10),
second: point(10, 0, 10),
third: point(10, 10, 10),
seeder,
});
face2.tagify(mg);

const face3 = new Face(
{
first: point(0, 0, 5),
second: point(10, 0, 5),
third: point(10, 10, 5),
fourth: point(0, 10, 5),
flags: InvisibleEdge.Third,
},
handle
);
const face3 = new Face({
first: point(0, 0, 5),
second: point(10, 0, 5),
third: point(10, 10, 5),
fourth: point(0, 10, 5),
flags: InvisibleEdge.Third,
seeder,
});
face3.tagify(mg);
expect(mg.stringify()).toMatchSnapshot();
});
Expand Down
16 changes: 7 additions & 9 deletions __tests__/entities/line.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Handle, Line, TagsManager, point } from "@/index";
import { Line, Seeder, TagsManager, point } from "@/index";

describe("XLine class", () => {
describe("Line class", () => {
it("should create a line entity", () => {
const line = new Line(
{
start: point(),
end: point(100, 100),
},
new Handle()
);
const line = new Line({
start: point(),
end: point(100, 100),
seeder: new Seeder(),
});
const mg = new TagsManager();
line.tagify(mg);
expect(mg.stringify()).toMatchSnapshot();
Expand Down
10 changes: 5 additions & 5 deletions __tests__/entities/manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {
BlockRecordEntry,
EntitiesManager,
Handle,
Seeder,
TagsManager,
point,
} from "@/index";

describe("EntitiesManager class", () => {
const handle = new Handle();
const br = new BlockRecordEntry({ name: "*Model_Space" }, handle);
const seeder = new Seeder();
const blockRecord = new BlockRecordEntry({ name: "*Model_Space", seeder });
it("should create an empty varaible", () => {
const mg = new EntitiesManager(br, handle);
const mg = new EntitiesManager({ blockRecord, seeder });
const m = new TagsManager();
mg.tagify(m);
expect(m.stringify()).toBe("");
});

it("should be able to add a line entity", () => {
const mg = new EntitiesManager(br, handle);
const mg = new EntitiesManager({ blockRecord, seeder });
mg.addLine({
start: point(),
end: point(100, 100),
Expand Down
22 changes: 11 additions & 11 deletions __tests__/entities/polyline.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Handle, TagsManager } from "@/utils";
import { Polyline, PolylineFlags, VertexFlags } from "@/entities";
import { Seeder, TagsManager } from "@/utils";

const polyfaceVertices = [
[0, 0, 0],
Expand Down Expand Up @@ -38,11 +38,11 @@ const polyline3DVertices = [
describe("Polyline class", () => {
it("should cover the polyline entity", () => {
const mg = new TagsManager();
const handle = new Handle();
const polyface = new Polyline(
{ flags: PolylineFlags.PolyfaceMesh },
handle
);
const seeder = new Seeder();
const polyface = new Polyline({
flags: PolylineFlags.PolyfaceMesh,
seeder,
});

const vertexFlags =
VertexFlags.PolyfaceMeshVertex | VertexFlags.Polyline3DMesh;
Expand All @@ -62,18 +62,18 @@ describe("Polyline class", () => {

polyface.tagify(mg);

const polyline2D = new Polyline({}, handle);
const polyline2D = new Polyline({ seeder });
polyline2DVertices.forEach((vertex) => {
const [x, y, z] = vertex;
polyline2D.add({ x, y, z });
});

polyline2D.tagify(mg);

const polyline3D = new Polyline(
{ flags: PolylineFlags.Polyline3D },
handle
);
const polyline3D = new Polyline({
flags: PolylineFlags.Polyline3D,
seeder,
});
polyline3DVertices.forEach((vertex) => {
const [x, y, z] = vertex;
polyline3D.add({ x, y, z, flags: VertexFlags.Polyline3DVertex });
Expand Down
4 changes: 2 additions & 2 deletions __tests__/header/__snapshots__/header.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`XHeader class > should be able to add a variable 1`] = `
exports[`Header class > should be able to add a variable 1`] = `
"0
SECTION
2
Expand All @@ -21,7 +21,7 @@ $ANGDIR
ENDSEC"
`;

exports[`XHeader class > should create a header section with defaults 1`] = `
exports[`Header class > should create a header section with defaults 1`] = `
"0
SECTION
2
Expand Down
Loading

0 comments on commit c342226

Please sign in to comment.