-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
2,200 additions
and
1,885 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function (code) { | ||
// Very simple, trivial extractor for the purposes of testing | ||
const keys = []; | ||
const lines = code.split(/\r?\n/); | ||
for (let i = 0; i < lines.length; i++) { | ||
for (const [str] of lines[i].matchAll(/STR_[A-Z_]+/g)) { | ||
keys.push({ keyName: str, line: i + 1 }); | ||
} | ||
} | ||
|
||
return { | ||
keys, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ExtractionResult, ExtractedKey } from '#cli/extractor/index.js'; | ||
|
||
export default function (code: string): ExtractionResult { | ||
// Very simple, trivial extractor for the purposes of testing | ||
const keys: ExtractedKey[] = []; | ||
const lines = code.split(/\r?\n/); | ||
for (let i = 0; i < lines.length; i++) { | ||
for (const [str] of lines[i].matchAll(/STR_[A-Z_]+/g)) { | ||
keys.push({ keyName: str, line: i + 1 }); | ||
} | ||
} | ||
|
||
return { | ||
keys, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Hey this is a very STR_CRUDE test | ||
to see if the custom extractors are STR_WORKING | ||
properly. | ||
|
||
Hopefully, this will catch any STR_NEW | ||
issue that may happen before it makes its | ||
way to STR_PRODUCTION! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fileURLToPathSlash } from './utils/toFilePath.js'; | ||
import { run } from './utils/run.js'; | ||
|
||
const FIXTURES_PATH = new URL('../__fixtures__/', import.meta.url); | ||
const FAKE_PROJECT = new URL('./customExtractors/', FIXTURES_PATH); | ||
const TEST_FILE = fileURLToPathSlash(new URL('./testfile.txt', FAKE_PROJECT)); | ||
const JS_EXTRACTOR = fileURLToPathSlash( | ||
new URL('./extract-js.js', FAKE_PROJECT) | ||
); | ||
const TS_EXTRACTOR = fileURLToPathSlash( | ||
new URL('./extract-ts.ts', FAKE_PROJECT) | ||
); | ||
|
||
it('successfully uses a custom extractor written in JS', async () => { | ||
const out = await run( | ||
['extract', 'print', '--extractor', JS_EXTRACTOR, '--patterns', TEST_FILE], | ||
undefined, | ||
50e3 | ||
); | ||
|
||
expect(out.code).toBe(0); | ||
expect(out.stdout).toContain('STR_CRUDE'); | ||
expect(out.stdout).toContain('STR_WORKING'); | ||
expect(out.stdout).toContain('STR_NEW'); | ||
expect(out.stdout).toContain('STR_PRODUCTION'); | ||
}, 60e3); | ||
|
||
it('successfully uses a custom extractor written in TS', async () => { | ||
const out = await run( | ||
['extract', 'print', '--extractor', TS_EXTRACTOR, '--patterns', TEST_FILE], | ||
undefined, | ||
50e3 | ||
); | ||
|
||
expect(out.code).toBe(0); | ||
expect(out.stdout).toContain('STR_CRUDE'); | ||
expect(out.stdout).toContain('STR_WORKING'); | ||
expect(out.stdout).toContain('STR_NEW'); | ||
expect(out.stdout).toContain('STR_PRODUCTION'); | ||
}, 60e3); |