Skip to content

Commit 200a5e2

Browse files
committed
refactor: utilize withDisposable for resource management in tests
1 parent d659ff1 commit 200a5e2

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/libexif/ExifEntry.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe("ExifEntry", () => {
3737
expect(exifEntry).toHaveProperty("format", "ASCII");
3838
expect(exifEntry).toHaveProperty("tag", "MAKE");
3939
expect(exifEntry.toString()).toBe("");
40-
exifEntry.free();
4140
});
4241
test("should return ASCII value", () => {
4342
const EXPECTED_ASCII_VALUE = "Canon";

src/libexif/ExifMnoteData.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { describe, expect, test } from "vitest";
33
import { ExifData } from "./ExifData.ts";
44
import { ExifMnoteData } from "./ExifMnoteData.ts";
55
import { getTestFixture } from "../__utils__/getTestFixture.ts";
6+
import { withDisposable } from "../__utils__/withDisposable.ts";
67

78
describe("ExifMnoteData", () => {
89
describe.each(["Sumo_Museum.jpg"])(
910
"ExifData.newFromData(%s).getMnoteData()",
1011
(testFixtureFile) => {
1112
test("should create a new ExifMnoteData instance from data", async () => {
1213
const testFixture = await getTestFixture(testFixtureFile);
13-
const exifData = ExifData.newFromData(testFixture.buffer);
14+
const exifData = withDisposable(
15+
ExifData.newFromData(testFixture.buffer),
16+
);
1417
const mnoteData = exifData.mnoteData;
1518
expect(mnoteData).not.toBeNull();
1619
expect(mnoteData).toBeInstanceOf(ExifMnoteData);
@@ -29,8 +32,6 @@ describe("ExifMnoteData", () => {
2932
);
3033
expect(mnoteData?.getValue(index)).toBe(exifMnoteEntry.value);
3134
});
32-
33-
exifData.free();
3435
});
3536
},
3637
);

src/libexif/exifUtils.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import {
1111
ExifRational,
1212
ExifSRational,
1313
} from "./exifUtils.ts";
14+
import { withDisposable } from "../__utils__/withDisposable.ts";
1415
import { HEAPU8 } from "../internal/emscripten.ts";
1516
import { malloc } from "../internal/stdlib.ts";
1617

1718
describe("ExifRational", () => {
1819
test("setters and getters work correctly", () => {
1920
const rationalPtr = malloc(exifFormatGetSize("RATIONAL"));
20-
const exifRational = new ExifRational(rationalPtr);
21+
const exifRational = withDisposable(new ExifRational(rationalPtr));
2122
exifRational.numerator = 355;
2223
exifRational.denominator = 113;
2324
expect(exifRational).toHaveProperty("numerator", 355);
@@ -28,14 +29,13 @@ describe("ExifRational", () => {
2829
.buffer,
2930
),
3031
).toEqual(new Uint32Array([355, 113]));
31-
exifRational.free();
3232
});
3333
});
3434

3535
describe("ExifSRational", () => {
3636
test("setters and getters work correctly", () => {
3737
const sRationalPtr = malloc(exifFormatGetSize("SRATIONAL"));
38-
const exifSRational = new ExifSRational(sRationalPtr);
38+
const exifSRational = withDisposable(new ExifSRational(sRationalPtr));
3939
exifSRational.numerator = -2147483648;
4040
exifSRational.denominator = 524288;
4141
expect(exifSRational).toHaveProperty("numerator", -2147483648);
@@ -48,7 +48,6 @@ describe("ExifSRational", () => {
4848
).buffer,
4949
),
5050
).toEqual(new Int32Array([-2147483648, 524288]));
51-
exifSRational.free();
5251
});
5352
});
5453

@@ -190,10 +189,9 @@ describe("exifGetRational", () => {
190189
it.each(EXIF_RATIONAL_TABLE)(
191190
"should return the correct value for buffer $buffer and order $order",
192191
({ buffer, order, expected }) => {
193-
const rational = exifGetRational(buffer, order);
192+
const rational = withDisposable(exifGetRational(buffer, order));
194193
expect(rational.numerator).toEqual(expected.numerator);
195194
expect(rational.denominator).toEqual(expected.denominator);
196-
rational.free();
197195
},
198196
);
199197
});
@@ -220,10 +218,9 @@ describe("exifGetSRational", () => {
220218
it.each(EXIF_SRATIONAL_TABLE)(
221219
"should return the correct value for buffer $buffer and order $order",
222220
({ buffer, order, expected }) => {
223-
const sRational = exifGetSRational(buffer, order);
221+
const sRational = withDisposable(exifGetSRational(buffer, order));
224222
expect(sRational.numerator).toEqual(expected.numerator);
225223
expect(sRational.denominator).toEqual(expected.denominator);
226-
sRational.free();
227224
},
228225
);
229226
});

0 commit comments

Comments
 (0)