-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #233 unable to insert |image_has_rationale=yes when {{Non-free X}…
…} template already has parameters
- Loading branch information
1 parent
2cba1e1
commit 0cf6896
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
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,8 @@ | ||
{ | ||
"dependencies": { | ||
"jest": "^27.4.2" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} |
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,29 @@ | ||
/* eslint-disable quotes */ | ||
|
||
function insertImageHasRationaleYes( wikicode ) { | ||
return wikicode.replace( /({{Non-free (?!use)[^|}]+)([|}])/i, '$1|image_has_rationale=yes$2' ); | ||
} | ||
|
||
test( `should touch {{Non-free X}}`, () => { | ||
const wikitext = `{{Non-free biog-pic}}`; | ||
const output = `{{Non-free biog-pic|image_has_rationale=yes}}`; | ||
expect( insertImageHasRationaleYes( wikitext ) ).toBe( output ); | ||
} ); | ||
|
||
test( `shouldn't touch {{Non-free use rationale X}}`, () => { | ||
const wikitext = | ||
`{{Non-free use rationale 2 | ||
|Description = This is a photo of Harry Conover | ||
}}`; | ||
const output = | ||
`{{Non-free use rationale 2 | ||
|Description = This is a photo of Harry Conover | ||
}}`; | ||
expect( insertImageHasRationaleYes( wikitext ) ).toBe( output ); | ||
} ); | ||
|
||
test( `should handle {{Non-free X}} with parameters`, () => { | ||
const wikitext = `{{Non-free biog-pic|Harry Conover|year=1944}}`; | ||
const output = `{{Non-free biog-pic|image_has_rationale=yes|Harry Conover|year=1944}}`; | ||
expect( insertImageHasRationaleYes( wikitext ) ).toBe( output ); | ||
} ); |