Skip to content

Commit 4c7e7c8

Browse files
committed
Add unit tests for PHP comment parsing in parsePHPFile
1 parent f499633 commit 4c7e7c8

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

tests/parse-php.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { describe, it } = require("node:test");
2+
const assert = require("node:assert");
3+
const { parsePHPFile } = require("../lib/extractors/php.js");
4+
5+
describe("parsePHPFile", () => {
6+
it("correctly extracts headers from standard docblock (/** ... */)", () => {
7+
const phpContent = `<?php
8+
/**
9+
* Plugin Name: My Plugin
10+
* Description: A basic WordPress plugin template with translation support.
11+
* Version: 1.0
12+
* Author: Your Name
13+
* Text Domain: my-plugin
14+
* Domain Path: /languages
15+
*/`;
16+
const result = parsePHPFile(phpContent);
17+
assert.deepStrictEqual(result, {
18+
name: "My Plugin",
19+
description: "A basic WordPress plugin template with translation support.",
20+
version: "1.0",
21+
author: "Your Name",
22+
textDomain: "my-plugin",
23+
domainPath: "/languages",
24+
});
25+
});
26+
27+
it("correctly extracts headers from simple comment block (/* ... */)", () => {
28+
const phpContent = `<?php
29+
/*
30+
Plugin Name: My Plugin
31+
Description: A basic WordPress plugin template with translation support.
32+
Version: 1.0
33+
Author: Your Name
34+
Text Domain: my-plugin
35+
Domain Path: /languages
36+
*/`;
37+
const result = parsePHPFile(phpContent);
38+
assert.deepStrictEqual(result, {
39+
name: "My Plugin",
40+
description: "A basic WordPress plugin template with translation support.",
41+
version: "1.0",
42+
author: "Your Name",
43+
textDomain: "my-plugin",
44+
domainPath: "/languages",
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)