This repository has been archived by the owner on May 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
3,635 additions
and
81 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,241 @@ | ||
import { | ||
CopyrightHeaderOptions, | ||
CopyrightHeaderStatus, | ||
getUpdatedCopyrightHeader, | ||
php, | ||
phtml | ||
} from '../src' | ||
|
||
describe('php', () => { | ||
const options: CopyrightHeaderOptions = { | ||
lines: [ | ||
'This file is part of @splish-me/copyright-headers', | ||
'', | ||
'Copyright (c) 2018 Splish UG (haftungsbeschränkt)' | ||
] | ||
} | ||
|
||
test('does not start with <?php', () => { | ||
const input = `` | ||
const [status, output] = getUpdatedCopyrightHeader(input, php, options) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Added) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
`) | ||
}) | ||
|
||
test('does start with <?php', () => { | ||
const input = `<?php | ||
echo "foo bar"; | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, php, options) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Added) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
echo "foo bar"; | ||
`) | ||
}) | ||
|
||
test('existing copyright header', () => { | ||
const input = `<?php | ||
/** | ||
* Copyright (c) 2016 Splish UG (haftungsbeschränkt) | ||
*/ | ||
echo "foo bar"; | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, php, { | ||
...options, | ||
shouldUpdate: () => true | ||
}) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Changed) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
echo "foo bar"; | ||
`) | ||
}) | ||
|
||
test('existing external copyright header', () => { | ||
const input = `<?php | ||
/** | ||
* Copyright (c) 2016 Max Mustermann Corporation | ||
*/ | ||
echo "foo bar"; | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, php, { | ||
...options, | ||
shouldUpdate: () => false | ||
}) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.External) | ||
expect(output).toEqual(input) | ||
}) | ||
|
||
test('multiple copyright headers', () => { | ||
const input = `<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2016 Splish UG (haftungsbeschränkt) | ||
*/ | ||
/** | ||
* Copyright (c) 2016 Max Mustermann Corporation | ||
*/ | ||
echo "foo bar"; | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, php, { | ||
...options, | ||
shouldUpdate: () => true | ||
}) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Changed) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
/** | ||
* Copyright (c) 2016 Max Mustermann Corporation | ||
*/ | ||
echo "foo bar"; | ||
`) | ||
}) | ||
}) | ||
|
||
describe('phtml', () => { | ||
const options: CopyrightHeaderOptions = { | ||
lines: [ | ||
'This file is part of @splish-me/copyright-headers', | ||
'', | ||
'Copyright (c) 2018 Splish UG (haftungsbeschränkt)' | ||
] | ||
} | ||
|
||
test('does not start with <?php', () => { | ||
const input = `` | ||
const [status, output] = getUpdatedCopyrightHeader(input, phtml, options) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Added) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
?> | ||
`) | ||
}) | ||
|
||
test('does start with <?php', () => { | ||
const input = `<?php | ||
echo "foo bar"; | ||
?> | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, phtml, options) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Added) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
echo "foo bar"; | ||
?> | ||
`) | ||
}) | ||
|
||
test('existing copyright header', () => { | ||
const input = `<?php | ||
/** | ||
* Copyright (c) 2016 Splish UG (haftungsbeschränkt) | ||
*/ | ||
echo "foo bar"; | ||
?> | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, phtml, { | ||
...options, | ||
shouldUpdate: () => true | ||
}) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Changed) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
echo "foo bar"; | ||
?> | ||
`) | ||
}) | ||
|
||
test('existing external copyright header', () => { | ||
const input = `<?php | ||
/** | ||
* Copyright (c) 2016 Max Mustermann Corporation | ||
*/ | ||
echo "foo bar"; | ||
?> | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, phtml, { | ||
...options, | ||
shouldUpdate: () => false | ||
}) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.External) | ||
expect(output).toEqual(input) | ||
}) | ||
|
||
test('multiple copyright headers', () => { | ||
const input = `<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2016 Splish UG (haftungsbeschränkt) | ||
*/ | ||
/** | ||
* Copyright (c) 2016 Max Mustermann Corporation | ||
*/ | ||
echo "foo bar"; | ||
?> | ||
` | ||
const [status, output] = getUpdatedCopyrightHeader(input, php, { | ||
...options, | ||
shouldUpdate: () => true | ||
}) | ||
|
||
expect(status).toEqual(CopyrightHeaderStatus.Changed) | ||
expect(output).toEqual(`<?php | ||
/** | ||
* This file is part of @splish-me/copyright-headers | ||
* | ||
* Copyright (c) 2018 Splish UG (haftungsbeschränkt) | ||
*/ | ||
/** | ||
* Copyright (c) 2016 Max Mustermann Corporation | ||
*/ | ||
echo "foo bar"; | ||
?> | ||
`) | ||
}) | ||
}) |
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,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node' | ||
} |
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
Oops, something went wrong.