Files
RedBear-OS/local/recipes/kde/kf6-syntaxhighlighting/source/autotests/folding/highlight.js.fold
T

263 lines
8.0 KiB
Plaintext

#! shebang
#! no-shebang
<beginfold id='1'>/*</beginfold id='1'> comment <endfold id='1'>*/</endfold id='1'>
function fun()
<beginfold id='2'>{</beginfold id='2'>
var boo = <beginfold id='2'>{</beginfold id='2'> 'key': <beginfold id='3'>[</beginfold id='3'> 1, 2.0, 3.0e1, 004, 0x5 <endfold id='3'>]</endfold id='3'> <endfold id='2'>}</endfold id='2'>;
<endfold id='2'>}</endfold id='2'>
class MyClass; // reserved keywords
class ClassWithPrivateField <beginfold id='2'>{</beginfold id='2'>
static #privateStaticField = 42;
static publicStaticMethod() <beginfold id='2'>{</beginfold id='2'>
return ClassWithPrivateField.#privateStaticField;
<endfold id='2'>}</endfold id='2'>
#message;
#privateMethod() <beginfold id='2'>{</beginfold id='2'>
return 42;
<endfold id='2'>}</endfold id='2'>
publicMethod() <beginfold id='2'>{</beginfold id='2'>
return this.#privateMethod();
<endfold id='2'>}</endfold id='2'>
get #decoratedMessage() <beginfold id='2'>{</beginfold id='2'>
return this.#message
<endfold id='2'>}</endfold id='2'>
set #decoratedMessage(msg) <beginfold id='2'>{</beginfold id='2'>
this.#message = msg;
<endfold id='2'>}</endfold id='2'>
<endfold id='2'>}</endfold id='2'>
// Member objects: text after "."
object.property instanceof Number;
iden1.iden2 . iden3.class class;
iden1?.iden2 . iden3.class class;
iden1.#iden2 . iden3.class class;
var escapes = "aa\b\n\0a\"a\x12a\32a\u{123}a\$\%\ \#\y\aaa\
aaa";
var octal = 0o124;
var bin = 0b1010;
日本語().ლಠ益ಠლ.ñá = 42;
δ /No-Regex/
// Only highlight valid regular expressions, of a single line, after strings
// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786
"text" /No-Regex
"text" /Regex[:)]*/;
const a = "6" / 2; <beginfold id='1'>/*</beginfold id='1'>comment<endfold id='1'>*/</endfold id='1'> const b = 5;
console.log("4" / "2"); // 2
// Single quote
const a = '6' / 2; <beginfold id='1'>/*</beginfold id='1'>comment<endfold id='1'>*/</endfold id='1'> const b = 5;
console.log('4' / '2'); // 2
// Template
const a = <beginfold id='4'>`</beginfold id='4'>6<endfold id='4'>`</endfold id='4'> / 2; <beginfold id='1'>/*</beginfold id='1'>comment<endfold id='1'>*/</endfold id='1'> const b = 5;
console.log(<beginfold id='4'>`</beginfold id='4'>4<endfold id='4'>`</endfold id='4'> / <beginfold id='4'>`</beginfold id='4'>2<endfold id='4'>`</endfold id='4'>); // 2
// Built-in
const os = require('os');
JSON.stringify("hello");
console.error("hello");
Math.LOG10E;
Number.MAX_SAFE_INTEGER;
String.raw<beginfold id='4'>`</beginfold id='4'>raw text \.\n${}<endfold id='4'>`</endfold id='4'>
// Tagged template literals
tagFunc<beginfold id='4'>`</beginfold id='4'>
Hello world!
${ alert("Hello!"); }<endfold id='4'>`</endfold id='4'>;
obj.something.tagFunc<beginfold id='4'>`</beginfold id='4'>Setting ${setting} is ${value + 5}!<endfold id='4'>`</endfold id='4'>;
<beginfold id='1'>/*</beginfold id='1'>
NOTE: The words "todo", "fixme" and "note" should be rendered in a different style
within comments, match should be caseless (to test for regexp insensitive attribute).
The regex used for this rule is <endfold id='1'>*/</endfold id='1'>
String = /\b(?:fixme|todo|note)\b/
<beginfold id='1'>/*</beginfold id='1'> Thus, for example "Notebook" is not caught by
this rule. (the "?:" in the subpattern is there to avoid the regex engine wasting time
saving a backref, which is not used for anything. I do not know if the overhead of parsing
that is greater than the time saved by not capturing the text...)
The rule for catching these words is placed in a context "Comment common", which is used
by both comment contexts (single line, multiline) using the new "IncludeRules" item.
<endfold id='1'>*/</endfold id='1'>
// test if regex support works - nice with new fallthrough prop in context:)
somestring.replace( /dooh/ , "bah!");
re=/foo/ig; // hehe
somestring.search(
/^foo\w+\s\d{0,15}$/
);
re =
/dooh/;
// This is supposedly legal:
re = somebool ? /foo/ : /bar/;
// NOTE - Special case: an empty regex, not a comment.
// The rule uses a positive lookahead assertion to catch it: "//(?=;)".
re = //;
re = /a|b/;
<beginfold id='1'>/*</beginfold id='1'>
Tests for the regex parser.
It will parse classes, quantifiers, special characters and regex operaters,
as specified in the netscape documentation for javascript.
Regexps are only parsed in their clean form, as the RegExp(string) constructor
is using a quoted string.
TODO: Find out if more regex feats should be supported.
Consider using more itemDatas - assertion, quantifier are options.
<endfold id='1'>*/</endfold id='1'>
re = /^text\s+\d+\s*$/;
re = /a pattern with caret \(^\) in it/;
re = /(\d{0,4})\D/;
re = /[a-zA-Z_]+/;
re = /[^\d^]+/;
re = /\s+?\w+\.$/;
re = /\/\//;
re = /a|b/;
// the following are not regexps in E4X (=xml embedded into JavaScript)
var p = <p>Hello World</p>
var p = /</
var p = />/
// a test if #pop back from a comment will work
re = <beginfold id='1'>/*</beginfold id='1'>/foo/<endfold id='1'>*/</endfold id='1'> /bar/;
// ^ POP
// ^ we got back after pop in comment, if there is regexp attribs here :-)
<beginfold id='1'>/*</beginfold id='1'>
Some tests if the fallthrough works.
The fallthrough happens if a regexp is not found in a possible (!) position,
which is after "search(" or "replace(" or "=" or "?" or ":" in version 0.1 of the xml file
<endfold id='1'>*/</endfold id='1'>
var foo = 'bar';
// ^ fallthrough!
somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1");
// ^ fallthrough expected. ("new" whould be bold)
something.method =
function ( a, b, c ) <beginfold id='2'>{</beginfold id='2'> <beginfold id='1'>/*</beginfold id='1'> ... <endfold id='1'>*/</endfold id='1'> <endfold id='2'>}</endfold id='2'>
// ^ fallthrough ?!
something.other =
function ( d, e, f ) <beginfold id='2'>{</beginfold id='2'> <beginfold id='1'>/*</beginfold id='1'> ... <endfold id='1'>*/</endfold id='1'> <endfold id='2'>}</endfold id='2'>
// fallthrough expected at col 0 ("function" should be bold)
var ary = new Array(5);
// ^ fallthrough ? (if keyword is correctly rendered)
var b = a ? 1 : 0;
// ^ ^ fallthroughs. numbers must be rendered correctly.
var c = d ? true : false;
var conditinalstring = b ?
"something" :
"something else";
// guess...
<beginfold id='1'>/*</beginfold id='1'>
Normal program flow...
<endfold id='1'>*/</endfold id='1'>
if (something)
dostuff();
else
dont();
return;
try <beginfold id='2'>{</beginfold id='2'> bla() <endfold id='2'>}</endfold id='2'> catch (e) <beginfold id='2'>{</beginfold id='2'> alert("ERROR! : " + e) <endfold id='2'>}</endfold id='2'>
for (int i=0; i < j; i++)
document.write("i is" + i + "<br>");
while (something)
<beginfold id='2'>{</beginfold id='2'>
block();
picky:
if (!1)
break;
else
continue;
<endfold id='2'>}</endfold id='2'>
with (a) <beginfold id='2'>{</beginfold id='2'>
do <beginfold id='2'>{</beginfold id='2'>
stuff( b ); // a.b if it exists
<endfold id='2'>}</endfold id='2'> while (itmakessense);
<endfold id='2'>}</endfold id='2'>
switch (i) <beginfold id='2'>{</beginfold id='2'>
case 0:
f();
break;
default:
break;
<endfold id='2'>}</endfold id='2'>
// Numerics
var a = 0xA;
var b = 0b1;
var c = 0o7;
var c = 07;
var c = 08;
var d = 1.1E+3;
var e = 1.E+3;
var f = .1E+3;
var g = 1E+3;
var h = 1.1;
var i = 1.;
var j = .1;
var k = 1;
// Bigint
const binBig = 0b101n;
const octBig = 0o567n;
const hexBig = 0xC0Bn;
const decBig = 123n;
// Invalid numbers
var l = 0xA1t;
var m = 0b0123;
var n = 0o29;
var n = 000_7;
// Number with separator
let a = 0xA_b_1
let a = 0xA_b_1n
let a = 0xA_b_1_
let a = 0xA_b__1
let b = 0o1_2_3
let b = 0o1_2_3n
let b = 0o1_2_3_
let b = 0o1_2__3
let b = 0o1_2_38
let b = 01_2_3
let b = 01_2_3n
let b = 01_2_3_
let b = 01_2__3
let c = 0b0_1_1
let c = 0b0_1_1n
let c = 0b0_1_1_
let c = 0b0_1__1
let d = 1_2_3
let d = 1_2_3n
let d = 1_2_3_
let d = 1_2__3
let d = 01_2_8