-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Git] Add of some jasmine tests #355
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,81 @@ | ||
Prism.languages.git = { | ||
/* | ||
* A simple one line comment like in a git status command | ||
* For instance: | ||
* $ git status | ||
* # On branch infinite-scroll | ||
* # Your branch and 'origin/sharedBranches/frontendTeam/infinite-scroll' have diverged, | ||
* # and have 1 and 2 different commits each, respectively. | ||
* nothing to commit (working directory clean) | ||
*/ | ||
'comment': /^#.*$/m, | ||
|
||
/* | ||
* a string (double and simple quote) | ||
*/ | ||
'string': /("|')(\\?.)*?\1/gm, | ||
|
||
/* | ||
* a git command. It starts with a random prompt finishing by a $, then "git" then some other parameters | ||
* For instance: | ||
* $ git add file.txt | ||
*/ | ||
'command': { | ||
pattern: /^.*\$ git .*$/m, | ||
(function() { | ||
// Exact copy of string token from prism-bash.js | ||
var string_regexp = { | ||
//allow multiline string | ||
pattern: /("|')(\\?[\s\S])*?\1/g, | ||
inside: { | ||
/* | ||
* A git command can contain a parameter starting by a single or a double dash followed by a string | ||
* For instance: | ||
* $ git diff --cached | ||
* $ git log -p | ||
*/ | ||
'parameter': /\s(--|-)\w+/m | ||
//'property' class reused for bash variables | ||
'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^\}]+\})/g | ||
} | ||
}, | ||
}; | ||
|
||
Prism.languages.git = { | ||
/* | ||
* A simple one line comment like in a git status command | ||
* For instance: | ||
* $ git status | ||
* # On branch infinite-scroll | ||
* # Your branch and 'origin/sharedBranches/frontendTeam/infinite-scroll' have diverged, | ||
* # and have 1 and 2 different commits each, respectively. | ||
* nothing to commit (working directory clean) | ||
*/ | ||
comment: /^#.*$/m, | ||
|
||
/* | ||
* a git command. It starts with a random prompt finishing by a $, then "git" then some other parameters | ||
* For instance: | ||
* $ git add file.txt | ||
*/ | ||
command: { | ||
pattern: /^.*\$ git .*$/m, | ||
inside: { | ||
/* | ||
* A git command can contain a parameter starting by a single or a double dash followed by a string | ||
* For instance: | ||
* $ git diff --cached | ||
* $ git log -p | ||
*/ | ||
'string': string_regexp, | ||
'parameter': /\s(--|-)\w+/m | ||
} | ||
}, | ||
|
||
/* | ||
* Coordinates displayed in a git diff command | ||
* For instance: | ||
* $ git diff | ||
* diff --git file.txt file.txt | ||
* index 6214953..1d54a52 100644 | ||
* --- file.txt | ||
* +++ file.txt | ||
* @@ -1 +1,2 @@ | ||
* -Here's my tetx file | ||
* +Here's my text file | ||
* +And this is the second line | ||
*/ | ||
coord: /^@@.*@@$/m, | ||
|
||
/* | ||
* Coordinates displayed in a git diff command | ||
* For instance: | ||
* $ git diff | ||
* diff --git file.txt file.txt | ||
* index 6214953..1d54a52 100644 | ||
* --- file.txt | ||
* +++ file.txt | ||
* @@ -1 +1,2 @@ | ||
* -Here's my tetx file | ||
* +Here's my text file | ||
* +And this is the second line | ||
*/ | ||
'coord': /^@@.*@@$/m, | ||
/* | ||
* Regexp to match the changed lines in a git diff output. Check the example above. | ||
*/ | ||
'deleted': /^-(?!-).+$/m, | ||
'inserted': /^\+(?!\+).+$/m, | ||
|
||
/* | ||
* Regexp to match the changed lines in a git diff output. Check the example above. | ||
*/ | ||
'deleted': /^-(?!-).+$/m, | ||
'inserted': /^\+(?!\+).+$/m, | ||
/* | ||
* a string (double and simple quote) | ||
*/ | ||
string: string_regexp, | ||
|
||
/* | ||
* Match a "commit [SHA1]" line in a git log output. | ||
* For instance: | ||
* $ git log | ||
* commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09 | ||
* Author: lgiraudel | ||
* Date: Mon Feb 17 11:18:34 2014 +0100 | ||
* | ||
* Add of a new line | ||
*/ | ||
'commit_sha1': /^commit \w{40}$/m | ||
}; | ||
/* | ||
* Match a "commit [SHA1]" line in a git log output. | ||
* For instance: | ||
* $ git log | ||
* commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09 | ||
* Author: lgiraudel | ||
* Date: Mon Feb 17 11:18:34 2014 +0100 | ||
* | ||
* Add of a new line | ||
*/ | ||
'commit_sha1': /^commit \w{40}$/m | ||
}; | ||
}()); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
Prism = require('../../prism'); | ||
require('../../components/prism-git'); | ||
|
||
describe('Prism-Git tests', function() { | ||
it('parses git commands', function() { | ||
var input = '$ git config --global core.editor "~/Sublime\ Text\ 3/sublime_text -w"'; | ||
|
||
var res = Prism.highlight(input, Prism.languages.git); | ||
|
||
expect(res).toBe('<span class="token command" >$ git config<span class="token parameter" > --global</span> core.editor <span class="token string" >"~/Sublime Text 3/sublime_text -w"</span></span>'); | ||
}); | ||
|
||
|
||
it('parses git comments', function() { | ||
var input = | ||
"$ git status\n" + | ||
"# On branch infinite-scroll\n" + | ||
"# Your branch and 'origin/sharedBranches/frontendTeam/infinite-scroll' have diverged,\n" + | ||
"# and have 1 and 2 different commits each, respectively.\n" + | ||
"nothing to commit (working directory clean)"; | ||
|
||
var res = Prism.highlight(input, Prism.languages.git); | ||
|
||
expect(res).toBe( | ||
'<span class="token command" >$ git status</span>\n' + | ||
'<span class="token comment" spellcheck="true"># On branch infinite-scroll</span>\n' + | ||
'<span class="token comment" spellcheck="true"># Your branch and \'origin/sharedBranches/frontendTeam/infinite-scroll\' have diverged,</span>\n' + | ||
'<span class="token comment" spellcheck="true"># and have 1 and 2 different commits each, respectively.</span>\n' + | ||
'nothing to commit (working directory clean)'); | ||
}); | ||
|
||
it('parses diff', function() { | ||
var input = | ||
"$ git diff\n" + | ||
"diff --git file.txt file.txt\n" + | ||
"index 6214953..1d54a52 100644\n" + | ||
"--- file.txt\n" + | ||
"+++ file.txt\n" + | ||
"@@ -1 +1,2 @@\n" + | ||
"-Here's my tetx file\n" + | ||
"+Here's my text file\n" + | ||
"+And this is the second line"; | ||
|
||
var res = Prism.highlight(input, Prism.languages.git); | ||
|
||
expect(res).toBe( | ||
'<span class="token command" >$ git diff</span>\n' + | ||
'diff --git file.txt file.txt\n' + | ||
'index 6214953..1d54a52 100644\n' + | ||
'--- file.txt\n' + | ||
'+++ file.txt\n' + | ||
'<span class="token coord" >@@ -1 +1,2 @@</span>\n' + | ||
'<span class="token deleted" >-Here\'s my tetx file</span>\n' + | ||
'<span class="token inserted" >+Here\'s my text file</span>\n' + | ||
'<span class="token inserted" >+And this is the second line</span>'); | ||
}); | ||
|
||
it('parses a commit SHA1 (40 char)', function() { | ||
var input = | ||
"$ git log\n" + | ||
"commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09\n" + | ||
"Author: lgiraudel\n" + | ||
"Date: Mon Feb 17 11:18:34 2014 +0100\n" + | ||
"\n" + | ||
" Add of a new line\n" + | ||
"\n" + | ||
"commit 87edc4ad8c71b95f6e46f736eb98b742859abd95\n" + | ||
"Author: lgiraudel\n" + | ||
"Date: Mon Feb 17 11:18:15 2014 +0100\n" + | ||
"\n" + | ||
" Typo fix\n" + | ||
"\n" + | ||
"commit 3102416a90c431400d2e2a14e707fb7fd6d9e06d\n" + | ||
"Author: lgiraudel\n" + | ||
"Date: Mon Feb 17 10:58:11 2014 +0100\n" + | ||
"\n" + | ||
" Initial commit"; | ||
|
||
var res = Prism.highlight(input, Prism.languages.git); | ||
|
||
expect(res).toBe( | ||
'<span class="token command" >$ git log</span>\n' + | ||
'<span class="token commit_sha1" >commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09</span>\n' + | ||
'Author: lgiraudel\n' + | ||
'Date: Mon Feb 17 11:18:34 2014 +0100\n' + | ||
'\n' + | ||
' Add of a new line\n' + | ||
'\n' + | ||
'<span class="token commit_sha1" >commit 87edc4ad8c71b95f6e46f736eb98b742859abd95</span>\n' + | ||
'Author: lgiraudel\n' + | ||
'Date: Mon Feb 17 11:18:15 2014 +0100\n' + | ||
'\n' + | ||
' Typo fix\n' + | ||
'\n' + | ||
'<span class="token commit_sha1" >commit 3102416a90c431400d2e2a14e707fb7fd6d9e06d</span>\n' + | ||
'Author: lgiraudel\n' + | ||
'Date: Mon Feb 17 10:58:11 2014 +0100\n' + | ||
'\n' + | ||
' Initial commit'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be nicer to pass the global Prism variable here?
And add it as an argument for the anonymous function?
This way, you would have a fixed and static dependency on
Prism
.