Skip to content

Commit

Permalink
Tests: Stricter pattern for nice-token-names test (#2588)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Nov 4, 2020
1 parent 25bdb49 commit 0df60be
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions components/prism-elm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Prism.languages.elm = {
comment: /--.*|{-[\s\S]*?-}/,
char: {
'comment': /--.*|{-[\s\S]*?-}/,
'char': {
pattern: /'(?:[^\\'\r\n]|\\(?:[abfnrtv\\']|\d+|x[0-9a-fA-F]+))'/,
greedy: true
},
string: [
'string': [
{
// Multiline strings are wrapped in triple ". Quotes may appear unescaped.
pattern: /"""[\s\S]*?"""/,
Expand All @@ -15,30 +15,30 @@ Prism.languages.elm = {
greedy: true
}
],
import_statement: {
'import-statement': {
// The imported or hidden names are not included in this import
// statement. This is because we want to highlight those exactly like
// we do for the names in the program.
pattern: /^\s*import\s+[A-Z]\w*(?:\.[A-Z]\w*)*(?:\s+as\s+(?:[A-Z]\w*)(?:\.[A-Z]\w*)*)?(?:\s+exposing\s+)?/m,
inside: {
keyword: /\b(?:import|as|exposing)\b/
'keyword': /\b(?:import|as|exposing)\b/
}
},
keyword: /\b(?:alias|as|case|else|exposing|if|in|infixl|infixr|let|module|of|then|type)\b/,
'keyword': /\b(?:alias|as|case|else|exposing|if|in|infixl|infixr|let|module|of|then|type)\b/,
// These are builtin variables only. Constructors are highlighted later as a constant.
builtin: /\b(?:abs|acos|always|asin|atan|atan2|ceiling|clamp|compare|cos|curry|degrees|e|flip|floor|fromPolar|identity|isInfinite|isNaN|logBase|max|min|negate|never|not|pi|radians|rem|round|sin|sqrt|tan|toFloat|toPolar|toString|truncate|turns|uncurry|xor)\b/,
'builtin': /\b(?:abs|acos|always|asin|atan|atan2|ceiling|clamp|compare|cos|curry|degrees|e|flip|floor|fromPolar|identity|isInfinite|isNaN|logBase|max|min|negate|never|not|pi|radians|rem|round|sin|sqrt|tan|toFloat|toPolar|toString|truncate|turns|uncurry|xor)\b/,
// decimal integers and floating point numbers | hexadecimal integers
number: /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0x[0-9a-f]+)\b/i,
'number': /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0x[0-9a-f]+)\b/i,
// Most of this is needed because of the meaning of a single '.'.
// If it stands alone freely, it is the function composition.
// It may also be a separator between a module name and an identifier => no
// operator. If it comes together with other special characters it is an
// operator too.
// Valid operator characters in 0.18: +-/*=.$<>:&|^?%#@~!
// Ref: https://groups.google.com/forum/#!msg/elm-dev/0AHSnDdkSkQ/E0SVU70JEQAJ
operator: /\s\.\s|[+\-/*=.$<>:&|^?%#@~!]{2,}|[+\-/*=$<>:&|^?%#@~!]/,
'operator': /\s\.\s|[+\-/*=.$<>:&|^?%#@~!]{2,}|[+\-/*=$<>:&|^?%#@~!]/,
// In Elm, nearly everything is a variable, do not highlight these.
hvariable: /\b(?:[A-Z]\w*\.)*[a-z]\w*\b/,
constant: /\b(?:[A-Z]\w*\.)*[A-Z]\w*\b/,
punctuation: /[{}[\]|(),.:]/
'hvariable': /\b(?:[A-Z]\w*\.)*[a-z]\w*\b/,
'constant': /\b(?:[A-Z]\w*\.)*[A-Z]\w*\b/,
'punctuation': /[{}[\]|(),.:]/
};
2 changes: 1 addition & 1 deletion components/prism-elm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/prism-git.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ Prism.languages.git = {
*
* Add of a new line
*/
'commit_sha1': /^commit \w{40}$/m
'commit-sha1': /^commit \w{40}$/m
};
2 changes: 1 addition & 1 deletion components/prism-git.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/prism-ocaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Prism.languages.ocaml = {
pattern: /\B~\w+/,
alias: 'function'
},
'type_variable': {
'type-variable': {
pattern: /\B'\w+/,
alias: 'function'
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-ocaml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ import Json.Decode as Json exposing (Decoder)
----------------------------------------------------

[
["import_statement", [
["import-statement", [
["keyword", "import"],
" Foo"
]],
["import_statement", [
["import-statement", [
["keyword", "import"],
" Foo_42.Bar ",
["keyword", "as"],
" Foobar"
]],
["import_statement", [
["import-statement", [
["keyword", "import"],
" Foo.Bar ",
["keyword", "as"],
" Foo.Baz"
]],
["import_statement", [
["import-statement", [
["keyword", "import"],
" List ",
["keyword", "exposing"]
]],
["punctuation", "("],
["hvariable", "map"],
["punctuation", ")"],
["import_statement", [
["import-statement", [
["keyword", "import"],
" Json.Decode ",
["keyword", "as"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ commit 3102416a90c431400d2e2a14e707fb7fd6d9e06d
----------------------------------------------------

[
["commit_sha1", "commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09"],
["commit_sha1", "commit 87edc4ad8c71b95f6e46f736eb98b742859abd95"],
["commit_sha1", "commit 3102416a90c431400d2e2a14e707fb7fd6d9e06d"]
["commit-sha1", "commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09"],
["commit-sha1", "commit 87edc4ad8c71b95f6e46f736eb98b742859abd95"],
["commit-sha1", "commit 3102416a90c431400d2e2a14e707fb7fd6d9e06d"]
]

----------------------------------------------------

Checks for commit SHA1.
Checks for commit SHA1.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
----------------------------------------------------

[
["type_variable", "'Foo"],
["type_variable", "'bar_42"]
["type-variable", "'Foo"],
["type-variable", "'bar_42"]
]

----------------------------------------------------

Checks for type variables.
Checks for type variables.
2 changes: 1 addition & 1 deletion tests/pattern-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function testPatterns(Prism) {
});

it('- should have nice names and aliases', function () {
const niceName = /^[a-z][a-z\d]*(?:[-_][a-z\d]+)*$/;
const niceName = /^[a-z][a-z\d]*(?:-[a-z\d]+)*$/;
function testName(name, desc = 'token name') {
if (!niceName.test(name)) {
assert.fail(`The ${desc} '${name}' does not match ${niceName}.\n\n`
Expand Down

0 comments on commit 0df60be

Please sign in to comment.