Commit 791f400004d1f2503e1e462968c448c4a9d3ef3c

mAAdhaTTah 2018-05-27T17:46:52

Add tests Also fix up the patterns in light of said tests & code review.

diff --git a/components/prism-tap.js b/components/prism-tap.js
index 97bef15..80e5d3e 100644
--- a/components/prism-tap.js
+++ b/components/prism-tap.js
@@ -1,18 +1,18 @@
 Prism.languages.tap = {
-	pass: /(^|\n)(    )*ok[^#\{\n]*/,
-	fail: /(^|\n)(    )*not ok[^#\{\n]*/,
-	pragma: /(^|\n)(    )*pragma ([+-])([a-z]+)(\n|$)/,
-	bailout: /(^|\n)(    )*bail out!(.*)(\n|$)/i,
-	version: /(^|\n)(    )*TAP version ([0-9]+)(\n|$)/i,
-	plan: /(^|\n)(    )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?(\n|$)/m,
+	fail: /not ok[^#{\n\r]*/,
+	pass: /ok[^#{\n\r]*/,
+	pragma: /pragma [+-][a-z]+/,
+	bailout: /bail out!.*/i,
+	version: /TAP version \d+/i,
+	plan: /\d+\.\.\d+(?: +#.*)?/,
 	subtest: {
-		pattern: /(^|\n)(    )*# Subtest(?:: (.*))?(\n|$)/,
+		pattern: /# Subtest(?:: .*)?/,
 		greedy: true
 	},
 	punctuation: /[{}]/,
-	'comment': /#.*/,
+	directive: /#.*/,
 	yamlish: {
-		pattern: /(^|\n)((    )*(  ))---\n(.*?\n)+\2\.\.\.(\n|$)/,
+		pattern: /(^[^\S\r\n]*)---(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?[^\S\r\n]*\.\.\.$/m,
 		lookbehind: true,
 		inside: Prism.languages.yaml,
 		alias: 'language-yaml'
diff --git a/components/prism-tap.min.js b/components/prism-tap.min.js
index c563148..4f14d9b 100644
--- a/components/prism-tap.min.js
+++ b/components/prism-tap.min.js
@@ -1 +1 @@
-Prism.languages.tap={pass:/(^|\n)(    )*ok[^#\{\n]*/,fail:/(^|\n)(    )*not ok[^#\{\n]*/,pragma:/(^|\n)(    )*pragma ([+-])([a-z]+)(\n|$)/,bailout:/(^|\n)(    )*bail out!(.*)(\n|$)/i,version:/(^|\n)(    )*TAP version ([0-9]+)(\n|$)/i,plan:/(^|\n)(    )*([0-9]+)\.\.([0-9]+)( +#[^\n]*)?(\n|$)/m,subtest:{pattern:/(^|\n)(    )*# Subtest(?:: (.*))?(\n|$)/,greedy:!0},punctuation:/[{}]/,comment:/#.*/,yamlish:{pattern:/(^|\n)((    )*(  ))---\n(.*?\n)+\2\.\.\.(\n|$)/,lookbehind:!0,inside:Prism.languages.yaml,alias:"language-yaml"}};
\ No newline at end of file
+Prism.languages.tap={fail:/not ok[^#{\n\r]*/,pass:/ok[^#{\n\r]*/,pragma:/pragma [+-][a-z]+/,bailout:/bail out!.*/i,version:/TAP version \d+/i,plan:/\d+\.\.\d+(?: +#.*)?/,subtest:{pattern:/# Subtest(?:: .*)?/,greedy:!0},punctuation:/[{}]/,directive:/#.*/,yamlish:{pattern:/(^[^\S\r\n]*)---(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?[^\S\r\n]*\.\.\.$/m,lookbehind:!0,inside:Prism.languages.yaml,alias:"language-yaml"}};
\ No newline at end of file
diff --git a/tests/languages/tap/bail_out_feature.test b/tests/languages/tap/bail_out_feature.test
new file mode 100644
index 0000000..eba8164
--- /dev/null
+++ b/tests/languages/tap/bail_out_feature.test
@@ -0,0 +1,13 @@
+Bail out! Couldn't connect to database.
+bail out! Failed to call API.
+
+----------------------------------------------------
+
+[
+	["bailout", "Bail out! Couldn't connect to database."],
+	["bailout", "bail out! Failed to call API."]
+]
+
+----------------------------------------------------
+
+Checks bail out
diff --git a/tests/languages/tap/directive_feature.test b/tests/languages/tap/directive_feature.test
new file mode 100644
index 0000000..5a3ff91
--- /dev/null
+++ b/tests/languages/tap/directive_feature.test
@@ -0,0 +1,15 @@
+ok # SKIP test not written
+ok 42 this is the description # TODO write test
+
+----------------------------------------------------
+
+[
+	["pass", "ok " ],
+	["directive", "# SKIP test not written"],
+	["pass", "ok 42 this is the description "],
+	["directive", "# TODO write test"]
+]
+
+----------------------------------------------------
+
+Checks directives
diff --git a/tests/languages/tap/pass_fail_feature.test b/tests/languages/tap/pass_fail_feature.test
new file mode 100644
index 0000000..d078299
--- /dev/null
+++ b/tests/languages/tap/pass_fail_feature.test
@@ -0,0 +1,17 @@
+not ok
+not ok 42 this is the description of the test
+ok
+ok 42 this is the description of the test
+
+----------------------------------------------------
+
+[
+	["fail", "not ok" ],
+	["fail", "not ok 42 this is the description of the test"],
+	["pass", "ok" ],
+	["pass", "ok 42 this is the description of the test"]
+]
+
+----------------------------------------------------
+
+Checks test pass & fail together correctly
diff --git a/tests/languages/tap/plan_feature.test b/tests/languages/tap/plan_feature.test
new file mode 100644
index 0000000..8bdcd4e
--- /dev/null
+++ b/tests/languages/tap/plan_feature.test
@@ -0,0 +1,13 @@
+1..10
+1..10 # directive
+
+----------------------------------------------------
+
+[
+	["plan", "1..10" ],
+	["plan", "1..10 # directive" ]
+]
+
+----------------------------------------------------
+
+Checks TAP plan
diff --git a/tests/languages/tap/pragma_feature.test b/tests/languages/tap/pragma_feature.test
new file mode 100644
index 0000000..7775f2e
--- /dev/null
+++ b/tests/languages/tap/pragma_feature.test
@@ -0,0 +1,13 @@
+pragma +strict
+pragma -strict
+
+----------------------------------------------------
+
+[
+	["pragma", "pragma +strict"],
+	["pragma", "pragma -strict"]
+]
+
+----------------------------------------------------
+
+Checks pragma
diff --git a/tests/languages/tap/version_feature.test b/tests/languages/tap/version_feature.test
new file mode 100644
index 0000000..600bccc
--- /dev/null
+++ b/tests/languages/tap/version_feature.test
@@ -0,0 +1,11 @@
+TAP version 13
+
+----------------------------------------------------
+
+[
+	["version", "TAP version 13" ]
+]
+
+----------------------------------------------------
+
+Checks TAP version
diff --git a/tests/languages/tap/yamlish_feature.test b/tests/languages/tap/yamlish_feature.test
new file mode 100644
index 0000000..be4a19e
--- /dev/null
+++ b/tests/languages/tap/yamlish_feature.test
@@ -0,0 +1,50 @@
+ok
+    ---
+    message: "Failed with error 'hostname peebles.example.com not found'"
+    severity: fail
+    data:
+      got:
+        hostname: 'peebles.example.com'
+        address: ~
+      expected:
+        hostname: 'peebles.example.com'
+        address: '85.193.201.85'
+    ...
+
+----------------------------------------------------
+
+[
+	["pass", "ok"],
+	["yamlish", [
+		["punctuation", "---"],
+		["key", "message"],
+		["punctuation", ":"],
+		["string", "\"Failed with error 'hostname peebles.example.com not found'\""],
+		["key", "severity"],
+		["punctuation", ":"],
+		" fail\n    ",
+		["key", "data"],
+		["punctuation", ":"],
+		["key", "got"],
+		["punctuation", ":"],
+		["key", "hostname"],
+		["punctuation", ":"],
+		["string", "'peebles.example.com'"],
+		["key", "address"],
+		["punctuation", ":"],
+		["null", "~"],
+		["key", "expected"],
+		["punctuation", ":"],
+		["key", "hostname"],
+		["punctuation", ":"],
+		["string", "'peebles.example.com'"],
+		["key", "address"],
+		["punctuation", ":"],
+		["string", "'85.193.201.85'"],
+		["punctuation", "..."]
+	]]
+]
+
+----------------------------------------------------
+
+Checks yaml embedding