Commit 71e57594e9b7b2b8f4cce194d55ed67b5e917f66

Andreas Rohner 2016-04-30T11:52:51

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.

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