Add basic test cases for the Bro language This patch adds basic tests for the Bro language and it enables the greedy-flag for the string token.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
diff --git a/components/prism-bro.js b/components/prism-bro.js
index 4591d92..bc46ae2 100644
--- a/components/prism-bro.js
+++ b/components/prism-bro.js
@@ -8,7 +8,10 @@ Prism.languages.bro = {
}
},
- 'string': /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
+ 'string': {
+ pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
+ greedy: true
+ },
'boolean': /\b(T|F)\b/,
@@ -36,7 +39,7 @@ Prism.languages.bro = {
}
},
- 'keyword':
+ 'keyword':
/\b(break|next|continue|alarm|using|of|add|delete|export|print|return|schedule|when|timeout|addr|any|bool|count|double|enum|file|int|interval|pattern|opaque|port|record|set|string|subnet|table|time|vector|for|if|else|in|module|function)\b/,
'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&|\|\|?|\?|\*|\/|~|\^|%/,
diff --git a/components/prism-bro.min.js b/components/prism-bro.min.js
index bc8a649..6ded4fd 100644
--- a/components/prism-bro.min.js
+++ b/components/prism-bro.min.js
@@ -1 +1 @@
-Prism.languages.bro={comment:{pattern:/(^|[^\\$])#.*/,lookbehind:!0,inside:{italic:/\b(TODO|FIXME|XXX)\b/}},string:/(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,"boolean":/\b(T|F)\b/,"function":{pattern:/(?:function|hook|event) [a-zA-Z0-9_]+(::[a-zA-Z0-9_]+)?/,inside:{keyword:/^(?:function|hook|event)/}},variable:{pattern:/(?:global|local) [a-zA-Z0-9_]+/i,inside:{keyword:/(?:global|local)/}},builtin:/(@(load(-(sigs|plugin))?|unload|prefixes|ifn?def|else|(end)?if|DIR|FILENAME))|(&?(redef|priority|log|optional|default|add_func|delete_func|expire_func|read_expire|write_expire|create_expire|synchronized|persistent|rotate_interval|rotate_size|encrypt|raw_output|mergeable|group|error_handler|type_column))/,constant:{pattern:/const [a-zA-Z0-9_]+/i,inside:{keyword:/const/}},keyword:/\b(break|next|continue|alarm|using|of|add|delete|export|print|return|schedule|when|timeout|addr|any|bool|count|double|enum|file|int|interval|pattern|opaque|port|record|set|string|subnet|table|time|vector|for|if|else|in|module|function)\b/,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&|\|\|?|\?|\*|\/|~|\^|%/,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
+Prism.languages.bro={comment:{pattern:/(^|[^\\$])#.*/,lookbehind:!0,inside:{italic:/\b(TODO|FIXME|XXX)\b/}},string:{pattern:/(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"boolean":/\b(T|F)\b/,"function":{pattern:/(?:function|hook|event) [a-zA-Z0-9_]+(::[a-zA-Z0-9_]+)?/,inside:{keyword:/^(?:function|hook|event)/}},variable:{pattern:/(?:global|local) [a-zA-Z0-9_]+/i,inside:{keyword:/(?:global|local)/}},builtin:/(@(load(-(sigs|plugin))?|unload|prefixes|ifn?def|else|(end)?if|DIR|FILENAME))|(&?(redef|priority|log|optional|default|add_func|delete_func|expire_func|read_expire|write_expire|create_expire|synchronized|persistent|rotate_interval|rotate_size|encrypt|raw_output|mergeable|group|error_handler|type_column))/,constant:{pattern:/const [a-zA-Z0-9_]+/i,inside:{keyword:/const/}},keyword:/\b(break|next|continue|alarm|using|of|add|delete|export|print|return|schedule|when|timeout|addr|any|bool|count|double|enum|file|int|interval|pattern|opaque|port|record|set|string|subnet|table|time|vector|for|if|else|in|module|function)\b/,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&|\|\|?|\?|\*|\/|~|\^|%/,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
diff --git a/tests/languages/bro/builtin_feature.test b/tests/languages/bro/builtin_feature.test
new file mode 100644
index 0000000..cd5a121
--- /dev/null
+++ b/tests/languages/bro/builtin_feature.test
@@ -0,0 +1,29 @@
+@load-sigs
+@load-plugin
+@unload
+@prefixes
+@ifndef
+@ifdef
+@else
+&redef
+&priority
+redef
+
+----------------------------------------------------
+
+[
+ ["builtin", "@load-sigs"],
+ ["builtin", "@load-plugin"],
+ ["builtin", "@unload"],
+ ["builtin", "@prefixes"],
+ ["builtin", "@ifndef"],
+ ["builtin", "@ifdef"],
+ ["builtin", "@else"],
+ ["builtin", "&redef"],
+ ["builtin", "&priority"],
+ ["builtin", "redef"]
+]
+
+----------------------------------------------------
+
+Checks for the builtins
\ No newline at end of file
diff --git a/tests/languages/bro/comment_feature.test b/tests/languages/bro/comment_feature.test
new file mode 100644
index 0000000..e1eff30
--- /dev/null
+++ b/tests/languages/bro/comment_feature.test
@@ -0,0 +1,17 @@
+## comment
+#TODO
+## FIXME
+# XXX
+
+----------------------------------------------------
+
+[
+ ["comment", [ "## comment"]],
+ ["comment", [ "#", ["italic", "TODO"]]],
+ ["comment", [ "## ", ["italic", "FIXME"]]],
+ ["comment", [ "# ", ["italic", "XXX"]]]
+]
+
+----------------------------------------------------
+
+Checks for the highlighting of comments
\ No newline at end of file
diff --git a/tests/languages/bro/function_feature.test b/tests/languages/bro/function_feature.test
new file mode 100644
index 0000000..a10d792
--- /dev/null
+++ b/tests/languages/bro/function_feature.test
@@ -0,0 +1,21 @@
+function foo
+hook foo
+event foo
+function foo::bar
+hook foo::bar
+event foo::bar
+
+----------------------------------------------------
+
+[
+ ["function", [["keyword", "function"], " foo"]],
+ ["function", [["keyword", "hook"], " foo"]],
+ ["function", [["keyword", "event"], " foo"]],
+ ["function", [["keyword", "function"], " foo::bar"]],
+ ["function", [["keyword", "hook"], " foo::bar"]],
+ ["function", [["keyword", "event"], " foo::bar"]]
+]
+
+----------------------------------------------------
+
+Checks for the function feature
\ No newline at end of file
diff --git a/tests/languages/bro/string_feature.test b/tests/languages/bro/string_feature.test
new file mode 100644
index 0000000..68277b5
--- /dev/null
+++ b/tests/languages/bro/string_feature.test
@@ -0,0 +1,23 @@
+""
+''
+"foo"
+'foo'
+"'foo'"
+'"bar"'
+" # comment "
+
+----------------------------------------------------
+
+[
+ ["string", "\"\""],
+ ["string", "''"],
+ ["string", "\"foo\""],
+ ["string", "'foo'"],
+ ["string", "\"'foo'\""],
+ ["string", "'\"bar\"'"],
+ ["string", "\" # comment \""]
+]
+
+----------------------------------------------------
+
+Checks for single-quoted and double-quoted strings.
\ No newline at end of file
diff --git a/tests/languages/bro/variable_feature.test b/tests/languages/bro/variable_feature.test
new file mode 100644
index 0000000..7a0a717
--- /dev/null
+++ b/tests/languages/bro/variable_feature.test
@@ -0,0 +1,20 @@
+local foo
+global foo
+local bool = T;
+const bar
+
+----------------------------------------------------
+
+[
+ ["variable", [["keyword", "local"], " foo"]],
+ ["variable", [["keyword", "global"], " foo"]],
+ ["variable", [["keyword", "local"], " bool"]],
+ ["operator", "="],
+ ["boolean", "T"],
+ ["punctuation", ";"],
+ ["constant", [["keyword", "const"], " bar"]]
+]
+
+----------------------------------------------------
+
+Checks for the highlighting of variables
\ No newline at end of file