Changeset View
Changeset View
Standalone View
Standalone View
autotests/folding/highlight.js.fold
1 | <beginfold id='2'>/*</beginfold id='2'> test.js - test for javascript.xml syntax file <endfold id='2'>*/</endfold id='2'> | 1 | <beginfold id='3'>/*</beginfold id='3'> test.js - test for javascript.xml syntax file <endfold id='3'>*/</endfold id='3'> | ||
---|---|---|---|---|---|
2 | // Note: this script will not, and is not supposed to, compile in any js engine. | 2 | // Note: this script will not, and is not supposed to, compile in any js engine. | ||
3 | 3 | | |||
4 | <beginfold id='2'>/*</beginfold id='2'> | 4 | <beginfold id='3'>/*</beginfold id='3'> | ||
5 | NOTE: The words "todo", "fixme" and "note" should be rendered in a different style | 5 | NOTE: The words "todo", "fixme" and "note" should be rendered in a different style | ||
6 | within comments, match should be caseless (to test for regexp insensitive attribute). | 6 | within comments, match should be caseless (to test for regexp insensitive attribute). | ||
7 | The regex used for this rule is <endfold id='2'>*/</endfold id='2'> | 7 | The regex used for this rule is <endfold id='3'>*/</endfold id='3'> | ||
8 | String = /\b(?:fixme|todo|note)\b/ | 8 | String = /\b(?:fixme|todo|note)\b/ | ||
9 | <beginfold id='2'>/*</beginfold id='2'> Thus, for example "Notebook" is not caught by | 9 | <beginfold id='3'>/*</beginfold id='3'> Thus, for example "Notebook" is not caught by | ||
10 | this rule. (the "?:" in the subpattern is there to avoid the regex engine wasting time | 10 | this rule. (the "?:" in the subpattern is there to avoid the regex engine wasting time | ||
11 | saving a backref, which is not used for anything. I do not know if the overhead of parsing | 11 | saving a backref, which is not used for anything. I do not know if the overhead of parsing | ||
12 | that is greater than the time saved by not capturing the text...) | 12 | that is greater than the time saved by not capturing the text...) | ||
13 | The rule for catching these words is placed in a context "Comment common", which is used | 13 | The rule for catching these words is placed in a context "Comment common", which is used | ||
14 | by both comment contexts (single line, multiline) using the new "IncludeRules" item. | 14 | by both comment contexts (single line, multiline) using the new "IncludeRules" item. | ||
15 | <endfold id='2'>*/</endfold id='2'> | 15 | <endfold id='3'>*/</endfold id='3'> | ||
16 | 16 | | |||
17 | // test if regex support works - nice with new fallthrough prop in context:) | 17 | // test if regex support works - nice with new fallthrough prop in context:) | ||
18 | somestring.replace( /dooh/ , "bah!"); | 18 | somestring.replace( /dooh/ , "bah!"); | ||
19 | re=/foo/ig; // hehe | 19 | re=/foo/ig; // hehe | ||
20 | 20 | | |||
21 | somestring.search( | 21 | somestring.search( | ||
22 | /^foo\w+\s\d{0,15}$/ | 22 | /^foo\w+\s\d{0,15}$/ | ||
23 | ); | 23 | ); | ||
24 | 24 | | |||
25 | re = | 25 | re = | ||
26 | /dooh/; | 26 | /dooh/; | ||
27 | 27 | | |||
28 | // This is supposedly legal: | 28 | // This is supposedly legal: | ||
29 | re = somebool ? /foo/ : /bar/; | 29 | re = somebool ? /foo/ : /bar/; | ||
30 | 30 | | |||
31 | // NOTE - Special case: an empty regex, not a comment. | 31 | // NOTE - Special case: an empty regex, not a comment. | ||
32 | // The rule uses a positive lookahead assertion to catch it: "//(?=;)". | 32 | // The rule uses a positive lookahead assertion to catch it: "//(?=;)". | ||
33 | re = //; | 33 | re = //; | ||
34 | re = /a|b/; | 34 | re = /a|b/; | ||
35 | 35 | | |||
36 | <beginfold id='2'>/*</beginfold id='2'> | 36 | <beginfold id='3'>/*</beginfold id='3'> | ||
37 | Tests for the regex parser. | 37 | Tests for the regex parser. | ||
38 | It will parse classes, quanitfiers, special characters and regex operaters, | 38 | It will parse classes, quanitfiers, special characters and regex operaters, | ||
39 | as specified in the netscape documentation for javascript. | 39 | as specified in the netscape documentation for javascript. | ||
40 | Regexps are only parsed in their clean form, as the RegExp(string) constructor | 40 | Regexps are only parsed in their clean form, as the RegExp(string) constructor | ||
41 | is using a quoted string. | 41 | is using a quoted string. | ||
42 | TODO: Find out if more regex feats should be supported. | 42 | TODO: Find out if more regex feats should be supported. | ||
43 | Consider using more itemDatas - assertion, quantifier are options. | 43 | Consider using more itemDatas - assertion, quantifier are options. | ||
44 | <endfold id='2'>*/</endfold id='2'> | 44 | <endfold id='3'>*/</endfold id='3'> | ||
45 | 45 | | |||
46 | re = /^text\s+\d+\s*$/; | 46 | re = /^text\s+\d+\s*$/; | ||
47 | re = /a pattern with caret \(^\) in it/; | 47 | re = /a pattern with caret \(^\) in it/; | ||
48 | re = /(\d{0,4})\D/; | 48 | re = /(\d{0,4})\D/; | ||
49 | re = /[a-zA-Z_]+/; | 49 | re = /[a-zA-Z_]+/; | ||
50 | re = /[^\d^]+/; | 50 | re = /[^\d^]+/; | ||
51 | re = /\s+?\w+\.$/; | 51 | re = /\s+?\w+\.$/; | ||
52 | re = /\/\//; | 52 | re = /\/\//; | ||
53 | re = /a|b/; | 53 | re = /a|b/; | ||
54 | 54 | | |||
55 | // the following are not regexps in E4X (=xml embedded into JavaScript) | 55 | // the following are not regexps in E4X (=xml embedded into JavaScript) | ||
56 | var p = <p>Hello World</p> | 56 | var p = <p>Hello World</p> | ||
57 | var p = /</ | 57 | var p = /</ | ||
58 | var p = />/ | 58 | var p = />/ | ||
59 | 59 | | |||
60 | // a test if #pop back from a comment will work | 60 | // a test if #pop back from a comment will work | ||
61 | re = <beginfold id='2'>/*</beginfold id='2'>/foo/<endfold id='2'>*/</endfold id='2'> /bar/; | 61 | re = <beginfold id='3'>/*</beginfold id='3'>/foo/<endfold id='3'>*/</endfold id='3'> /bar/; | ||
62 | // ^ POP | 62 | // ^ POP | ||
63 | // ^ we got back after pop in comment, if there is regexp attribs here :-) | 63 | // ^ we got back after pop in comment, if there is regexp attribs here :-) | ||
64 | 64 | | |||
65 | <beginfold id='2'>/*</beginfold id='2'> | 65 | <beginfold id='3'>/*</beginfold id='3'> | ||
66 | Some tests if the fallthrough works. | 66 | Some tests if the fallthrough works. | ||
67 | The fallthrough happens if a regexp is not found in a possible (!) position, | 67 | The fallthrough happens if a regexp is not found in a possible (!) position, | ||
68 | which is after "search(" or "replace(" or "=" or "?" or ":" in version 0.1 of the xml file | 68 | which is after "search(" or "replace(" or "=" or "?" or ":" in version 0.1 of the xml file | ||
69 | <endfold id='2'>*/</endfold id='2'> | 69 | <endfold id='3'>*/</endfold id='3'> | ||
70 | 70 | | |||
71 | var foo = 'bar'; | 71 | var foo = 'bar'; | ||
72 | // ^ fallthrough! | 72 | // ^ fallthrough! | ||
73 | 73 | | |||
74 | 74 | | |||
75 | somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1"); | 75 | somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1"); | ||
76 | // ^ fallthrough expected. ("new" whould be bold) | 76 | // ^ fallthrough expected. ("new" whould be bold) | ||
77 | 77 | | |||
78 | 78 | | |||
79 | something.method = | 79 | something.method = | ||
80 | function ( a, b, c ) <beginfold id='3'>{</beginfold id='3'> <beginfold id='2'>/*</beginfold id='2'> ... <endfold id='2'>*/</endfold id='2'> <endfold id='3'>}</endfold id='3'> | 80 | function ( a, b, c ) <beginfold id='2'>{</beginfold id='2'> <beginfold id='3'>/*</beginfold id='3'> ... <endfold id='3'>*/</endfold id='3'> <endfold id='2'>}</endfold id='2'> | ||
81 | // ^ fallthrough ?! | 81 | // ^ fallthrough ?! | ||
82 | 82 | | |||
83 | something.other = | 83 | something.other = | ||
84 | function ( d, e, f ) <beginfold id='3'>{</beginfold id='3'> <beginfold id='2'>/*</beginfold id='2'> ... <endfold id='2'>*/</endfold id='2'> <endfold id='3'>}</endfold id='3'> | 84 | function ( d, e, f ) <beginfold id='2'>{</beginfold id='2'> <beginfold id='3'>/*</beginfold id='3'> ... <endfold id='3'>*/</endfold id='3'> <endfold id='2'>}</endfold id='2'> | ||
85 | // fallthrough expected at col 0 ("function" should be bold) | 85 | // fallthrough expected at col 0 ("function" should be bold) | ||
86 | 86 | | |||
87 | var ary = new Array(5); | 87 | var ary = new Array(5); | ||
88 | // ^ fallthrough ? (if keyword is correctly rendered) | 88 | // ^ fallthrough ? (if keyword is correctly rendered) | ||
89 | 89 | | |||
90 | var b = a ? 1 : 0; | 90 | var b = a ? 1 : 0; | ||
91 | // ^ ^ fallthroughs. numbers must be rendered correctly. | 91 | // ^ ^ fallthroughs. numbers must be rendered correctly. | ||
92 | 92 | | |||
93 | var c = d ? true : false; | 93 | var c = d ? true : false; | ||
94 | 94 | | |||
95 | var conditinalstring = b ? | 95 | var conditinalstring = b ? | ||
96 | "something" : | 96 | "something" : | ||
97 | "something else"; | 97 | "something else"; | ||
98 | // guess... | 98 | // guess... | ||
99 | 99 | | |||
100 | 100 | | |||
101 | <beginfold id='2'>/*</beginfold id='2'> | 101 | <beginfold id='3'>/*</beginfold id='3'> | ||
102 | Normal program flow... | 102 | Normal program flow... | ||
103 | <endfold id='2'>*/</endfold id='2'> | 103 | <endfold id='3'>*/</endfold id='3'> | ||
104 | 104 | | |||
105 | if (something) | 105 | if (something) | ||
106 | dostuff(); | 106 | dostuff(); | ||
107 | else | 107 | else | ||
108 | dont(); | 108 | dont(); | ||
109 | 109 | | |||
110 | return; | 110 | return; | ||
111 | 111 | | |||
112 | try <beginfold id='3'>{</beginfold id='3'> bla() <endfold id='3'>}</endfold id='3'> catch (e) <beginfold id='3'>{</beginfold id='3'> alert("ERROR! : " + e) <endfold id='3'>}</endfold id='3'> | 112 | 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'> | ||
113 | 113 | | |||
114 | for (int i=0; i < j; i++) | 114 | for (int i=0; i < j; i++) | ||
115 | document.write("i is" + i + "<br>"); | 115 | document.write("i is" + i + "<br>"); | ||
116 | 116 | | |||
117 | while (something) | 117 | while (something) | ||
118 | <beginfold id='3'>{</beginfold id='3'> | 118 | <beginfold id='2'>{</beginfold id='2'> | ||
119 | block(); | 119 | block(); | ||
120 | picky: | 120 | picky: | ||
121 | if (!1) | 121 | if (!1) | ||
122 | break; | 122 | break; | ||
123 | else | 123 | else | ||
124 | continue; | 124 | continue; | ||
125 | <endfold id='3'>}</endfold id='3'> | 125 | <endfold id='2'>}</endfold id='2'> | ||
126 | 126 | | |||
127 | with (a) <beginfold id='3'>{</beginfold id='3'> | 127 | with (a) <beginfold id='2'>{</beginfold id='2'> | ||
128 | do <beginfold id='3'>{</beginfold id='3'> | 128 | do <beginfold id='2'>{</beginfold id='2'> | ||
129 | stuff( b ); // a.b if it exists | 129 | stuff( b ); // a.b if it exists | ||
130 | <endfold id='3'>}</endfold id='3'> while (itmakessense); | 130 | <endfold id='2'>}</endfold id='2'> while (itmakessense); | ||
131 | <endfold id='3'>}</endfold id='3'> | 131 | <endfold id='2'>}</endfold id='2'> | ||
132 | 132 | | |||
133 | switch (i) <beginfold id='3'>{</beginfold id='3'> | 133 | switch (i) <beginfold id='2'>{</beginfold id='2'> | ||
134 | case 0: | 134 | case 0: | ||
135 | f(); | 135 | f(); | ||
136 | break; | 136 | break; | ||
137 | default: | 137 | default: | ||
138 | break; | 138 | break; | ||
139 | <endfold id='3'>}</endfold id='3'> | 139 | <endfold id='2'>}</endfold id='2'> |